diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php
index ef6f79e4eb551..d79f14764dea8 100644
--- a/apps/updatenotification/lib/AppInfo/Application.php
+++ b/apps/updatenotification/lib/AppInfo/Application.php
@@ -1,4 +1,5 @@
*
diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php
index ba16f114f6140..57f89969db4c2 100644
--- a/apps/updatenotification/lib/Controller/AdminController.php
+++ b/apps/updatenotification/lib/Controller/AdminController.php
@@ -1,4 +1,5 @@
config->setAppValue('core', 'lastupdatedat', 0);
return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]);
@@ -85,7 +86,7 @@ public function setChannel($channel) {
/**
* @return DataResponse
*/
- public function createCredentials() {
+ public function createCredentials(): DataResponse {
// Create a new job and store the creation date
$this->jobList->add(ResetTokenBackgroundJob::class);
$this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());
diff --git a/apps/updatenotification/lib/Notification/BackgroundJob.php b/apps/updatenotification/lib/Notification/BackgroundJob.php
index 3c0cac60cded4..c010ccc89e5ab 100644
--- a/apps/updatenotification/lib/Notification/BackgroundJob.php
+++ b/apps/updatenotification/lib/Notification/BackgroundJob.php
@@ -1,4 +1,5 @@
getChannel(), ['daily', 'git'], true)) {
+ if (\in_array($this->getChannel(), ['daily', 'git'], true)) {
// "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi
return;
}
@@ -102,10 +103,10 @@ protected function checkCoreUpdate() {
$errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0);
$this->config->setAppValue('updatenotification', 'update_check_errors', $errors);
- if (in_array($errors, $this->connectionNotifications, true)) {
+ if (\in_array($errors, $this->connectionNotifications, true)) {
$this->sendErrorNotifications($errors);
}
- } else if (is_array($status)) {
+ } else if (\is_array($status)) {
$this->config->setAppValue('updatenotification', 'update_check_errors', 0);
$this->clearErrorNotifications();
@@ -178,26 +179,31 @@ protected function createNotifications($app, $version, $visibleVersion = '') {
if ($lastNotification === $version) {
// We already notified about this update
return;
- } else if ($lastNotification !== false) {
+ }
+
+ if ($lastNotification !== false) {
// Delete old updates
$this->deleteOutdatedNotifications($app, $lastNotification);
}
-
$notification = $this->notificationManager->createNotification();
- $notification->setApp('updatenotification')
- ->setDateTime(new \DateTime())
- ->setObject($app, $version);
-
- if ($visibleVersion !== '') {
- $notification->setSubject('update_available', ['version' => $visibleVersion]);
- } else {
- $notification->setSubject('update_available');
- }
+ try {
+ $notification->setApp('updatenotification')
+ ->setDateTime(new \DateTime())
+ ->setObject($app, $version);
- foreach ($this->getUsersToNotify() as $uid) {
- $notification->setUser($uid);
- $this->notificationManager->notify($notification);
+ if ($visibleVersion !== '') {
+ $notification->setSubject('update_available', ['version' => $visibleVersion]);
+ } else {
+ $notification->setSubject('update_available');
+ }
+
+ foreach ($this->getUsersToNotify() as $uid) {
+ $notification->setUser($uid);
+ $this->notificationManager->notify($notification);
+ }
+ } catch (\InvalidArgumentException $e) {
+ return;
}
$this->config->setAppValue('updatenotification', $app, $version);
@@ -206,12 +212,12 @@ protected function createNotifications($app, $version, $visibleVersion = '') {
/**
* @return string[]
*/
- protected function getUsersToNotify() {
+ protected function getUsersToNotify(): array {
if ($this->users !== null) {
return $this->users;
}
- $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
+ $notifyGroups = (array) json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
$this->users = [];
foreach ($notifyGroups as $group) {
$groupToNotify = $this->groupManager->get($group);
@@ -235,15 +241,19 @@ protected function getUsersToNotify() {
*/
protected function deleteOutdatedNotifications($app, $version) {
$notification = $this->notificationManager->createNotification();
- $notification->setApp('updatenotification')
- ->setObject($app, $version);
+ try {
+ $notification->setApp('updatenotification')
+ ->setObject($app, $version);
+ } catch (\InvalidArgumentException $e) {
+ return;
+ }
$this->notificationManager->markProcessed($notification);
}
/**
* @return VersionCheck
*/
- protected function createVersionCheck() {
+ protected function createVersionCheck(): VersionCheck {
return new VersionCheck(
$this->client,
$this->config
@@ -253,7 +263,7 @@ protected function createVersionCheck() {
/**
* @return string
*/
- protected function getChannel() {
+ protected function getChannel(): string {
return \OC_Util::getChannel();
}
diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php
index d18a26637020b..c88937f0dff54 100644
--- a/apps/updatenotification/lib/Notification/Notifier.php
+++ b/apps/updatenotification/lib/Notification/Notifier.php
@@ -1,4 +1,5 @@
getApp() !== 'updatenotification') {
- throw new \InvalidArgumentException();
+ throw new \InvalidArgumentException('Unknown app id');
}
$l = $this->l10NFactory->get('updatenotification', $languageCode);
@@ -94,7 +96,7 @@ public function prepare(INotification $notification, $languageCode) {
$errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0);
if ($errors === 0) {
$this->notificationManager->markProcessed($notification);
- throw new \InvalidArgumentException();
+ throw new \InvalidArgumentException('Update checked worked again');
}
$notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors]))
@@ -145,14 +147,14 @@ public function prepare(INotification $notification, $languageCode) {
protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) {
if (version_compare($notification->getObjectId(), $installedVersion, '<=')) {
$this->notificationManager->markProcessed($notification);
- throw new \InvalidArgumentException();
+ throw new \InvalidArgumentException('Update already installed');
}
}
/**
* @return bool
*/
- protected function isAdmin() {
+ protected function isAdmin(): bool {
$user = $this->userSession->getUser();
if ($user instanceof IUser) {
@@ -162,11 +164,11 @@ protected function isAdmin() {
return false;
}
- protected function getCoreVersions() {
- return implode('.', \OCP\Util::getVersion());
+ protected function getCoreVersions(): string {
+ return implode('.', Util::getVersion());
}
- protected function getAppVersions() {
+ protected function getAppVersions(): array {
return \OC_App::getAppVersions();
}
diff --git a/apps/updatenotification/lib/ResetTokenBackgroundJob.php b/apps/updatenotification/lib/ResetTokenBackgroundJob.php
index 5dd7c4f35f1e1..87cca466ec7e2 100644
--- a/apps/updatenotification/lib/ResetTokenBackgroundJob.php
+++ b/apps/updatenotification/lib/ResetTokenBackgroundJob.php
@@ -1,4 +1,5 @@
config->getAppValue('core', 'lastupdatedat');
$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
@@ -99,7 +100,7 @@ public function getForm() {
/**
* @return string the section ID, e.g. 'sharing'
*/
- public function getSection() {
+ public function getSection(): string {
return 'server';
}
@@ -110,7 +111,7 @@ public function getSection() {
*
* E.g.: 70
*/
- public function getPriority() {
+ public function getPriority(): int {
return 1;
}
}
diff --git a/apps/updatenotification/lib/UpdateChecker.php b/apps/updatenotification/lib/UpdateChecker.php
index cabdfe8b9ff62..5f2712423d215 100644
--- a/apps/updatenotification/lib/UpdateChecker.php
+++ b/apps/updatenotification/lib/UpdateChecker.php
@@ -1,4 +1,5 @@
updater->check();
$result = [];
- if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
+ if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
$result['updateAvailable'] = true;
$result['updateVersion'] = $data['versionstring'];
$result['updaterEnabled'] = $data['autoupdater'] === '1';
- if(substr($data['web'], 0, 8) === 'https://') {
+ if (strpos($data['web'], 'https://') === 0) {
$result['updateLink'] = $data['web'];
}
- if(substr($data['url'], 0, 8) === 'https://') {
+ if (strpos($data['url'], 'https://') === 0) {
$result['downloadLink'] = $data['url'];
}
@@ -68,7 +69,7 @@ public function populateJavaScriptVariables(array $data) {
$data['array']['oc_updateState'] = json_encode([
'updateAvailable' => true,
'updateVersion' => $this->getUpdateState()['updateVersion'],
- 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '',
+ 'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
]);
}
}
diff --git a/apps/updatenotification/templates/admin.php b/apps/updatenotification/templates/admin.php
index e09d19848e753..19bbec769d094 100644
--- a/apps/updatenotification/templates/admin.php
+++ b/apps/updatenotification/templates/admin.php
@@ -1,4 +1,5 @@
- t("A non-default update server is in use to be checked for updates:")); ?>
+ t('A non-default update server is in use to be checked for updates:')); ?>
@@ -65,10 +66,10 @@
t('Notify members of the following groups about available updates:')); ?>
-
+
t('Only notification for app updates are available.')); ?>
- t('The selected update channel makes dedicated notifications for the server obsolete.')); ?>
- t('The selected update channel does not support updates of the server.')); ?>
+ t('The selected update channel makes dedicated notifications for the server obsolete.')); } ?>
+ t('The selected update channel does not support updates of the server.')); } ?>