diff options
author | Robin Appelman <robin@icewind.nl> | 2020-11-13 17:04:36 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2020-11-26 15:22:03 +0100 |
commit | 23fb497ff59a90813cba24ca1c82be979cf95046 (patch) | |
tree | 2c56eb189e025d098f7c89539416936014ae9522 /lib/private | |
parent | 54e3beba165739c480730f797e2b386b12a92713 (diff) | |
download | nextcloud-server-23fb497ff59a90813cba24ca1c82be979cf95046.tar.gz nextcloud-server-23fb497ff59a90813cba24ca1c82be979cf95046.zip |
extend cache events
- adds cache remove event
- expose storage id in event
- emit events during cache move
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/Cache/AbstractCacheEvent.php | 12 | ||||
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 18 | ||||
-rw-r--r-- | lib/private/Files/Cache/CacheEntry.php | 2 |
3 files changed, 27 insertions, 5 deletions
diff --git a/lib/private/Files/Cache/AbstractCacheEvent.php b/lib/private/Files/Cache/AbstractCacheEvent.php index a4029476fa5..bb7ade386e0 100644 --- a/lib/private/Files/Cache/AbstractCacheEvent.php +++ b/lib/private/Files/Cache/AbstractCacheEvent.php @@ -36,6 +36,7 @@ class AbstractCacheEvent extends Event implements ICacheEvent { protected $storage; protected $path; protected $fileId; + protected $storageId; /** * @param IStorage $storage @@ -43,10 +44,11 @@ class AbstractCacheEvent extends Event implements ICacheEvent { * @param int $fileId * @since 16.0.0 */ - public function __construct(IStorage $storage, string $path, int $fileId) { + public function __construct(IStorage $storage, string $path, int $fileId, int $storageId) { $this->storage = $storage; $this->path = $path; $this->fileId = $fileId; + $this->storageId = $storageId; } /** @@ -80,4 +82,12 @@ class AbstractCacheEvent extends Event implements ICacheEvent { public function getFileId(): int { return $this->fileId; } + + /** + * @return int + * @since 21.0.0 + */ + public function getStorageId(): int { + return $this->storageId; + } } diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 1d3b4da3bce..bf8d35411fb 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -42,6 +42,7 @@ use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Cache\CacheInsertEvent; +use OCP\Files\Cache\CacheRemoveEvent; use OCP\Files\Cache\CacheUpdateEvent; use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; @@ -284,7 +285,8 @@ class Cache implements ICache { $data['name'] = basename($file); [$values, $extensionValues] = $this->normalizeData($data); - $values['storage'] = $this->getNumericStorageId(); + $storageId = $this->getNumericStorageId(); + $values['storage'] = $storageId; try { $builder = $this->connection->getQueryBuilder(); @@ -308,7 +310,7 @@ class Cache implements ICache { $query->execute(); } - $this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId)); + $this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId, $storageId)); return $fileId; } } catch (UniqueConstraintViolationException $e) { @@ -399,7 +401,7 @@ class Cache implements ICache { $path = $this->getPathById($id); // path can still be null if the file doesn't exist if ($path !== null) { - $this->eventDispatcher->dispatch(CacheUpdateEvent::class, new CacheUpdateEvent($this->storage, $path, $id)); + $this->eventDispatcher->dispatch(CacheUpdateEvent::class, new CacheUpdateEvent($this->storage, $path, $id, $this->getNumericStorageId())); } } @@ -536,6 +538,8 @@ class Cache implements ICache { if ($entry->getMimeType() == FileInfo::MIMETYPE_FOLDER) { $this->removeChildren($entry); } + + $this->eventDispatcher->dispatch(CacheRemoveEvent::class, new CacheRemoveEvent($this->storage, $entry->getPath(), $entry->getId(), $this->getNumericStorageId())); } } @@ -677,9 +681,17 @@ class Cache implements ICache { $query->execute(); $this->connection->commit(); + + if ($sourceCache->getNumericStorageId() !== $this->getNumericStorageId()) { + $this->eventDispatcher->dispatch(CacheRemoveEvent::class, new CacheRemoveEvent($this->storage, $sourcePath, $sourceId, $sourceCache->getNumericStorageId())); + $this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $targetPath, $sourceId, $this->getNumericStorageId())); + } else { + $this->eventDispatcher->dispatch(CacheUpdateEvent::class, new CacheUpdateEvent($this->storage, $targetPath, $sourceId, $this->getNumericStorageId())); + } } else { $this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); } + } /** diff --git a/lib/private/Files/Cache/CacheEntry.php b/lib/private/Files/Cache/CacheEntry.php index a0ba9020909..5f31ecfbec3 100644 --- a/lib/private/Files/Cache/CacheEntry.php +++ b/lib/private/Files/Cache/CacheEntry.php @@ -67,7 +67,7 @@ class CacheEntry implements ICacheEntry { public function getPath() { - return $this->data['path']; + return (string)$this->data['path']; } |