diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-07-22 21:38:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-22 21:38:50 +0300 |
commit | 346f647962e00b1f5e5f19a8526c88a09ebca59e (patch) | |
tree | 64f324cb5ff04f29247bf00f32e84bc7c8f4ed36 /apps/updatenotification | |
parent | c842678f0a1fb65981a03302895192ddc58479c9 (diff) | |
parent | 7870ca06637453f4e72dbd67edbfb3603d813196 (diff) |
Merge pull request #21870 from nextcloud/fix/bootstrap-context-container-interfaces
Make the bootstrap context return ContainerInterface instances
Diffstat (limited to 'apps/updatenotification')
-rw-r--r-- | apps/updatenotification/lib/AppInfo/Application.php | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php index 12d5cd9e626..48f89de3c37 100644 --- a/apps/updatenotification/lib/AppInfo/Application.php +++ b/apps/updatenotification/lib/AppInfo/Application.php @@ -30,12 +30,19 @@ namespace OCA\UpdateNotification\AppInfo; use OCA\UpdateNotification\Notification\Notifier; use OCA\UpdateNotification\UpdateChecker; +use OCP\App\IAppManager; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\AppFramework\IAppContainer; use OCP\AppFramework\QueryException; +use OCP\IConfig; +use OCP\IGroupManager; +use OCP\ILogger; use OCP\IUser; +use OCP\IUserSession; +use OCP\Notification\IManager as INotificationManager; use OCP\Util; class Application extends App implements IBootstrap { @@ -47,36 +54,41 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - $server = $context->getServerContainer(); - - if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) { - // Updater check is disabled - return; - } - - // Always register the notifier, so background jobs (without a user) can send push notifications - $notificationsManager = $server->getNotificationManager(); - $notificationsManager->registerNotifierService(Notifier::class); + $context->injectFn(function (IConfig $config, + INotificationManager $notificationsManager, + IUserSession $userSession, + IAppManager $appManager, + IGroupManager $groupManager, + IAppContainer $appContainer, + ILogger $logger) { + if ($config->getSystemValue('updatechecker', true) !== true) { + // Updater check is disabled + return; + } - $user = $server->getUserSession()->getUser(); - if (!$user instanceof IUser) { - // Nothing to do for guests - return; - } + // Always register the notifier, so background jobs (without a user) can send push notifications + $notificationsManager->registerNotifierService(Notifier::class); - if (!$server->getAppManager()->isEnabledForUser('notifications') && - $server->getGroupManager()->isAdmin($user->getUID())) { - try { - $updateChecker = $server->query(UpdateChecker::class); - } catch (QueryException $e) { - $server->getLogger()->logException($e); + $user = $userSession->getUser(); + if (!$user instanceof IUser) { + // Nothing to do for guests return; } - if ($updateChecker->getUpdateState() !== []) { - Util::addScript('updatenotification', 'legacy-notification'); - \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); + if (!$appManager->isEnabledForUser('notifications') && + $groupManager->isAdmin($user->getUID())) { + try { + $updateChecker = $appContainer->get(UpdateChecker::class); + } catch (QueryException $e) { + $logger->logException($e); + return; + } + + if ($updateChecker->getUpdateState() !== []) { + Util::addScript('updatenotification', 'legacy-notification'); + \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); + } } - } + }); } } |