diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-05-27 18:36:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-27 18:36:40 +0200 |
commit | e4378fd18cb39407097f40431cd28c1fa01ba75d (patch) | |
tree | c4b3cd4a8fb79afe6a5ab680625c3664fdaa8f66 /lib | |
parent | ac79137816709b4adc6b2e21cc52c807381c4baf (diff) | |
parent | ae0e9ff0834e9446d14d58b5dfbc5cc90794f760 (diff) | |
download | nextcloud-server-e4378fd18cb39407097f40431cd28c1fa01ba75d.tar.gz nextcloud-server-e4378fd18cb39407097f40431cd28c1fa01ba75d.zip |
Merge pull request #32349 from nextcloud/enh/projects-event
Add event to load additional scripts for projects
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 4 | ||||
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/Collaboration/Resources/Listener.php | 33 | ||||
-rw-r--r-- | lib/public/Collaboration/Resources/LoadAdditionalScriptsEvent.php | 40 |
5 files changed, 72 insertions, 7 deletions
diff --git a/lib/base.php b/lib/base.php index f6a3331a798..82dcd5965aa 100644 --- a/lib/base.php +++ b/lib/base.php @@ -62,9 +62,11 @@ * */ +use OC\EventDispatcher\SymfonyAdapter; use OCP\EventDispatcher\IEventDispatcher; use OCP\Group\Events\UserRemovedEvent; use OCP\ILogger; +use OCP\Server; use OCP\Share; use OC\Encryption\HookManager; use OC\Files\Filesystem; @@ -888,7 +890,7 @@ class OC { } private static function registerResourceCollectionHooks() { - \OC\Collaboration\Resources\Listener::register(\OC::$server->getEventDispatcher()); + \OC\Collaboration\Resources\Listener::register(Server::get(SymfonyAdapter::class), Server::get(IEventDispatcher::class)); } /** diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index d4e2cbe7c8e..ae80dc78b03 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -148,6 +148,7 @@ return array( 'OCP\\Collaboration\\Resources\\IProvider' => $baseDir . '/lib/public/Collaboration/Resources/IProvider.php', 'OCP\\Collaboration\\Resources\\IProviderManager' => $baseDir . '/lib/public/Collaboration/Resources/IProviderManager.php', 'OCP\\Collaboration\\Resources\\IResource' => $baseDir . '/lib/public/Collaboration/Resources/IResource.php', + 'OCP\\Collaboration\\Resources\\LoadAdditionalScriptsEvent' => $baseDir . '/lib/public/Collaboration/Resources/LoadAdditionalScriptsEvent.php', 'OCP\\Collaboration\\Resources\\ResourceException' => $baseDir . '/lib/public/Collaboration/Resources/ResourceException.php', 'OCP\\Command\\IBus' => $baseDir . '/lib/public/Command/IBus.php', 'OCP\\Command\\ICommand' => $baseDir . '/lib/public/Command/ICommand.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index d1997b2b785..327c44a739c 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -177,6 +177,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Collaboration\\Resources\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/IProvider.php', 'OCP\\Collaboration\\Resources\\IProviderManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/IProviderManager.php', 'OCP\\Collaboration\\Resources\\IResource' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/IResource.php', + 'OCP\\Collaboration\\Resources\\LoadAdditionalScriptsEvent' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/LoadAdditionalScriptsEvent.php', 'OCP\\Collaboration\\Resources\\ResourceException' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/ResourceException.php', 'OCP\\Command\\IBus' => __DIR__ . '/../../..' . '/lib/public/Command/IBus.php', 'OCP\\Command\\ICommand' => __DIR__ . '/../../..' . '/lib/public/Command/ICommand.php', diff --git a/lib/private/Collaboration/Resources/Listener.php b/lib/private/Collaboration/Resources/Listener.php index ba012b4ca44..b9f1e72cbfa 100644 --- a/lib/private/Collaboration/Resources/Listener.php +++ b/lib/private/Collaboration/Resources/Listener.php @@ -26,14 +26,16 @@ declare(strict_types=1); */ namespace OC\Collaboration\Resources; +use OC\EventDispatcher\SymfonyAdapter; use OCP\Collaboration\Resources\IManager; +use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IGroup; use OCP\IUser; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; class Listener { - public static function register(EventDispatcherInterface $dispatcher): void { + public static function register(SymfonyAdapter $symfonyDispatcher, IEventDispatcher $eventDispatcher): void { $listener = function (GenericEvent $event) { /** @var IUser $user */ $user = $event->getArgument('user'); @@ -42,10 +44,10 @@ class Listener { $resourceManager->invalidateAccessCacheForUser($user); }; - $dispatcher->addListener(IGroup::class . '::postAddUser', $listener); - $dispatcher->addListener(IGroup::class . '::postRemoveUser', $listener); + $symfonyDispatcher->addListener(IGroup::class . '::postAddUser', $listener); + $symfonyDispatcher->addListener(IGroup::class . '::postRemoveUser', $listener); - $dispatcher->addListener(IUser::class . '::postDelete', function (GenericEvent $event) { + $symfonyDispatcher->addListener(IUser::class . '::postDelete', function (GenericEvent $event) { /** @var IUser $user */ $user = $event->getSubject(); /** @var IManager $resourceManager */ @@ -54,7 +56,7 @@ class Listener { $resourceManager->invalidateAccessCacheForUser($user); }); - $dispatcher->addListener(IGroup::class . '::preDelete', function (GenericEvent $event) { + $symfonyDispatcher->addListener(IGroup::class . '::preDelete', function (GenericEvent $event) { /** @var IGroup $group */ $group = $event->getSubject(); /** @var IManager $resourceManager */ @@ -64,5 +66,24 @@ class Listener { $resourceManager->invalidateAccessCacheForUser($user); } }); + + // Stay backward compatible with the legacy event for now + $fallbackEventRunning = false; + $symfonyDispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () use ($eventDispatcher, &$fallbackEventRunning) { + if ($fallbackEventRunning) { + return; + } + $fallbackEventRunning = true; + $eventDispatcher->dispatchTyped(new LoadAdditionalScriptsEvent()); + $fallbackEventRunning = false; + }); + $eventDispatcher->addListener(LoadAdditionalScriptsEvent::class, static function () use ($symfonyDispatcher, &$fallbackEventRunning) { + if ($fallbackEventRunning) { + return; + } + $fallbackEventRunning = true; + $symfonyDispatcher->dispatch('\OCP\Collaboration\Resources::loadAdditionalScripts'); + $fallbackEventRunning = false; + }); } } diff --git a/lib/public/Collaboration/Resources/LoadAdditionalScriptsEvent.php b/lib/public/Collaboration/Resources/LoadAdditionalScriptsEvent.php new file mode 100644 index 00000000000..2f1dc5a0a00 --- /dev/null +++ b/lib/public/Collaboration/Resources/LoadAdditionalScriptsEvent.php @@ -0,0 +1,40 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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 OCP\Collaboration\Resources; + +use OCP\EventDispatcher\Event; + +/** + * This event is used by apps to register their own frontend scripts for integrating + * projects in their app. Apps also need to dispatch the event in order to load + * scripts during page load + * + * @see https://docs.nextcloud.com/server/latest/developer_manual/digging_deeper/projects.html + * @since 25.0.0 + */ +class LoadAdditionalScriptsEvent extends Event { +} |