diff options
author | Robin Appelman <robin@icewind.nl> | 2019-01-22 17:08:32 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2019-02-07 15:51:30 +0100 |
commit | 748bcd407b4079adeceff3455749ad1e4d316c9d (patch) | |
tree | 9ae604f077275240486ce5b6e4077f4635695f80 /lib/private | |
parent | a1aa6ee70d45d359d7e277873106a668aa642305 (diff) | |
download | nextcloud-server-748bcd407b4079adeceff3455749ad1e4d316c9d.tar.gz nextcloud-server-748bcd407b4079adeceff3455749ad1e4d316c9d.zip |
add event for inserting cache entries
this provides a reliable way for apps to listen to new files
without the need to of cache wrappers to hook into inserts themselves
(something which isn't 100% reliable)
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 24 | ||||
-rw-r--r-- | lib/private/Files/Cache/Storage.php | 4 |
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 43e48e51654..17e870bcbb4 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -40,10 +40,12 @@ namespace OC\Files\Cache; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCP\DB\QueryBuilder\IQueryBuilder; use Doctrine\DBAL\Driver\Statement; +use OCP\Files\Cache\CacheInsertEvent; use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; use \OCP\Files\IMimeTypeLoader; use OCP\Files\Search\ISearchQuery; +use OCP\Files\Storage\IStorage; use OCP\IDBConnection; /** @@ -71,6 +73,8 @@ class Cache implements ICache { */ protected $storageId; + private $storage; + /** * @var Storage $storageCache */ @@ -84,18 +88,17 @@ class Cache implements ICache { */ protected $connection; + protected $eventDispatcher; + /** @var QuerySearchHelper */ protected $querySearchHelper; /** - * @param \OC\Files\Storage\Storage|string $storage + * @param IStorage $storage */ - public function __construct($storage) { - if ($storage instanceof \OC\Files\Storage\Storage) { - $this->storageId = $storage->getId(); - } else { - $this->storageId = $storage; - } + public function __construct(IStorage $storage) { + $this->storageId = $storage->getId(); + $this->storage = $storage; if (strlen($this->storageId) > 64) { $this->storageId = md5($this->storageId); } @@ -103,6 +106,7 @@ class Cache implements ICache { $this->storageCache = new Storage($storage); $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); $this->connection = \OC::$server->getDatabaseConnection(); + $this->eventDispatcher = \OC::$server->getEventDispatcher(); $this->querySearchHelper = new QuerySearchHelper($this->mimetypeLoader); } @@ -283,9 +287,11 @@ class Cache implements ICache { } if ($builder->execute()) { - return (int)$this->connection->lastInsertId('*PREFIX*filecache'); + $fileId = (int)$this->connection->lastInsertId('*PREFIX*filecache'); + $this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId)); + return $fileId; } - } catch(UniqueConstraintViolationException $e) { + } catch (UniqueConstraintViolationException $e) { // entry exists already } diff --git a/lib/private/Files/Cache/Storage.php b/lib/private/Files/Cache/Storage.php index 794c4872c93..5b37c1f43f8 100644 --- a/lib/private/Files/Cache/Storage.php +++ b/lib/private/Files/Cache/Storage.php @@ -28,6 +28,8 @@ namespace OC\Files\Cache; +use OCP\Files\Storage\IStorage; + /** * Handle the mapping between the string and numeric storage ids * @@ -61,7 +63,7 @@ class Storage { * @throws \RuntimeException */ public function __construct($storage, $isAvailable = true) { - if ($storage instanceof \OC\Files\Storage\Storage) { + if ($storage instanceof IStorage) { $this->storageId = $storage->getId(); } else { $this->storageId = $storage; |