]> source.dussan.org Git - nextcloud-server.git/commitdiff
Listen to cache event when deleting metadata 41634/head
authorLouis Chemineau <louis@chmn.me>
Tue, 21 Nov 2023 10:36:41 +0000 (11:36 +0100)
committerLouis <louis@chmn.me>
Tue, 21 Nov 2023 12:52:31 +0000 (13:52 +0100)
Signed-off-by: Louis Chemineau <louis@chmn.me>
lib/private/FilesMetadata/FilesMetadataManager.php
lib/private/FilesMetadata/Listener/MetadataDelete.php

index 187eed6776834fa40f9819478699233d4d1e65d9..28498af4ab014e0e531f72d6bd143deb86aa0683 100644 (file)
@@ -37,7 +37,7 @@ use OCP\DB\Exception;
 use OCP\DB\Exception as DBException;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\EventDispatcher\IEventDispatcher;
-use OCP\Files\Events\Node\NodeDeletedEvent;
+use OCP\Files\Cache\CacheEntryRemovedEvent;
 use OCP\Files\Events\Node\NodeWrittenEvent;
 use OCP\Files\InvalidPathException;
 use OCP\Files\Node;
@@ -305,6 +305,6 @@ class FilesMetadataManager implements IFilesMetadataManager {
         */
        public static function loadListeners(IEventDispatcher $eventDispatcher): void {
                $eventDispatcher->addServiceListener(NodeWrittenEvent::class, MetadataUpdate::class);
-               $eventDispatcher->addServiceListener(NodeDeletedEvent::class, MetadataDelete::class);
+               $eventDispatcher->addServiceListener(CacheEntryRemovedEvent::class, MetadataDelete::class);
        }
 }
index 25c944475a9ee515c4ffd9bfb7891794aa893a3b..d950c2cea5f30d5600bb9c932b83dc31312c9be4 100644 (file)
@@ -28,14 +28,14 @@ namespace OC\FilesMetadata\Listener;
 use Exception;
 use OCP\EventDispatcher\Event;
 use OCP\EventDispatcher\IEventListener;
-use OCP\Files\Events\Node\NodeDeletedEvent;
+use OCP\Files\Cache\CacheEntryRemovedEvent;
 use OCP\FilesMetadata\IFilesMetadataManager;
 use Psr\Log\LoggerInterface;
 
 /**
  * Handle file deletion event and remove stored metadata related to the deleted file
  *
- * @template-implements IEventListener<NodeDeletedEvent>
+ * @template-implements IEventListener<CacheEntryRemovedEvent>
  */
 class MetadataDelete implements IEventListener {
        public function __construct(
@@ -44,16 +44,13 @@ class MetadataDelete implements IEventListener {
        ) {
        }
 
-       /**
-        * @param Event $event
-        */
        public function handle(Event $event): void {
-               if (!($event instanceof NodeDeletedEvent)) {
+               if (!($event instanceof CacheEntryRemovedEvent)) {
                        return;
                }
 
                try {
-                       $nodeId = (int)$event->getNode()->getId();
+                       $nodeId = $event->getFileId();
                        if ($nodeId > 0) {
                                $this->filesMetadataManager->deleteMetadata($nodeId);
                        }