diff options
author | Joas Schilling <coding@schilljs.com> | 2023-07-27 19:44:42 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-07-28 14:11:18 +0200 |
commit | 9bf812ac6c29f7722ba6db876dbabbc1b065dce1 (patch) | |
tree | bfccaf4388810c3db315734bac5e08343680a3bc /apps | |
parent | 53392861ff2a2786c9be565a9d5fb09eb652f29a (diff) | |
download | nextcloud-server-9bf812ac6c29f7722ba6db876dbabbc1b065dce1.tar.gz nextcloud-server-9bf812ac6c29f7722ba6db876dbabbc1b065dce1.zip |
feat!: Migrate TagService events to typed events
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/lib/AppInfo/Application.php | 3 | ||||
-rw-r--r-- | apps/files/lib/Service/TagService.php | 21 | ||||
-rw-r--r-- | apps/files/tests/Service/TagServiceTest.php | 6 |
3 files changed, 16 insertions, 14 deletions
diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index 7021769752e..09db1be7570 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -57,6 +57,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 +111,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), ); }); 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']); |