]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(files_trashbin): Migrate to IEventDispatcher and emit as typed event
authorJoas Schilling <coding@schilljs.com>
Fri, 7 Jul 2023 09:27:29 +0000 (11:27 +0200)
committerJoas Schilling <coding@schilljs.com>
Wed, 19 Jul 2023 15:37:33 +0000 (17:37 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/files_trashbin/lib/Events/MoveToTrashEvent.php
apps/files_trashbin/lib/Storage.php
apps/files_trashbin/tests/StorageTest.php

index 3dce70f96bdd819ef0c3d1698890b8f4db2ffe61..c07d7822e3acb96cc6e212267ce380c521cf0d54 100644 (file)
@@ -33,6 +33,7 @@ use OCP\Files\Node;
  * Event to allow other apps to disable the trash bin for specific files
  *
  * @package OCA\Files_Trashbin\Events
+ * @since 28.0.0 Dispatched as a typed event
  */
 class MoveToTrashEvent extends Event {
 
index f08d8d25a55a97afdcda61f3701e073e28671f6e..68d0951b6947ca7bc8f2c466651f6c3ede738d1d 100644 (file)
@@ -33,13 +33,13 @@ use OC\Files\Storage\Wrapper\Wrapper;
 use OCA\Files_Trashbin\Events\MoveToTrashEvent;
 use OCA\Files_Trashbin\Trash\ITrashManager;
 use OCP\Encryption\Exceptions\GenericEncryptionException;
+use OCP\EventDispatcher\IEventDispatcher;
 use OCP\Files\IRootFolder;
 use OCP\Files\Mount\IMountPoint;
 use OCP\Files\Node;
 use OCP\Files\Storage\IStorage;
 use OCP\ILogger;
 use OCP\IUserManager;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 class Storage extends Wrapper {
        /** @var IMountPoint */
@@ -51,7 +51,7 @@ class Storage extends Wrapper {
        /** @var ILogger */
        private $logger;
 
-       /** @var EventDispatcherInterface */
+       /** @var IEventDispatcher */
        private $eventDispatcher;
 
        /** @var IRootFolder */
@@ -69,7 +69,7 @@ class Storage extends Wrapper {
         * @param ITrashManager $trashManager
         * @param IUserManager|null $userManager
         * @param ILogger|null $logger
-        * @param EventDispatcherInterface|null $eventDispatcher
+        * @param IEventDispatcher|null $eventDispatcher
         * @param IRootFolder|null $rootFolder
         */
        public function __construct(
@@ -77,7 +77,7 @@ class Storage extends Wrapper {
                ITrashManager $trashManager = null,
                IUserManager $userManager = null,
                ILogger $logger = null,
-               EventDispatcherInterface $eventDispatcher = null,
+               IEventDispatcher $eventDispatcher = null,
                IRootFolder $rootFolder = null
        ) {
                $this->mountPoint = $parameters['mountPoint'];
@@ -153,6 +153,7 @@ class Storage extends Wrapper {
 
                foreach ($nodes as $node) {
                        $event = $this->createMoveToTrashEvent($node);
+                       $this->eventDispatcher->dispatchTyped($event);
                        $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event);
                        if ($event->shouldMoveToTrashBin() === false) {
                                return false;
@@ -217,7 +218,7 @@ class Storage extends Wrapper {
                                \OC::$server->query(ITrashManager::class),
                                \OC::$server->getUserManager(),
                                \OC::$server->getLogger(),
-                               \OC::$server->getEventDispatcher(),
+                               \OC::$server->get(IEventDispatcher::class),
                                \OC::$server->getLazyRootFolder()
                        );
                }, 1);
index 15b47385d45545c4ecfb3311d52d6cf60c1a67d4..b4b995c3ae59043d1ef2ff98da55c2b2f9404e75 100644 (file)
@@ -41,6 +41,7 @@ use OCA\Files_Trashbin\Storage;
 use OCA\Files_Trashbin\Trash\ITrashManager;
 use OCP\AppFramework\Bootstrap\IBootContext;
 use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
 use OCP\Files\Cache\ICache;
 use OCP\Files\Folder;
 use OCP\Files\IRootFolder;
@@ -50,7 +51,6 @@ use OCP\ILogger;
 use OCP\IUserManager;
 use OCP\Lock\ILockingProvider;
 use OCP\Share\IShare;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Test\Traits\MountProviderTrait;
 
 class TemporaryNoCross extends Temporary {
@@ -607,7 +607,7 @@ class StorageTest extends \Test\TestCase {
                $userManager->expects($this->any())
                        ->method('userExists')->willReturn($userExists);
                $logger = $this->getMockBuilder(ILogger::class)->getMock();
-               $eventDispatcher = $this->createMock(EventDispatcherInterface::class);
+               $eventDispatcher = $this->createMock(IEventDispatcher::class);
                $rootFolder = $this->createMock(IRootFolder::class);
                $userFolder = $this->createMock(Folder::class);
                $node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();