4040
4141use OC \AppConfig ;
4242use OCP \App \AppPathNotFoundException ;
43+ use OCP \App \Events \AppDisableEvent ;
44+ use OCP \App \Events \AppEnableEvent ;
4345use OCP \App \IAppManager ;
4446use OCP \App \ManagerEvent ;
47+ use OCP \EventDispatcher \IEventDispatcher ;
4548use OCP \ICacheFactory ;
4649use OCP \IConfig ;
4750use 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 ();
0 commit comments