From 44b810bfbd83fc6eb95a67430894dbd2cf6eb339 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 27 Jul 2023 21:45:31 +0200 Subject: feat!: Migrate Sharing events to typed events Signed-off-by: Joas Schilling --- apps/files_sharing/lib/AppInfo/Application.php | 5 +---- apps/files_sharing/lib/Notification/Listener.php | 9 +++------ 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'apps/files_sharing/lib') diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 65197e9b270..8f5fe7aca5b 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -143,10 +143,7 @@ class Application extends App implements IBootstrap { }); // notifications api to accept incoming user shares - $dispatcher->addListener('OCP\Share::postShare', function ($event) { - if (!$event instanceof OldGenericEvent) { - return; - } + $dispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) { /** @var Listener $listener */ $listener = $this->getContainer()->query(Listener::class); $listener->shareNotification($event); diff --git a/apps/files_sharing/lib/Notification/Listener.php b/apps/files_sharing/lib/Notification/Listener.php index db7939767d6..b6d30cdb3f5 100644 --- a/apps/files_sharing/lib/Notification/Listener.php +++ b/apps/files_sharing/lib/Notification/Listener.php @@ -31,6 +31,7 @@ use OCP\IGroupManager; use OCP\IUser; use OCP\Notification\IManager as INotificationManager; use OCP\Notification\INotification; +use OCP\Share\Events\ShareCreatedEvent; use OCP\Share\IManager as IShareManager; use OCP\Share\IShare; use Symfony\Component\EventDispatcher\GenericEvent; @@ -54,12 +55,8 @@ class Listener { $this->groupManager = $groupManager; } - /** - * @param GenericEvent $event - */ - public function shareNotification(GenericEvent $event): void { - /** @var IShare $share */ - $share = $event->getSubject(); + public function shareNotification(ShareCreatedEvent $event): void { + $share = $event->getShare(); $notification = $this->instantiateNotification($share); if ($share->getShareType() === IShare::TYPE_USER) { -- cgit v1.2.3 From c5dcf3c849639c4f54d6cd903b31be9b1cefe71e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 27 Jul 2023 23:08:15 +0200 Subject: fix!: Remove LegacyBeforeTemplateRenderedListener from files_sharing Signed-off-by: Joas Schilling --- .../composer/composer/autoload_classmap.php | 1 - .../composer/composer/autoload_static.php | 1 - apps/files_sharing/lib/AppInfo/Application.php | 2 - .../LegacyBeforeTemplateRenderedListener.php | 57 ---------------------- 4 files changed, 61 deletions(-) delete mode 100644 apps/files_sharing/lib/Listener/LegacyBeforeTemplateRenderedListener.php (limited to 'apps/files_sharing/lib') diff --git a/apps/files_sharing/composer/composer/autoload_classmap.php b/apps/files_sharing/composer/composer/autoload_classmap.php index a82d721b1bd..b5da8c44ecc 100644 --- a/apps/files_sharing/composer/composer/autoload_classmap.php +++ b/apps/files_sharing/composer/composer/autoload_classmap.php @@ -55,7 +55,6 @@ return array( 'OCA\\Files_Sharing\\Helper' => $baseDir . '/../lib/Helper.php', 'OCA\\Files_Sharing\\Hooks' => $baseDir . '/../lib/Hooks.php', 'OCA\\Files_Sharing\\ISharedStorage' => $baseDir . '/../lib/ISharedStorage.php', - 'OCA\\Files_Sharing\\Listener\\LegacyBeforeTemplateRenderedListener' => $baseDir . '/../lib/Listener/LegacyBeforeTemplateRenderedListener.php', 'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => $baseDir . '/../lib/Listener/LoadAdditionalListener.php', 'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files_Sharing\\Listener\\ShareInteractionListener' => $baseDir . '/../lib/Listener/ShareInteractionListener.php', diff --git a/apps/files_sharing/composer/composer/autoload_static.php b/apps/files_sharing/composer/composer/autoload_static.php index 63d0bae8995..779bdb317b9 100644 --- a/apps/files_sharing/composer/composer/autoload_static.php +++ b/apps/files_sharing/composer/composer/autoload_static.php @@ -70,7 +70,6 @@ class ComposerStaticInitFiles_Sharing 'OCA\\Files_Sharing\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php', 'OCA\\Files_Sharing\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', 'OCA\\Files_Sharing\\ISharedStorage' => __DIR__ . '/..' . '/../lib/ISharedStorage.php', - 'OCA\\Files_Sharing\\Listener\\LegacyBeforeTemplateRenderedListener' => __DIR__ . '/..' . '/../lib/Listener/LegacyBeforeTemplateRenderedListener.php', 'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalListener.php', 'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files_Sharing\\Listener\\ShareInteractionListener' => __DIR__ . '/..' . '/../lib/Listener/ShareInteractionListener.php', diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 8f5fe7aca5b..d89419b8ea9 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -37,7 +37,6 @@ use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; use OCA\Files_Sharing\External\Manager; use OCA\Files_Sharing\External\MountProvider as ExternalMountProvider; use OCA\Files_Sharing\Helper; -use OCA\Files_Sharing\Listener\LegacyBeforeTemplateRenderedListener; use OCA\Files_Sharing\Listener\LoadAdditionalListener; use OCA\Files_Sharing\Listener\LoadSidebarListener; use OCA\Files_Sharing\Listener\ShareInteractionListener; @@ -133,7 +132,6 @@ class Application extends App implements IBootstrap { public function registerEventsScripts(IEventDispatcher $dispatcher): void { // sidebar and files scripts $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); - $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class); $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); diff --git a/apps/files_sharing/lib/Listener/LegacyBeforeTemplateRenderedListener.php b/apps/files_sharing/lib/Listener/LegacyBeforeTemplateRenderedListener.php deleted file mode 100644 index e7e81c3a17a..00000000000 --- a/apps/files_sharing/lib/Listener/LegacyBeforeTemplateRenderedListener.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * @author Julius Härtl - * - * @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 . - * - */ -namespace OCA\Files_Sharing\Listener; - -use OC\EventDispatcher\SymfonyAdapter; -use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; -use OCP\EventDispatcher\Event; -use OCP\EventDispatcher\IEventListener; -use Symfony\Component\EventDispatcher\GenericEvent; - -class LegacyBeforeTemplateRenderedListener implements IEventListener { - - /** @var SymfonyAdapter */ - private $dispatcher; - - public function __construct(SymfonyAdapter $dispatcher) { - $this->dispatcher = $dispatcher; - } - - public function handle(Event $event): void { - if (!($event instanceof BeforeTemplateRenderedEvent)) { - return; - } - - $eventName = 'OCA\Files_Sharing::loadAdditionalScripts'; - - if ($event->getScope() !== null) { - $eventName .= '::' . $event->getScope(); - } - - $legacyEvent = new GenericEvent(null, ['share' => $event->getShare()]); - $this->dispatcher->dispatch($eventName, $legacyEvent); - } -} -- cgit v1.2.3