4141use Doctrine \DBAL \Driver \Statement ;
4242use Doctrine \DBAL \Exception \UniqueConstraintViolationException ;
4343use OCP \DB \QueryBuilder \IQueryBuilder ;
44+ use OCP \EventDispatcher \IEventDispatcher ;
45+ use OCP \Files \Cache \CacheEntryInsertedEvent ;
46+ use OCP \Files \Cache \CacheEntryUpdatedEvent ;
4447use OCP \Files \Cache \CacheInsertEvent ;
45- use OCP \Files \Cache \CacheRemoveEvent ;
48+ use OCP \Files \Cache \CacheEntryRemovedEvent ;
4649use OCP \Files \Cache \CacheUpdateEvent ;
4750use OCP \Files \Cache \ICache ;
4851use OCP \Files \Cache \ICacheEntry ;
@@ -92,6 +95,9 @@ class Cache implements ICache {
9295 */
9396 protected $ connection ;
9497
98+ /**
99+ * @var IEventDispatcher
100+ */
95101 protected $ eventDispatcher ;
96102
97103 /** @var QuerySearchHelper */
@@ -110,7 +116,7 @@ public function __construct(IStorage $storage) {
110116 $ this ->storageCache = new Storage ($ storage );
111117 $ this ->mimetypeLoader = \OC ::$ server ->getMimeTypeLoader ();
112118 $ this ->connection = \OC ::$ server ->getDatabaseConnection ();
113- $ this ->eventDispatcher = \OC ::$ server ->getEventDispatcher ( );
119+ $ this ->eventDispatcher = \OC ::$ server ->get (IEventDispatcher::class );
114120 $ this ->querySearchHelper = new QuerySearchHelper ($ this ->mimetypeLoader );
115121 }
116122
@@ -310,7 +316,9 @@ public function insert($file, array $data) {
310316 $ query ->execute ();
311317 }
312318
313- $ this ->eventDispatcher ->dispatch (CacheInsertEvent::class, new CacheInsertEvent ($ this ->storage , $ file , $ fileId , $ storageId ));
319+ $ event = new CacheEntryInsertedEvent ($ this ->storage , $ file , $ fileId , $ storageId );
320+ $ this ->eventDispatcher ->dispatch (CacheInsertEvent::class, $ event );
321+ $ this ->eventDispatcher ->dispatchTyped ($ event );
314322 return $ fileId ;
315323 }
316324 } catch (UniqueConstraintViolationException $ e ) {
@@ -401,7 +409,9 @@ public function update($id, array $data) {
401409 $ path = $ this ->getPathById ($ id );
402410 // path can still be null if the file doesn't exist
403411 if ($ path !== null ) {
404- $ this ->eventDispatcher ->dispatch (CacheUpdateEvent::class, new CacheUpdateEvent ($ this ->storage , $ path , $ id , $ this ->getNumericStorageId ()));
412+ $ event = new CacheEntryUpdatedEvent ($ this ->storage , $ path , $ id , $ this ->getNumericStorageId ());
413+ $ this ->eventDispatcher ->dispatch (CacheUpdateEvent::class, $ event );
414+ $ this ->eventDispatcher ->dispatchTyped ($ event );
405415 }
406416 }
407417
@@ -539,7 +549,7 @@ public function remove($file) {
539549 $ this ->removeChildren ($ entry );
540550 }
541551
542- $ this ->eventDispatcher ->dispatch (CacheRemoveEvent ::class, new CacheRemoveEvent ($ this ->storage , $ entry ->getPath (), $ entry ->getId (), $ this ->getNumericStorageId ()));
552+ $ this ->eventDispatcher ->dispatch (CacheEntryRemovedEvent ::class, new CacheEntryRemovedEvent ($ this ->storage , $ entry ->getPath (), $ entry ->getId (), $ this ->getNumericStorageId ()));
543553 }
544554 }
545555
@@ -683,10 +693,14 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
683693 $ this ->connection ->commit ();
684694
685695 if ($ sourceCache ->getNumericStorageId () !== $ this ->getNumericStorageId ()) {
686- $ this ->eventDispatcher ->dispatch (CacheRemoveEvent::class, new CacheRemoveEvent ($ this ->storage , $ sourcePath , $ sourceId , $ sourceCache ->getNumericStorageId ()));
687- $ this ->eventDispatcher ->dispatch (CacheInsertEvent::class, new CacheInsertEvent ($ this ->storage , $ targetPath , $ sourceId , $ this ->getNumericStorageId ()));
696+ $ this ->eventDispatcher ->dispatchTyped (new CacheEntryRemovedEvent ($ this ->storage , $ sourcePath , $ sourceId , $ sourceCache ->getNumericStorageId ()));
697+ $ event = new CacheEntryInsertedEvent ($ this ->storage , $ targetPath , $ sourceId , $ this ->getNumericStorageId ());
698+ $ this ->eventDispatcher ->dispatch (CacheInsertEvent::class, $ event );
699+ $ this ->eventDispatcher ->dispatchTyped ($ event );
688700 } else {
689- $ this ->eventDispatcher ->dispatch (CacheUpdateEvent::class, new CacheUpdateEvent ($ this ->storage , $ targetPath , $ sourceId , $ this ->getNumericStorageId ()));
701+ $ event = new CacheEntryUpdatedEvent ($ this ->storage , $ targetPath , $ sourceId , $ this ->getNumericStorageId ());
702+ $ this ->eventDispatcher ->dispatch (CacheUpdateEvent::class, $ event );
703+ $ this ->eventDispatcher ->dispatchTyped ($ event );
690704 }
691705 } else {
692706 $ this ->moveFromCacheFallback ($ sourceCache , $ sourcePath , $ targetPath );
0 commit comments