Skip to content

Commit bf68763

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 11d7cd0 commit bf68763

9 files changed

Lines changed: 213 additions & 12 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => $baseDir . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php',
8282
'OCP\\AppFramework\\Utility\\ITimeFactory' => $baseDir . '/lib/public/AppFramework/Utility/ITimeFactory.php',
8383
'OCP\\App\\AppPathNotFoundException' => $baseDir . '/lib/public/App/AppPathNotFoundException.php',
84+
'OCP\\App\\Events\\AppDisableEvent' => $baseDir . '/lib/public/App/Events/AppDisableEvent.php',
85+
'OCP\\App\\Events\\AppEnableEvent' => $baseDir . '/lib/public/App/Events/AppEnableEvent.php',
86+
'OCP\\App\\Events\\AppUpdateEvent' => $baseDir . '/lib/public/App/Events/AppUpdateEvent.php',
8487
'OCP\\App\\IAppManager' => $baseDir . '/lib/public/App/IAppManager.php',
8588
'OCP\\App\\ManagerEvent' => $baseDir . '/lib/public/App/ManagerEvent.php',
8689
'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
@@ -114,6 +114,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
114114
'OCP\\AppFramework\\Utility\\IControllerMethodReflector' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/IControllerMethodReflector.php',
115115
'OCP\\AppFramework\\Utility\\ITimeFactory' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Utility/ITimeFactory.php',
116116
'OCP\\App\\AppPathNotFoundException' => __DIR__ . '/../../..' . '/lib/public/App/AppPathNotFoundException.php',
117+
'OCP\\App\\Events\\AppDisableEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppDisableEvent.php',
118+
'OCP\\App\\Events\\AppEnableEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppEnableEvent.php',
119+
'OCP\\App\\Events\\AppUpdateEvent' => __DIR__ . '/../../..' . '/lib/public/App/Events/AppUpdateEvent.php',
117120
'OCP\\App\\IAppManager' => __DIR__ . '/../../..' . '/lib/public/App/IAppManager.php',
118121
'OCP\\App\\ManagerEvent' => __DIR__ . '/../../..' . '/lib/public/App/ManagerEvent.php',
119122
'OCP\\Authentication\\Events\\AnyLoginFailedEvent' => __DIR__ . '/../../..' . '/lib/public/Authentication/Events/AnyLoginFailedEvent.php',

lib/private/App/AppManager.php

Lines changed: 15 additions & 5 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;
@@ -81,7 +84,9 @@ class AppManager implements IAppManager {
8184
private $memCacheFactory;
8285

8386
/** @var EventDispatcherInterface */
84-
private $dispatcher;
87+
private $legacyDispatcher;
88+
89+
private IEventDispatcher $dispatcher;
8590

8691
/** @var LoggerInterface */
8792
private $logger;
@@ -109,13 +114,15 @@ public function __construct(IUserSession $userSession,
109114
AppConfig $appConfig,
110115
IGroupManager $groupManager,
111116
ICacheFactory $memCacheFactory,
112-
EventDispatcherInterface $dispatcher,
117+
EventDispatcherInterface $legacyDispatcher,
118+
IEventDispatcher $dispatcher,
113119
LoggerInterface $logger) {
114120
$this->userSession = $userSession;
115121
$this->config = $config;
116122
$this->appConfig = $appConfig;
117123
$this->groupManager = $groupManager;
118124
$this->memCacheFactory = $memCacheFactory;
125+
$this->legacyDispatcher = $legacyDispatcher;
119126
$this->dispatcher = $dispatcher;
120127
$this->logger = $logger;
121128
}
@@ -321,7 +328,8 @@ public function enableApp(string $appId, bool $forceEnable = false): void {
321328

322329
$this->installedAppsCache[$appId] = 'yes';
323330
$this->appConfig->setValue($appId, 'enabled', 'yes');
324-
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
331+
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId));
332+
$this->legacyDispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
325333
ManagerEvent::EVENT_APP_ENABLE, $appId
326334
));
327335
$this->clearAppsCache();
@@ -373,7 +381,8 @@ public function enableAppForGroups(string $appId, array $groups, bool $forceEnab
373381

374382
$this->installedAppsCache[$appId] = json_encode($groupIds);
375383
$this->appConfig->setValue($appId, 'enabled', json_encode($groupIds));
376-
$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(
377386
ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups
378387
));
379388
$this->clearAppsCache();
@@ -408,7 +417,8 @@ public function disableApp($appId, $automaticDisabled = false) {
408417
\OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']);
409418
}
410419

411-
$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(
412422
ManagerEvent::EVENT_APP_DISABLE, $appId
413423
));
414424
$this->clearAppsCache();

lib/private/Server.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ public function __construct($webRoot, \OC\Config $config) {
926926
$c->get(IGroupManager::class),
927927
$c->get(ICacheFactory::class),
928928
$c->get(SymfonyAdapter::class),
929+
$c->get(IEventDispatcher::class),
929930
$c->get(LoggerInterface::class)
930931
);
931932
});

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;
@@ -1029,6 +1032,7 @@ public static function updateApp(string $appId): bool {
10291032
$version = \OC_App::getAppVersion($appId);
10301033
\OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version);
10311034

1035+
\OC::$server->get(IEventDispatcher::class)->dispatchTyped(new AppUpdateEvent($appId));
10321036
\OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
10331037
ManagerEvent::EVENT_APP_UPDATE, $appId
10341038
));
@@ -1048,7 +1052,7 @@ public static function executeRepairSteps(string $appId, array $steps) {
10481052
// load the app
10491053
self::loadApp($appId);
10501054

1051-
$dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
1055+
$dispatcher = \OC::$server->get(IEventDispatcher::class);
10521056

10531057
// load the steps
10541058
$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)