diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-07-16 17:08:03 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-07-21 20:43:18 +0200 |
commit | 91e7f12088cb87ffef5660429ece404364167978 (patch) | |
tree | baf44ebc7b240bd49eb0f6bf615cbb1ed99d13db /apps/updatenotification/lib/AppInfo/Application.php | |
parent | e029055e766298c5852eedabf06ff42b06a50198 (diff) | |
download | nextcloud-server-91e7f12088cb87ffef5660429ece404364167978.tar.gz nextcloud-server-91e7f12088cb87ffef5660429ece404364167978.zip |
Adjust apps' code to use the ContainerInterface
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/updatenotification/lib/AppInfo/Application.php')
-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..c369c957442 100644 --- a/apps/updatenotification/lib/AppInfo/Application.php +++ b/apps/updatenotification/lib/AppInfo/Application.php @@ -30,13 +30,20 @@ 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\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; +use Psr\Container\ContainerInterface; class Application extends App implements IBootstrap { public function __construct() { @@ -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, + ContainerInterface $container, + 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 = $container->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'); + } } - } + }); } } |