diff options
author | Thomas Citharel <tcit@tcit.fr> | 2022-12-08 10:55:19 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2023-03-13 11:52:57 +0100 |
commit | f1751c44286930ea4ef41b046cdc4570330ee301 (patch) | |
tree | d5e403dfc0ab94bcf73a0490edba8de0e5365150 /lib | |
parent | ade49e0b15e408bf00dd24f5641bd9a29a18f05c (diff) | |
download | nextcloud-server-f1751c44286930ea4ef41b046cdc4570330ee301.tar.gz nextcloud-server-f1751c44286930ea4ef41b046cdc4570330ee301.zip |
Introduced app enable/disable/update typed events
OCP\App\ManagerEvent is depreciated since 22 without a replacement
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 3 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 3 | ||||
-rw-r--r-- | lib/private/App/AppManager.php | 29 | ||||
-rw-r--r-- | lib/private/Server.php | 1 | ||||
-rw-r--r-- | lib/private/legacy/OC_App.php | 6 | ||||
-rw-r--r-- | lib/public/App/Events/AppDisableEvent.php | 51 | ||||
-rw-r--r-- | lib/public/App/Events/AppEnableEvent.php | 62 | ||||
-rw-r--r-- | lib/public/App/Events/AppUpdateEvent.php | 51 |
8 files changed, 196 insertions, 10 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index ee6117f9b73..1ecd8152c0f 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -82,6 +82,9 @@ return array( 'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => $baseDir . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php', 'OCP\\AppFramework\\Utility\\ITimeFactory' => $baseDir . '/lib/public/AppFramework/Utility/ITimeFactory.php', 'OCP\\App\\AppPathNotFoundException' => $baseDir . '/lib/public/App/AppPathNotFoundException.php', + 'OCP\\App\\Events\\AppDisableEvent' => $baseDir . '/lib/public/App/Events/AppDisableEvent.php', + 'OCP\\App\\Events\\AppEnableEvent' => $baseDir . '/lib/public/App/Events/AppEnableEvent.php', + 'OCP\\App\\Events\\AppUpdateEvent' => $baseDir . '/lib/public/App/Events/AppUpdateEvent.php', 'OCP\\App\\IAppManager' => $baseDir . '/lib/public/App/IAppManager.php', 'OCP\\App\\ManagerEvent' => $baseDir . '/lib/public/App/ManagerEvent.php', 'OCP\\Authentication\\Events\\AnyLoginFailedEvent' => $baseDir . '/lib/public/Authentication/Events/AnyLoginFailedEvent.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 253b9ddbada..2127835e514 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -115,6 +115,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php', 'OCP\\AppFramework\\Utility\\ITimeFactory' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/ITimeFactory.php', 'OCP\\App\\AppPathNotFoundException' => __DIR__ . '/../../..' . '/lib/public/App/AppPathNotFoundException.php', + 'OCP\\App\\Events\\AppDisableEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppDisableEvent.php', + 'OCP\\App\\Events\\AppEnableEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppEnableEvent.php', + 'OCP\\App\\Events\\AppUpdateEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppUpdateEvent.php', 'OCP\\App\\IAppManager' => __DIR__ . '/../../..' . '/lib/public/App/IAppManager.php', 'OCP\\App\\ManagerEvent' => __DIR__ . '/../../..' . '/lib/public/App/ManagerEvent.php', 'OCP\\Authentication\\Events\\AnyLoginFailedEvent' => __DIR__ . '/../../..' . '/lib/public/Authentication/Events/AnyLoginFailedEvent.php', diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index d14f0a2644e..0a89711f178 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -40,8 +40,11 @@ namespace OC\App; use OC\AppConfig; use OCP\App\AppPathNotFoundException; +use OCP\App\Events\AppDisableEvent; +use OCP\App\Events\AppEnableEvent; use OCP\App\IAppManager; use OCP\App\ManagerEvent; +use OCP\EventDispatcher\IEventDispatcher; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; @@ -80,7 +83,9 @@ class AppManager implements IAppManager { private $memCacheFactory; /** @var EventDispatcherInterface */ - private $dispatcher; + private $legacyDispatcher; + + private IEventDispatcher $dispatcher; /** @var LoggerInterface */ private $logger; @@ -108,13 +113,15 @@ class AppManager implements IAppManager { AppConfig $appConfig, IGroupManager $groupManager, ICacheFactory $memCacheFactory, - EventDispatcherInterface $dispatcher, + EventDispatcherInterface $legacyDispatcher, + IEventDispatcher $dispatcher, LoggerInterface $logger) { $this->userSession = $userSession; $this->config = $config; $this->appConfig = $appConfig; $this->groupManager = $groupManager; $this->memCacheFactory = $memCacheFactory; + $this->legacyDispatcher = $legacyDispatcher; $this->dispatcher = $dispatcher; $this->logger = $logger; } @@ -163,7 +170,7 @@ class AppManager implements IAppManager { } /** - * @param \OCP\IGroup $group + * @param IGroup $group * @return array */ public function getEnabledAppsForGroup(IGroup $group): array { @@ -287,7 +294,7 @@ class AppManager implements IAppManager { * Notice: This actually checks if the app is enabled and not only if it is installed. * * @param string $appId - * @param \OCP\IGroup[]|String[] $groups + * @param IGroup[]|String[] $groups * @return bool */ public function isInstalled($appId) { @@ -320,7 +327,8 @@ class AppManager implements IAppManager { $this->installedAppsCache[$appId] = 'yes'; $this->appConfig->setValue($appId, 'enabled', 'yes'); - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( + $this->dispatcher->dispatchTyped(new AppEnableEvent($appId)); + $this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( ManagerEvent::EVENT_APP_ENABLE, $appId )); $this->clearAppsCache(); @@ -345,7 +353,7 @@ class AppManager implements IAppManager { * Enable an app only for specific groups * * @param string $appId - * @param \OCP\IGroup[] $groups + * @param IGroup[] $groups * @param bool $forceEnable * @throws \InvalidArgumentException if app can't be enabled for groups * @throws AppPathNotFoundException @@ -363,8 +371,9 @@ class AppManager implements IAppManager { $this->ignoreNextcloudRequirementForApp($appId); } + /** @var string[] $groupIds */ $groupIds = array_map(function ($group) { - /** @var \OCP\IGroup $group */ + /** @var IGroup $group */ return ($group instanceof IGroup) ? $group->getGID() : $group; @@ -372,7 +381,8 @@ class AppManager implements IAppManager { $this->installedAppsCache[$appId] = json_encode($groupIds); $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( + $this->dispatcher->dispatchTyped(new AppEnableEvent($appId, $groupIds)); + $this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups )); $this->clearAppsCache(); @@ -407,7 +417,8 @@ class AppManager implements IAppManager { \OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']); } - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( + $this->dispatcher->dispatchTyped(new AppDisableEvent($appId)); + $this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( ManagerEvent::EVENT_APP_DISABLE, $appId )); $this->clearAppsCache(); diff --git a/lib/private/Server.php b/lib/private/Server.php index f9fc585e74d..9a4ee0da198 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -928,6 +928,7 @@ class Server extends ServerContainer implements IServerContainer { $c->get(IGroupManager::class), $c->get(ICacheFactory::class), $c->get(SymfonyAdapter::class), + $c->get(IEventDispatcher::class), $c->get(LoggerInterface::class) ); }); diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 7f51d81d21b..a7887d2bed7 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -50,9 +50,12 @@ declare(strict_types=1); * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + +use OCP\App\Events\AppUpdateEvent; use OCP\AppFramework\QueryException; use OCP\App\ManagerEvent; use OCP\Authentication\IAlternativeLogin; +use OCP\EventDispatcher\IEventDispatcher; use OCP\ILogger; use OCP\Settings\IManager as ISettingsManager; use OC\AppFramework\Bootstrap\Coordinator; @@ -1042,6 +1045,7 @@ class OC_App { $version = \OC_App::getAppVersion($appId); \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version); + \OC::$server->get(IEventDispatcher::class)->dispatchTyped(new AppUpdateEvent($appId)); \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( ManagerEvent::EVENT_APP_UPDATE, $appId )); @@ -1061,7 +1065,7 @@ class OC_App { // load the app self::loadApp($appId); - $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class); + $dispatcher = \OC::$server->get(IEventDispatcher::class); // load the steps $r = new Repair([], $dispatcher, \OC::$server->get(LoggerInterface::class)); diff --git a/lib/public/App/Events/AppDisableEvent.php b/lib/public/App/Events/AppDisableEvent.php new file mode 100644 index 00000000000..5a50587446f --- /dev/null +++ b/lib/public/App/Events/AppDisableEvent.php @@ -0,0 +1,51 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022, Thomas Citharel <nextcloud@tcit.fr> + * + * @author Thomas Citharel <nextcloud@tcit.fr> + * + * @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\App\Events; + +use OCP\EventDispatcher\Event; + +/** + * @since 27.0.0 + */ +class AppDisableEvent extends Event { + private string $appId; + + /** + * @since 27.0.0 + */ + public function __construct(string $appId) { + parent::__construct(); + + $this->appId = $appId; + } + + /** + * @since 27.0.0 + */ + public function getAppId(): string { + return $this->appId; + } +} diff --git a/lib/public/App/Events/AppEnableEvent.php b/lib/public/App/Events/AppEnableEvent.php new file mode 100644 index 00000000000..1aff3630f86 --- /dev/null +++ b/lib/public/App/Events/AppEnableEvent.php @@ -0,0 +1,62 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022, Thomas Citharel <nextcloud@tcit.fr> + * + * @author Thomas Citharel <nextcloud@tcit.fr> + * + * @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\App\Events; + +use OCP\EventDispatcher\Event; + +/** + * @since 27.0.0 + */ +class AppEnableEvent extends Event { + private string $appId; + /** @var string[] */ + private array $groupIds; + + /** + * @param string[] $groupIds + * @since 27.0.0 + */ + public function __construct(string $appId, array $groupIds = []) { + parent::__construct(); + + $this->appId = $appId; + $this->groupIds = $groupIds; + } + + /** + * @since 27.0.0 + */ + public function getAppId(): string { + return $this->appId; + } + + /** + * @since 27.0.0 + */ + public function getGroupIds(): array { + return $this->groupIds; + } +} diff --git a/lib/public/App/Events/AppUpdateEvent.php b/lib/public/App/Events/AppUpdateEvent.php new file mode 100644 index 00000000000..92f1f8f9b16 --- /dev/null +++ b/lib/public/App/Events/AppUpdateEvent.php @@ -0,0 +1,51 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022, Thomas Citharel <nextcloud@tcit.fr> + * + * @author Thomas Citharel <nextcloud@tcit.fr> + * + * @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\App\Events; + +use OCP\EventDispatcher\Event; + +/** + * @since 27.0.0 + */ +class AppUpdateEvent extends Event { + private string $appId; + + /** + * @since 27.0.0 + */ + public function __construct(string $appId) { + parent::__construct(); + + $this->appId = $appId; + } + + /** + * @since 27.0.0 + */ + public function getAppId(): string { + return $this->appId; + } +} |