diff options
Diffstat (limited to 'apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php')
-rw-r--r-- | apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php index f55bbe01dba..8879bb0c223 100644 --- a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php +++ b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php @@ -10,6 +10,7 @@ namespace OCA\UpdateNotification\BackgroundJob; use OC\Installer; use OC\Updater\VersionCheck; +use OCA\UpdateNotification\AppInfo\Application; use OCP\App\IAppManager; use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Utility\ITimeFactory; @@ -21,10 +22,15 @@ use OCP\Notification\IManager; use OCP\ServerVersion; class UpdateAvailableNotifications extends TimedJob { - protected $connectionNotifications = [3, 7, 14, 30]; - /** @var string[] */ - protected $users; + /** + * Numbers of failed updater connection to report error as notification. + * @var list<int> + */ + protected const CONNECTION_NOTIFICATIONS = [3, 7, 14, 30]; + + /** @var ?string[] */ + protected $users = null; public function __construct( ITimeFactory $timeFactory, @@ -64,9 +70,14 @@ class UpdateAvailableNotifications extends TimedJob { } /** - * Check for ownCloud update + * Check for Nextcloud server update */ - protected function checkCoreUpdate() { + protected function checkCoreUpdate(): void { + if (!$this->config->getSystemValueBool('updatechecker', true)) { + // update checker is disabled so no core update check! + return; + } + if (\in_array($this->serverVersion->getChannel(), ['daily', 'git'], true)) { // "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi return; @@ -77,7 +88,7 @@ class UpdateAvailableNotifications extends TimedJob { $errors = 1 + $this->appConfig->getAppValueInt('update_check_errors', 0); $this->appConfig->setAppValueInt('update_check_errors', $errors); - if (\in_array($errors, $this->connectionNotifications, true)) { + if (\in_array($errors, self::CONNECTION_NOTIFICATIONS, true)) { $this->sendErrorNotifications($errors); } } elseif (\is_array($status)) { @@ -94,14 +105,14 @@ class UpdateAvailableNotifications extends TimedJob { * Send a message to the admin when the update server could not be reached * @param int $numDays */ - protected function sendErrorNotifications($numDays) { + protected function sendErrorNotifications($numDays): void { $this->clearErrorNotifications(); $notification = $this->notificationManager->createNotification(); try { - $notification->setApp('updatenotification') + $notification->setApp(Application::APP_NAME) ->setDateTime(new \DateTime()) - ->setObject('updatenotification', 'error') + ->setObject(Application::APP_NAME, 'error') ->setSubject('connection_error', ['days' => $numDays]); foreach ($this->getUsersToNotify() as $uid) { @@ -116,12 +127,12 @@ class UpdateAvailableNotifications extends TimedJob { /** * Remove error notifications again */ - protected function clearErrorNotifications() { + protected function clearErrorNotifications(): void { $notification = $this->notificationManager->createNotification(); try { - $notification->setApp('updatenotification') + $notification->setApp(Application::APP_NAME) ->setSubject('connection_error') - ->setObject('updatenotification', 'error'); + ->setObject(Application::APP_NAME, 'error'); } catch (\InvalidArgumentException $e) { return; } @@ -131,7 +142,7 @@ class UpdateAvailableNotifications extends TimedJob { /** * Check all installed apps for updates */ - protected function checkAppUpdates() { + protected function checkAppUpdates(): void { $apps = $this->appManager->getEnabledApps(); foreach ($apps as $app) { $update = $this->isUpdateAvailable($app); @@ -148,7 +159,7 @@ class UpdateAvailableNotifications extends TimedJob { * @param string $version * @param string $visibleVersion */ - protected function createNotifications($app, $version, $visibleVersion = '') { + protected function createNotifications($app, $version, $visibleVersion = ''): void { $lastNotification = $this->appConfig->getAppValueString($app, ''); if ($lastNotification === $version) { // We already notified about this update @@ -162,7 +173,7 @@ class UpdateAvailableNotifications extends TimedJob { $notification = $this->notificationManager->createNotification(); try { - $notification->setApp('updatenotification') + $notification->setApp(Application::APP_NAME) ->setDateTime(new \DateTime()) ->setObject($app, $version); @@ -212,12 +223,12 @@ class UpdateAvailableNotifications extends TimedJob { * @param string $app * @param string $version */ - protected function deleteOutdatedNotifications($app, $version) { + protected function deleteOutdatedNotifications($app, $version): void { $notification = $this->notificationManager->createNotification(); try { - $notification->setApp('updatenotification') + $notification->setApp(Application::APP_NAME) ->setObject($app, $version); - } catch (\InvalidArgumentException $e) { + } catch (\InvalidArgumentException) { return; } $this->notificationManager->markProcessed($notification); |