2016-02-09 13:58:29 -05:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-01-17 07:42:02 -05:00
|
|
|
declare(strict_types=1);
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2016-02-09 13:58:29 -05:00
|
|
|
/**
|
2024-05-30 14:13:41 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-02-09 13:58:29 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\UpdateNotification\AppInfo;
|
|
|
|
|
|
2024-03-02 15:33:02 -05:00
|
|
|
use OCA\UpdateNotification\Listener\AppUpdateEventListener;
|
|
|
|
|
use OCA\UpdateNotification\Listener\BeforeTemplateRenderedEventListener;
|
|
|
|
|
use OCA\UpdateNotification\Notification\AppUpdateNotifier;
|
2018-01-11 05:58:43 -05:00
|
|
|
use OCA\UpdateNotification\Notification\Notifier;
|
|
|
|
|
use OCA\UpdateNotification\UpdateChecker;
|
2024-03-02 15:33:02 -05:00
|
|
|
use OCP\App\Events\AppUpdateEvent;
|
2020-07-16 11:08:03 -04:00
|
|
|
use OCP\App\IAppManager;
|
2016-02-09 13:58:29 -05:00
|
|
|
use OCP\AppFramework\App;
|
2020-07-13 11:09:23 -04:00
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
2024-03-02 15:33:02 -05:00
|
|
|
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
|
2020-07-16 11:08:03 -04:00
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\IGroupManager;
|
2018-01-11 05:58:43 -05:00
|
|
|
use OCP\IUser;
|
2020-07-16 11:08:03 -04:00
|
|
|
use OCP\IUserSession;
|
2018-01-11 05:58:43 -05:00
|
|
|
use OCP\Util;
|
2024-03-02 15:04:56 -05:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
|
use Psr\Container\ContainerInterface;
|
2023-09-19 10:06:40 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2016-02-09 13:58:29 -05:00
|
|
|
|
2020-07-13 11:09:23 -04:00
|
|
|
class Application extends App implements IBootstrap {
|
2024-03-02 15:33:02 -05:00
|
|
|
public const APP_NAME = 'updatenotification';
|
|
|
|
|
|
2018-01-11 05:38:26 -05:00
|
|
|
public function __construct() {
|
2024-03-02 15:33:02 -05:00
|
|
|
parent::__construct(self::APP_NAME, []);
|
2016-02-09 13:58:29 -05:00
|
|
|
}
|
2018-01-11 05:58:43 -05:00
|
|
|
|
2020-07-13 11:09:23 -04:00
|
|
|
public function register(IRegistrationContext $context): void {
|
2021-04-16 06:39:08 -04:00
|
|
|
$context->registerNotifierService(Notifier::class);
|
2024-03-02 15:33:02 -05:00
|
|
|
$context->registerNotifierService(AppUpdateNotifier::class);
|
|
|
|
|
|
|
|
|
|
$context->registerEventListener(AppUpdateEvent::class, AppUpdateEventListener::class);
|
|
|
|
|
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedEventListener::class);
|
2020-07-13 11:09:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function boot(IBootContext $context): void {
|
2020-07-16 11:08:03 -04:00
|
|
|
$context->injectFn(function (IConfig $config,
|
2023-09-19 10:06:40 -04:00
|
|
|
IUserSession $userSession,
|
|
|
|
|
IAppManager $appManager,
|
|
|
|
|
IGroupManager $groupManager,
|
2024-03-02 15:04:56 -05:00
|
|
|
ContainerInterface $container,
|
2024-09-24 11:23:48 -04:00
|
|
|
LoggerInterface $logger,
|
|
|
|
|
): void {
|
2020-07-16 11:08:03 -04:00
|
|
|
if ($config->getSystemValue('updatechecker', true) !== true) {
|
|
|
|
|
// Updater check is disabled
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-03-19 03:52:52 -04:00
|
|
|
|
2020-07-16 11:08:03 -04:00
|
|
|
$user = $userSession->getUser();
|
|
|
|
|
if (!$user instanceof IUser) {
|
|
|
|
|
// Nothing to do for guests
|
2018-01-11 05:58:43 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-16 11:08:03 -04:00
|
|
|
if (!$appManager->isEnabledForUser('notifications') &&
|
|
|
|
|
$groupManager->isAdmin($user->getUID())) {
|
|
|
|
|
try {
|
2024-03-02 15:04:56 -05:00
|
|
|
$updateChecker = $container->get(UpdateChecker::class);
|
|
|
|
|
} catch (ContainerExceptionInterface $e) {
|
2023-09-19 10:06:40 -04:00
|
|
|
$logger->error($e->getMessage(), ['exception' => $e]);
|
2020-07-16 11:08:03 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($updateChecker->getUpdateState() !== []) {
|
2024-09-24 11:23:48 -04:00
|
|
|
Util::addScript('updatenotification', 'update-notification-legacy');
|
|
|
|
|
$updateChecker->setInitialState();
|
2020-07-16 11:08:03 -04:00
|
|
|
}
|
2018-01-11 05:58:43 -05:00
|
|
|
}
|
2020-07-16 11:08:03 -04:00
|
|
|
});
|
2018-01-11 05:58:43 -05:00
|
|
|
}
|
2016-02-09 13:58:29 -05:00
|
|
|
}
|