3636use OC \Hooks \PublicEmitter ;
3737use OC \Lock \DBLockingProvider ;
3838use OCA \Files_Sharing \SharedStorage ;
39+ use OCP \EventDispatcher \IEventDispatcher ;
40+ use OCP \Files \Events \BeforeFileScannedEvent ;
41+ use OCP \Files \Events \BeforeFolderScannedEvent ;
42+ use OCP \Files \Events \NodeAddedToCache ;
43+ use OCP \Files \Events \FileCacheUpdated ;
44+ use OCP \Files \Events \NodeRemovedFromCache ;
45+ use OCP \Files \Events \FileScannedEvent ;
46+ use OCP \Files \Events \FolderScannedEvent ;
3947use OCP \Files \NotFoundException ;
4048use OCP \Files \Storage \IStorage ;
4149use OCP \Files \StorageNotAvailableException ;
50+ use OCP \IDBConnection ;
4251use OCP \ILogger ;
4352
4453/**
5362class Scanner extends PublicEmitter {
5463 const MAX_ENTRIES_TO_COMMIT = 10000 ;
5564
56- /**
57- * @var string $user
58- */
65+ /** @var string $user */
5966 private $ user ;
6067
61- /**
62- * @var \OCP\IDBConnection
63- */
68+ /** @var IDBConnection */
6469 protected $ db ;
6570
66- /**
67- * @var ILogger
68- */
71+ /** @var IEventDispatcher */
72+ private $ dispatcher ;
73+
74+ /** @var ILogger */
6975 protected $ logger ;
7076
7177 /**
@@ -84,13 +90,15 @@ class Scanner extends PublicEmitter {
8490
8591 /**
8692 * @param string $user
87- * @param \OCP\IDBConnection $db
93+ * @param IDBConnection|null $db
94+ * @param IEventDispatcher $dispatcher
8895 * @param ILogger $logger
8996 */
90- public function __construct ($ user , $ db , ILogger $ logger ) {
91- $ this ->logger = $ logger ;
97+ public function __construct ($ user , $ db , IEventDispatcher $ dispatcher , ILogger $ logger ) {
9298 $ this ->user = $ user ;
9399 $ this ->db = $ db ;
100+ $ this ->dispatcher = $ dispatcher ;
101+ $ this ->logger = $ logger ;
94102 // when DB locking is used, no DB transactions will be used
95103 $ this ->useTransaction = !(\OC ::$ server ->getLockingProvider () instanceof DBLockingProvider);
96104 }
@@ -121,18 +129,21 @@ protected function getMounts($dir) {
121129 */
122130 protected function attachListener ($ mount ) {
123131 $ scanner = $ mount ->getStorage ()->getScanner ();
124- $ emitter = $ this ;
125- $ scanner -> listen ('\OC\Files\Cache \Scanner ' , 'scanFile ' , function ( $ path ) use ( $ mount , $ emitter ) {
126- $ emitter -> emit ( ' \OC\Files\Utils\Scanner ' , ' scanFile ' , array ($ mount ->getMountPoint () . $ path ));
132+ $ scanner -> listen ( ' \OC\Files\Cache\Scanner ' , ' scanFile ' , function ( $ path ) use ( $ mount ) {
133+ $ this -> emit ('\OC\Files\Utils \Scanner ' , 'scanFile ' , array ( $ mount -> getMountPoint () . $ path ));
134+ $ this -> dispatcher -> dispatchTyped ( new BeforeFileScannedEvent ($ mount ->getMountPoint () . $ path ));
127135 });
128- $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'scanFolder ' , function ($ path ) use ($ mount , $ emitter ) {
129- $ emitter ->emit ('\OC\Files\Utils\Scanner ' , 'scanFolder ' , array ($ mount ->getMountPoint () . $ path ));
136+ $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'scanFolder ' , function ($ path ) use ($ mount ) {
137+ $ this ->emit ('\OC\Files\Utils\Scanner ' , 'scanFolder ' , array ($ mount ->getMountPoint () . $ path ));
138+ $ this ->dispatcher ->dispatchTyped (new BeforeFolderScannedEvent ($ mount ->getMountPoint () . $ path ));
130139 });
131- $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'postScanFile ' , function ($ path ) use ($ mount , $ emitter ) {
132- $ emitter ->emit ('\OC\Files\Utils\Scanner ' , 'postScanFile ' , array ($ mount ->getMountPoint () . $ path ));
140+ $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'postScanFile ' , function ($ path ) use ($ mount ) {
141+ $ this ->emit ('\OC\Files\Utils\Scanner ' , 'postScanFile ' , array ($ mount ->getMountPoint () . $ path ));
142+ $ this ->dispatcher ->dispatchTyped (new FileScannedEvent ($ mount ->getMountPoint () . $ path ));
133143 });
134- $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'postScanFolder ' , function ($ path ) use ($ mount , $ emitter ) {
135- $ emitter ->emit ('\OC\Files\Utils\Scanner ' , 'postScanFolder ' , array ($ mount ->getMountPoint () . $ path ));
144+ $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'postScanFolder ' , function ($ path ) use ($ mount ) {
145+ $ this ->emit ('\OC\Files\Utils\Scanner ' , 'postScanFolder ' , array ($ mount ->getMountPoint () . $ path ));
146+ $ this ->dispatcher ->dispatchTyped (new FolderScannedEvent ($ mount ->getMountPoint () . $ path ));
136147 });
137148 }
138149
@@ -225,12 +236,15 @@ public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECUR
225236
226237 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'removeFromCache ' , function ($ path ) use ($ storage ) {
227238 $ this ->postProcessEntry ($ storage , $ path );
239+ $ this ->dispatcher ->dispatchTyped (new NodeRemovedFromCache ($ storage , $ path ));
228240 });
229241 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'updateCache ' , function ($ path ) use ($ storage ) {
230242 $ this ->postProcessEntry ($ storage , $ path );
243+ $ this ->dispatcher ->dispatchTyped (new FileCacheUpdated ($ storage , $ path ));
231244 });
232245 $ scanner ->listen ('\OC\Files\Cache\Scanner ' , 'addToCache ' , function ($ path ) use ($ storage ) {
233246 $ this ->postProcessEntry ($ storage , $ path );
247+ $ this ->dispatcher ->dispatchTyped (new NodeAddedToCache ($ storage , $ path ));
234248 });
235249
236250 if (!$ storage ->file_exists ($ relativePath )) {
0 commit comments