Skip to content

Commit c64dcbb

Browse files
committed
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>
1 parent ade49e0 commit c64dcbb

File tree

10 files changed

+221
-17
lines changed

10 files changed

+221
-17
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => $baseDir . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php',
8383
'OCP\\AppFramework\\Utility\\ITimeFactory' => $baseDir . '/lib/public/AppFramework/Utility/ITimeFactory.php',
8484
'OCP\\App\\AppPathNotFoundException' => $baseDir . '/lib/public/App/AppPathNotFoundException.php',
85+
'OCP\\App\\Events\\AppDisableEvent' => $baseDir . '/lib/public/App/Events/AppDisableEvent.php',
86+
'OCP\\App\\Events\\AppEnableEvent' => $baseDir . '/lib/public/App/Events/AppEnableEvent.php',
87+
'OCP\\App\\Events\\AppUpdateEvent' => $baseDir . '/lib/public/App/Events/AppUpdateEvent.php',
8588
'OCP\\App\\IAppManager' => $baseDir . '/lib/public/App/IAppManager.php',
8689
'OCP\\App\\ManagerEvent' => $baseDir . '/lib/public/App/ManagerEvent.php',
8790
'OCP\\Authentication\\Events\\AnyLoginFailedEvent' => $baseDir . '/lib/public/Authentication/Events/AnyLoginFailedEvent.php',

lib/composer/composer/autoload_static.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
115115
'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php',
116116
'OCP\\AppFramework\\Utility\\ITimeFactory' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/ITimeFactory.php',
117117
'OCP\\App\\AppPathNotFoundException' => __DIR__ . '/../../..' . '/lib/public/App/AppPathNotFoundException.php',
118+
'OCP\\App\\Events\\AppDisableEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppDisableEvent.php',
119+
'OCP\\App\\Events\\AppEnableEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppEnableEvent.php',
120+
'OCP\\App\\Events\\AppUpdateEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppUpdateEvent.php',
118121
'OCP\\App\\IAppManager' => __DIR__ . '/../../..' . '/lib/public/App/IAppManager.php',
119122
'OCP\\App\\ManagerEvent' => __DIR__ . '/../../..' . '/lib/public/App/ManagerEvent.php',
120123
'OCP\\Authentication\\Events\\AnyLoginFailedEvent' => __DIR__ . '/../../..' . '/lib/public/Authentication/Events/AnyLoginFailedEvent.php',

lib/private/App/AppManager.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040

4141
use OC\AppConfig;
4242
use OCP\App\AppPathNotFoundException;
43+
use OCP\App\Events\AppDisableEvent;
44+
use OCP\App\Events\AppEnableEvent;
4345
use OCP\App\IAppManager;
4446
use OCP\App\ManagerEvent;
47+
use OCP\EventDispatcher\IEventDispatcher;
4548
use OCP\ICacheFactory;
4649
use OCP\IConfig;
4750
use OCP\IGroup;
@@ -80,7 +83,9 @@ class AppManager implements IAppManager {
8083
private $memCacheFactory;
8184

8285
/** @var EventDispatcherInterface */
83-
private $dispatcher;
86+
private $legacyDispatcher;
87+
88+
private IEventDispatcher $dispatcher;
8489

8590
/** @var LoggerInterface */
8691
private $logger;
@@ -108,13 +113,15 @@ public function __construct(IUserSession $userSession,
108113
AppConfig $appConfig,
109114
IGroupManager $groupManager,
110115
ICacheFactory $memCacheFactory,
111-
EventDispatcherInterface $dispatcher,
116+
EventDispatcherInterface $legacyDispatcher,
117+
IEventDispatcher $dispatcher,
112118
LoggerInterface $logger) {
113119
$this->userSession = $userSession;
114120
$this->config = $config;
115121
$this->appConfig = $appConfig;
116122
$this->groupManager = $groupManager;
117123
$this->memCacheFactory = $memCacheFactory;
124+
$this->legacyDispatcher = $legacyDispatcher;
118125
$this->dispatcher = $dispatcher;
119126
$this->logger = $logger;
120127
}
@@ -163,7 +170,7 @@ public function getEnabledAppsForUser(IUser $user) {
163170
}
164171

165172
/**
166-
* @param \OCP\IGroup $group
173+
* @param IGroup $group
167174
* @return array
168175
*/
169176
public function getEnabledAppsForGroup(IGroup $group): array {
@@ -287,7 +294,7 @@ private function checkAppForGroups(string $enabled, IGroup $group): bool {
287294
* Notice: This actually checks if the app is enabled and not only if it is installed.
288295
*
289296
* @param string $appId
290-
* @param \OCP\IGroup[]|String[] $groups
297+
* @param IGroup[]|String[] $groups
291298
* @return bool
292299
*/
293300
public function isInstalled($appId) {
@@ -320,7 +327,8 @@ public function enableApp(string $appId, bool $forceEnable = false): void {
320327

321328
$this->installedAppsCache[$appId] = 'yes';
322329
$this->appConfig->setValue($appId, 'enabled', 'yes');
323-
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
330+
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId));
331+
$this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
324332
ManagerEvent::EVENT_APP_ENABLE, $appId
325333
));
326334
$this->clearAppsCache();
@@ -345,7 +353,7 @@ public function hasProtectedAppType($types) {
345353
* Enable an app only for specific groups
346354
*
347355
* @param string $appId
348-
* @param \OCP\IGroup[] $groups
356+
* @param IGroup[] $groups
349357
* @param bool $forceEnable
350358
* @throws \InvalidArgumentException if app can't be enabled for groups
351359
* @throws AppPathNotFoundException
@@ -363,16 +371,18 @@ public function enableAppForGroups(string $appId, array $groups, bool $forceEnab
363371
$this->ignoreNextcloudRequirementForApp($appId);
364372
}
365373

374+
/** @var string[] $groupIds */
366375
$groupIds = array_map(function ($group) {
367-
/** @var \OCP\IGroup $group */
376+
/** @var IGroup $group */
368377
return ($group instanceof IGroup)
369378
? $group->getGID()
370379
: $group;
371380
}, $groups);
372381

373382
$this->installedAppsCache[$appId] = json_encode($groupIds);
374383
$this->appConfig->setValue($appId, 'enabled', json_encode($groupIds));
375-
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
384+
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId, $groupIds));
385+
$this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
376386
ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups
377387
));
378388
$this->clearAppsCache();
@@ -407,7 +417,8 @@ public function disableApp($appId, $automaticDisabled = false) {
407417
\OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']);
408418
}
409419

410-
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent(
420+
$this->dispatcher->dispatchTyped(new AppDisableEvent($appId));
421+
$this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent(
411422
ManagerEvent::EVENT_APP_DISABLE, $appId
412423
));
413424
$this->clearAppsCache();

lib/private/Server.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ public function __construct($webRoot, \OC\Config $config) {
928928
$c->get(IGroupManager::class),
929929
$c->get(ICacheFactory::class),
930930
$c->get(SymfonyAdapter::class),
931+
$c->get(IEventDispatcher::class),
931932
$c->get(LoggerInterface::class)
932933
);
933934
});

lib/private/legacy/OC_App.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@
5050
* along with this program. If not, see <http://www.gnu.org/licenses/>
5151
*
5252
*/
53+
54+
use OCP\App\Events\AppUpdateEvent;
5355
use OCP\AppFramework\QueryException;
5456
use OCP\App\ManagerEvent;
5557
use OCP\Authentication\IAlternativeLogin;
58+
use OCP\EventDispatcher\IEventDispatcher;
5659
use OCP\ILogger;
5760
use OCP\Settings\IManager as ISettingsManager;
5861
use OC\AppFramework\Bootstrap\Coordinator;
@@ -1042,6 +1045,7 @@ public static function updateApp(string $appId): bool {
10421045
$version = \OC_App::getAppVersion($appId);
10431046
\OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version);
10441047

1048+
\OC::$server->get(IEventDispatcher::class)->dispatchTyped(new AppUpdateEvent($appId));
10451049
\OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
10461050
ManagerEvent::EVENT_APP_UPDATE, $appId
10471051
));
@@ -1061,7 +1065,7 @@ public static function executeRepairSteps(string $appId, array $steps) {
10611065
// load the app
10621066
self::loadApp($appId);
10631067

1064-
$dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
1068+
$dispatcher = \OC::$server->get(IEventDispatcher::class);
10651069

10661070
// load the steps
10671071
$r = new Repair([], $dispatcher, \OC::$server->get(LoggerInterface::class));
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2022, Thomas Citharel <nextcloud@tcit.fr>
7+
*
8+
* @author Thomas Citharel <nextcloud@tcit.fr>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCP\App\Events;
27+
28+
use OCP\EventDispatcher\Event;
29+
30+
/**
31+
* @since 26.0.0
32+
*/
33+
class AppDisableEvent extends Event {
34+
private string $appId;
35+
36+
/**
37+
* @since 26.0.0
38+
*/
39+
public function __construct(string $appId) {
40+
parent::__construct();
41+
42+
$this->appId = $appId;
43+
}
44+
45+
/**
46+
* @since 26.0.0
47+
*/
48+
public function getAppId(): string {
49+
return $this->appId;
50+
}
51+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2022, Thomas Citharel <nextcloud@tcit.fr>
7+
*
8+
* @author Thomas Citharel <nextcloud@tcit.fr>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCP\App\Events;
27+
28+
use OCP\EventDispatcher\Event;
29+
30+
/**
31+
* @since 26.0.0
32+
*/
33+
class AppEnableEvent extends Event {
34+
private string $appId;
35+
/** @var string[] */
36+
private array $groupIds;
37+
38+
/**
39+
* @param string[] $groupIds
40+
* @since 26.0.0
41+
*/
42+
public function __construct(string $appId, array $groupIds = []) {
43+
parent::__construct();
44+
45+
$this->appId = $appId;
46+
$this->groupIds = $groupIds;
47+
}
48+
49+
/**
50+
* @since 26.0.0
51+
*/
52+
public function getAppId(): string {
53+
return $this->appId;
54+
}
55+
56+
/**
57+
* @since 26.0.0
58+
*/
59+
public function getGroupIds(): array {
60+
return $this->groupIds;
61+
}
62+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2022, Thomas Citharel <nextcloud@tcit.fr>
7+
*
8+
* @author Thomas Citharel <nextcloud@tcit.fr>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCP\App\Events;
27+
28+
use OCP\EventDispatcher\Event;
29+
30+
/**
31+
* @since 26.0.0
32+
*/
33+
class AppUpdateEvent extends Event {
34+
private string $appId;
35+
36+
/**
37+
* @since 26.0.0
38+
*/
39+
public function __construct(string $appId) {
40+
parent::__construct();
41+
42+
$this->appId = $appId;
43+
}
44+
45+
/**
46+
* @since 26.0.0
47+
*/
48+
public function getAppId(): string {
49+
return $this->appId;
50+
}
51+
}

0 commit comments

Comments
 (0)