Merge pull request #1619 from nextcloud/backport-1617-update-notification-readable-version

[stable10] Update notification readable version (10.0.1 instead of 9.1.1.5)
This commit is contained in:
Lukas Reschke 2016-10-06 09:17:47 +02:00 committed by GitHub
commit bbde2f9b11
3 changed files with 30 additions and 18 deletions

View File

@ -98,8 +98,8 @@ class BackgroundJob extends TimedJob {
$status = $updater->check(); $status = $updater->check();
if (isset($status['version'])) { if (isset($status['version'])) {
$url = $this->urlGenerator->linkToRouteAbsolute('settings_admin') . '#updater'; $url = $this->urlGenerator->linkToRouteAbsolute('settings.AdminSettings.index') . '#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 $app
* @param string $version * @param string $version
* @param string $url * @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); $lastNotification = $this->config->getAppValue('updatenotification', $app, false);
if ($lastNotification === $version) { if ($lastNotification === $version) {
// We already notified about this update // We already notified about this update
@ -139,9 +140,14 @@ class BackgroundJob extends TimedJob {
$notification->setApp('updatenotification') $notification->setApp('updatenotification')
->setDateTime(new \DateTime()) ->setDateTime(new \DateTime())
->setObject($app, $version) ->setObject($app, $version)
->setSubject('update_available')
->setLink($url); ->setLink($url);
if ($visibleVersion !== '') {
$notification->setSubject('update_available', ['version' => $visibleVersion]);
} else {
$notification->setSubject('update_available');
}
foreach ($this->getUsersToNotify() as $uid) { foreach ($this->getUsersToNotify() as $uid) {
$notification->setUser($uid); $notification->setUser($uid);
$this->notificationManager->notify($notification); $this->notificationManager->notify($notification);

View File

@ -66,9 +66,10 @@ class Notifier implements INotifier {
$l = $this->l10NFactory->get('updatenotification', $languageCode); $l = $this->l10NFactory->get('updatenotification', $languageCode);
if ($notification->getObjectType() === 'core') { if ($notification->getObjectType() === 'core') {
$appName = $l->t('Nextcloud core');
$this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions()); $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions());
$parameters = $notification->getSubjectParameters();
$notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']]));
} else { } else {
$appInfo = $this->getAppInfo($notification->getObjectType()); $appInfo = $this->getAppInfo($notification->getObjectType());
$appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name'];
@ -76,9 +77,10 @@ class Notifier implements INotifier {
if (isset($this->appVersions[$notification->getObjectType()])) { if (isset($this->appVersions[$notification->getObjectType()])) {
$this->updateAlreadyInstalledCheck($notification, $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; return $notification;
} }

View File

@ -104,20 +104,23 @@ class BackgroundJobTest extends TestCase {
public function dataCheckCoreUpdate() { public function dataCheckCoreUpdate() {
return [ return [
['daily', null, null], ['daily', null, null, null],
['git', null, null], ['git', null, null, null],
['beta', false, null], ['beta', false, null, null],
['beta', [ ['beta', [
'version' => '9.2.0', 'version' => '9.2.0',
], '9.2.0'], 'versionstring' => 'Nextcloud 11.0.0',
['stable', false, null], ], '9.2.0', 'Nextcloud 11.0.0'],
['stable', false, null, null],
['stable', [ ['stable', [
'version' => '9.2.0', 'version' => '9.2.0',
], '9.2.0'], 'versionstring' => 'Nextcloud 11.0.0',
['production', false, null], ], '9.2.0', 'Nextcloud 11.0.0'],
['production', false, null, null],
['production', [ ['production', [
'version' => '9.2.0', '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 string $channel
* @param mixed $versionCheck * @param mixed $versionCheck
* @param null|string $notification * @param null|string $notification
* @param null|string $readableVersion
*/ */
public function testCheckCoreUpdate($channel, $versionCheck, $notification) { public function testCheckCoreUpdate($channel, $versionCheck, $notification, $readableVersion) {
$job = $this->getJob([ $job = $this->getJob([
'getChannel', 'getChannel',
'createVersionCheck', 'createVersionCheck',
@ -164,12 +168,12 @@ class BackgroundJobTest extends TestCase {
} else { } else {
$this->urlGenerator->expects($this->once()) $this->urlGenerator->expects($this->once())
->method('linkToRouteAbsolute') ->method('linkToRouteAbsolute')
->with('settings_admin') ->with('settings.AdminSettings.index')
->willReturn('admin-url'); ->willReturn('admin-url');
$job->expects($this->once()) $job->expects($this->once())
->method('createNotifications') ->method('createNotifications')
->willReturn('core', $notification, 'admin-url#updater'); ->willReturn('core', $notification, 'admin-url#updater', $readableVersion);
} }
$this->invokePrivate($job, 'checkCoreUpdate'); $this->invokePrivate($job, 'checkCoreUpdate');