diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-08-04 10:39:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-04 10:39:57 +0200 |
commit | 44b4c16a091592203df51c19d0be1b520bc3ad9b (patch) | |
tree | 25ee31ab54832dc2bc984f4f91940c30dcb8ac33 /apps/files | |
parent | f8bd676154f988ef2130ccb0e29b0cc95e42a204 (diff) | |
parent | 3962cd0aa8ab7530deffa3b41cab2e11a01fd14a (diff) | |
download | nextcloud-server-44b4c16a091592203df51c19d0be1b520bc3ad9b.tar.gz nextcloud-server-44b4c16a091592203df51c19d0be1b520bc3ad9b.zip |
Merge pull request #39605 from nextcloud/bugfix/noid/final-events-cleanup
fix!: Final round of moving to IEventDispatcher
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | apps/files/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | apps/files/lib/AppInfo/Application.php | 5 | ||||
-rw-r--r-- | apps/files/lib/Collaboration/Resources/Listener.php | 9 | ||||
-rw-r--r-- | apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php | 57 | ||||
-rw-r--r-- | apps/files/lib/Service/TagService.php | 21 | ||||
-rw-r--r-- | apps/files/tests/Service/TagServiceTest.php | 6 |
7 files changed, 22 insertions, 78 deletions
diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index c6d03ffd3be..0f3e01b5b53 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -57,7 +57,6 @@ return array( 'OCA\\Files\\Event\\LoadSidebar' => $baseDir . '/../lib/Event/LoadSidebar.php', 'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir . '/../lib/Exception/TransferOwnershipException.php', 'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php', - 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', 'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files\\Listener\\RenderReferenceEventListener' => $baseDir . '/../lib/Listener/RenderReferenceEventListener.php', 'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php', diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php index 2cb71917bd6..2b152c734f1 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -72,7 +72,6 @@ class ComposerStaticInitFiles 'OCA\\Files\\Event\\LoadSidebar' => __DIR__ . '/..' . '/../lib/Event/LoadSidebar.php', 'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php', 'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php', - 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', 'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files\\Listener\\RenderReferenceEventListener' => __DIR__ . '/..' . '/../lib/Listener/RenderReferenceEventListener.php', 'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php', diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index 3cbe8d9d950..feba7b09178 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -42,7 +42,6 @@ use OCA\Files\Controller\ApiController; use OCA\Files\DirectEditingCapabilities; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files\Event\LoadSidebar; -use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter; use OCA\Files\Listener\LoadSidebarListener; use OCA\Files\Listener\RenderReferenceEventListener; use OCA\Files\Notification\Notifier; @@ -57,6 +56,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Collaboration\Reference\RenderReferenceEvent; use OCP\Collaboration\Resources\IProviderManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IL10N; use OCP\IPreview; @@ -110,7 +110,7 @@ class Application extends App implements IBootstrap { $c->get(IActivityManager::class), $c->get(ITagManager::class)->load(self::APP_ID), $server->getUserFolder(), - $server->getEventDispatcher() + $c->get(IEventDispatcher::class), ); }); @@ -120,7 +120,6 @@ class Application extends App implements IBootstrap { $context->registerCapability(Capabilities::class); $context->registerCapability(DirectEditingCapabilities::class); - $context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class); $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class); $context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class); diff --git a/apps/files/lib/Collaboration/Resources/Listener.php b/apps/files/lib/Collaboration/Resources/Listener.php index 28ce5f87897..e37bf0e9610 100644 --- a/apps/files/lib/Collaboration/Resources/Listener.php +++ b/apps/files/lib/Collaboration/Resources/Listener.php @@ -28,12 +28,15 @@ namespace OCA\Files\Collaboration\Resources; use OCP\EventDispatcher\IEventDispatcher; use OCP\Server; use OCP\Collaboration\Resources\IManager; +use OCP\Share\Events\ShareCreatedEvent; +use OCP\Share\Events\ShareDeletedEvent; +use OCP\Share\Events\ShareDeletedFromSelfEvent; class Listener { public static function register(IEventDispatcher $dispatcher): void { - $dispatcher->addListener('OCP\Share::postShare', [self::class, 'shareModification']); - $dispatcher->addListener('OCP\Share::postUnshare', [self::class, 'shareModification']); - $dispatcher->addListener('OCP\Share::postUnshareFromSelf', [self::class, 'shareModification']); + $dispatcher->addListener(ShareCreatedEvent::class, [self::class, 'shareModification']); + $dispatcher->addListener(ShareDeletedEvent::class, [self::class, 'shareModification']); + $dispatcher->addListener(ShareDeletedFromSelfEvent::class, [self::class, 'shareModification']); } public static function shareModification(): void { diff --git a/apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php b/apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php deleted file mode 100644 index f60f9d73d78..00000000000 --- a/apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -declare(strict_types=1); - -/** - * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Joas Schilling <coding@schilljs.com> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -namespace OCA\Files\Listener; - -use OC\EventDispatcher\SymfonyAdapter; -use OCA\Files\Event\LoadAdditionalScriptsEvent; -use OCP\EventDispatcher\Event; -use OCP\EventDispatcher\IEventListener; -use Symfony\Component\EventDispatcher\GenericEvent; - -class LegacyLoadAdditionalScriptsAdapter implements IEventListener { - - /** @var SymfonyAdapter */ - private $dispatcher; - - public function __construct(SymfonyAdapter $dispatcher) { - $this->dispatcher = $dispatcher; - } - - public function handle(Event $event): void { - if (!($event instanceof LoadAdditionalScriptsEvent)) { - return; - } - - $legacyEvent = new GenericEvent(null, ['hiddenFields' => []]); - $this->dispatcher->dispatch('OCA\Files::loadAdditionalScripts', $legacyEvent); - - $hiddenFields = $legacyEvent->getArgument('hiddenFields'); - foreach ($hiddenFields as $name => $value) { - $event->addHiddenField($name, $value); - } - } -} diff --git a/apps/files/lib/Service/TagService.php b/apps/files/lib/Service/TagService.php index af4f7d0ef1e..e29848bf21d 100644 --- a/apps/files/lib/Service/TagService.php +++ b/apps/files/lib/Service/TagService.php @@ -26,12 +26,13 @@ namespace OCA\Files\Service; use OCA\Files\Activity\FavoriteProvider; use OCP\Activity\IManager; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\NodeAddedToFavorite; +use OCP\Files\Events\NodeRemovedFromFavorite; use OCP\Files\Folder; use OCP\ITags; use OCP\IUser; use OCP\IUserSession; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; /** * Service class to manage tags on files. @@ -46,7 +47,7 @@ class TagService { private $tagger; /** @var Folder|null */ private $homeFolder; - /** @var EventDispatcherInterface */ + /** @var IEventDispatcher */ private $dispatcher; public function __construct( @@ -54,7 +55,7 @@ class TagService { IManager $activityManager, ?ITags $tagger, ?Folder $homeFolder, - EventDispatcherInterface $dispatcher + IEventDispatcher $dispatcher, ) { $this->userSession = $userSession; $this->activityManager = $activityManager; @@ -120,12 +121,12 @@ class TagService { return; } - $eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite'; - $this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [ - 'userId' => $user->getUID(), - 'fileId' => $fileId, - 'path' => $path, - ])); + if ($addToFavorite) { + $event = new NodeAddedToFavorite($user, $fileId, $path); + } else { + $event = new NodeRemovedFromFavorite($user, $fileId, $path); + } + $this->dispatcher->dispatchTyped($event); $event = $this->activityManager->generateEvent(); try { diff --git a/apps/files/tests/Service/TagServiceTest.php b/apps/files/tests/Service/TagServiceTest.php index dce01e7170f..2b9bc5be460 100644 --- a/apps/files/tests/Service/TagServiceTest.php +++ b/apps/files/tests/Service/TagServiceTest.php @@ -29,10 +29,10 @@ namespace OCA\Files\Tests\Service; use OCA\Files\Service\TagService; use OCP\Activity\IManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\ITags; use OCP\IUser; use OCP\IUserSession; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Class TagServiceTest @@ -59,7 +59,7 @@ class TagServiceTest extends \Test\TestCase { */ private $root; - /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ private $dispatcher; /** @@ -90,7 +90,7 @@ class TagServiceTest extends \Test\TestCase { ->willReturn($user); $this->root = \OC::$server->getUserFolder(); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->tagger = \OC::$server->getTagManager()->load('files'); $this->tagService = $this->getTagService(['addActivity']); |