diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-12-11 11:27:05 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-12-13 09:41:05 +0100 |
commit | b81b824da138281d904c775664c82f060ba4fbec (patch) | |
tree | 0194aea2aabe08a168bc32ccf964b94f31db6ae5 /lib/private/Files/Utils | |
parent | 642606754b133a36d7715b45b243155cbb006f95 (diff) | |
download | nextcloud-server-b81b824da138281d904c775664c82f060ba4fbec.tar.gz nextcloud-server-b81b824da138281d904c775664c82f060ba4fbec.zip |
Add typed events for the filesystem/scanner
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Files/Utils')
-rw-r--r-- | lib/private/Files/Utils/Scanner.php | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index 45194b57cbf..53712d28171 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -36,9 +36,18 @@ use OC\ForbiddenException; use OC\Hooks\PublicEmitter; use OC\Lock\DBLockingProvider; use OCA\Files_Sharing\SharedStorage; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\BeforeFileScannedEvent; +use OCP\Files\Events\BeforeFolderScannedEvent; +use OCP\Files\Events\NodeAddedToCache; +use OCP\Files\Events\FileCacheUpdated; +use OCP\Files\Events\NodeRemovedFromCache; +use OCP\Files\Events\FileScannedEvent; +use OCP\Files\Events\FolderScannedEvent; use OCP\Files\NotFoundException; use OCP\Files\Storage\IStorage; use OCP\Files\StorageNotAvailableException; +use OCP\IDBConnection; use OCP\ILogger; /** @@ -53,19 +62,16 @@ use OCP\ILogger; class Scanner extends PublicEmitter { const MAX_ENTRIES_TO_COMMIT = 10000; - /** - * @var string $user - */ + /** @var string $user */ private $user; - /** - * @var \OCP\IDBConnection - */ + /** @var IDBConnection */ protected $db; - /** - * @var ILogger - */ + /** @var IEventDispatcher */ + private $dispatcher; + + /** @var ILogger */ protected $logger; /** @@ -84,13 +90,15 @@ class Scanner extends PublicEmitter { /** * @param string $user - * @param \OCP\IDBConnection $db + * @param IDBConnection|null $db + * @param IEventDispatcher $dispatcher * @param ILogger $logger */ - public function __construct($user, $db, ILogger $logger) { - $this->logger = $logger; + public function __construct($user, $db, IEventDispatcher $dispatcher, ILogger $logger) { $this->user = $user; $this->db = $db; + $this->dispatcher = $dispatcher; + $this->logger = $logger; // when DB locking is used, no DB transactions will be used $this->useTransaction = !(\OC::$server->getLockingProvider() instanceof DBLockingProvider); } @@ -121,18 +129,21 @@ class Scanner extends PublicEmitter { */ protected function attachListener($mount) { $scanner = $mount->getStorage()->getScanner(); - $emitter = $this; - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount) { + $this->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); + $this->dispatcher->dispatchTyped(new BeforeFileScannedEvent($mount->getMountPoint() . $path)); }); - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount) { + $this->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); + $this->dispatcher->dispatchTyped(new BeforeFolderScannedEvent($mount->getMountPoint() . $path)); }); - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount) { + $this->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); + $this->dispatcher->dispatchTyped(new FileScannedEvent($mount->getMountPoint() . $path)); }); - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount) { + $this->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); + $this->dispatcher->dispatchTyped(new FolderScannedEvent($mount->getMountPoint() . $path)); }); } @@ -225,12 +236,15 @@ class Scanner extends PublicEmitter { $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { $this->postProcessEntry($storage, $path); + $this->dispatcher->dispatchTyped(new NodeRemovedFromCache($storage, $path)); }); $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { $this->postProcessEntry($storage, $path); + $this->dispatcher->dispatchTyped(new FileCacheUpdated($storage, $path)); }); $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { $this->postProcessEntry($storage, $path); + $this->dispatcher->dispatchTyped(new NodeAddedToCache($storage, $path)); }); if (!$storage->file_exists($relativePath)) { |