Skip to content
Snippets Groups Projects
Unverified Commit b74c12c3 authored by Joas Schilling's avatar Joas Schilling
Browse files

Use the readable version for notifications

parent 14d226dc
No related branches found
No related tags found
No related merge requests found
......@@ -99,7 +99,7 @@ class BackgroundJob extends TimedJob {
$status = $updater->check();
if (isset($status['version'])) {
$url = $this->urlGenerator->linkToRouteAbsolute('settings_admin') . '#updater';
$this->createNotifications('core', $status['version'], $url);
$this->createNotifications('core', $status['version'], $url, $status['versionstring']);
}
}
......@@ -123,8 +123,9 @@ class BackgroundJob extends TimedJob {
* @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
......@@ -139,9 +140,14 @@ class BackgroundJob extends TimedJob {
$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);
......
......@@ -66,9 +66,10 @@ class Notifier implements INotifier {
$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'];
......@@ -76,9 +77,10 @@ class Notifier implements INotifier {
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;
}
......
......@@ -104,20 +104,23 @@ class BackgroundJobTest extends TestCase {
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'],
];
}
......@@ -127,8 +130,9 @@ class BackgroundJobTest extends TestCase {
* @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',
......@@ -169,7 +173,7 @@ class BackgroundJobTest extends TestCase {
$job->expects($this->once())
->method('createNotifications')
->willReturn('core', $notification, 'admin-url#updater');
->willReturn('core', $notification, 'admin-url#updater', $readableVersion);
}
$this->invokePrivate($job, 'checkCoreUpdate');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment