Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions apps/updatenotification/lib/Notification/BackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ protected function checkCoreUpdate() {

$status = $updater->check();
if (isset($status['version'])) {
$url = $this->urlGenerator->linkToRouteAbsolute('settings_admin') . '#updater';
$this->createNotifications('core', $status['version'], $url);
$url = $this->urlGenerator->linkToRouteAbsolute('settings.AdminSettings.index') . '#updater';
$this->createNotifications('core', $status['version'], $url, $status['versionstring']);
}
}

Expand All @@ -123,8 +123,9 @@ protected function checkAppUpdates() {
* @param string $app
* @param string $version
* @param string $url
* @param string $visibleVersion
*/
protected function createNotifications($app, $version, $url) {
protected function createNotifications($app, $version, $url, $visibleVersion = '') {
$lastNotification = $this->config->getAppValue('updatenotification', $app, false);
if ($lastNotification === $version) {
// We already notified about this update
Expand All @@ -139,9 +140,14 @@ protected function createNotifications($app, $version, $url) {
$notification->setApp('updatenotification')
->setDateTime(new \DateTime())
->setObject($app, $version)
->setSubject('update_available')
->setLink($url);

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);
Expand Down
8 changes: 5 additions & 3 deletions apps/updatenotification/lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@ public function prepare(INotification $notification, $languageCode) {

$l = $this->l10NFactory->get('updatenotification', $languageCode);
if ($notification->getObjectType() === 'core') {
$appName = $l->t('Nextcloud core');

$this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions());

$parameters = $notification->getSubjectParameters();
$notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']]));
} else {
$appInfo = $this->getAppInfo($notification->getObjectType());
$appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name'];

if (isset($this->appVersions[$notification->getObjectType()])) {
$this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]);
}

$notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()]));
}

$notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()]));
return $notification;
}

Expand Down
26 changes: 15 additions & 11 deletions apps/updatenotification/tests/Notification/BackgroundJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,23 @@ public function testRun() {

public function dataCheckCoreUpdate() {
return [
['daily', null, null],
['git', null, null],
['beta', false, null],
['daily', null, null, null],
['git', null, null, null],
['beta', false, null, null],
['beta', [
'version' => '9.2.0',
], '9.2.0'],
['stable', false, null],
'versionstring' => 'Nextcloud 11.0.0',
], '9.2.0', 'Nextcloud 11.0.0'],
['stable', false, null, null],
['stable', [
'version' => '9.2.0',
], '9.2.0'],
['production', false, null],
'versionstring' => 'Nextcloud 11.0.0',
], '9.2.0', 'Nextcloud 11.0.0'],
['production', false, null, null],
['production', [
'version' => '9.2.0',
], '9.2.0'],
'versionstring' => 'Nextcloud 11.0.0',
], '9.2.0', 'Nextcloud 11.0.0'],
];
}

Expand All @@ -127,8 +130,9 @@ public function dataCheckCoreUpdate() {
* @param string $channel
* @param mixed $versionCheck
* @param null|string $notification
* @param null|string $readableVersion
*/
public function testCheckCoreUpdate($channel, $versionCheck, $notification) {
public function testCheckCoreUpdate($channel, $versionCheck, $notification, $readableVersion) {
$job = $this->getJob([
'getChannel',
'createVersionCheck',
Expand Down Expand Up @@ -164,12 +168,12 @@ public function testCheckCoreUpdate($channel, $versionCheck, $notification) {
} else {
$this->urlGenerator->expects($this->once())
->method('linkToRouteAbsolute')
->with('settings_admin')
->with('settings.AdminSettings.index')
->willReturn('admin-url');

$job->expects($this->once())
->method('createNotifications')
->willReturn('core', $notification, 'admin-url#updater');
->willReturn('core', $notification, 'admin-url#updater', $readableVersion);
}

$this->invokePrivate($job, 'checkCoreUpdate');
Expand Down