Merge pull request #1540 from nextcloud/switch-for-autoupdater-control

Switch for autoupdater control
This commit is contained in:
Lukas Reschke 2016-09-27 16:06:38 +02:00 committed by GitHub
commit a4b2b9058e
9 changed files with 53 additions and 18 deletions

View File

@ -35,6 +35,11 @@ $(document).ready(function(){
body.removeAttr('id');
body.attr('id', 'body-settings');
}
},
error: function(){
OC.Notification.showTemporary(t('updatenotification', 'Could not start updater, please try the manual update'));
$('#oca_updatenotification_button').addClass('hidden');
$('#oca_updatenotification_section .button').removeClass('hidden');
}
});
});

View File

@ -107,11 +107,13 @@ class AdminController extends Controller implements ISettings {
$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
$params = [
'isNewVersionAvailable' => ($updateState === []) ? false : true,
'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
'lastChecked' => $lastUpdateCheck,
'currentChannel' => $currentChannel,
'channels' => $channels,
'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'],
'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'],
'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'],
'updaterEnabled' => $updateState['updaterEnabled'],
'notify_groups' => implode('|', $notifyGroups),
];

View File

@ -46,9 +46,13 @@ class UpdateChecker {
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://') {
$result['updateLink'] = $data['web'];
}
if(substr($data['url'], 0, 8) === 'https://') {
$result['downloadLink'] = $data['url'];
}
return $result;
}

View File

@ -14,13 +14,18 @@
$currentChannel = $_['currentChannel'];
?>
<form id="oca_updatenotification_section" class="followupsection">
<?php if($isNewVersionAvailable === true): ?>
<?php if($isNewVersionAvailable === true) { ?>
<strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong>
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
<?php else: ?>
<?php if ($_['updaterEnabled']) { ?>
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
<?php } ?>
<?php if (!empty($_['downloadLink'])) { ?>
<a href="<?php p($_['downloadLink']); ?>" class="button<?php if ($_['updaterEnabled']) { p(' hidden'); } ?>"><?php p($l->t('Download now')) ?></a>
<?php } ?>
<?php } else { ?>
<strong><?php print_unescaped($l->t('Your version is up to date.')); ?></strong>
<span class="icon-info svg" title="<?php p($l->t('Checked on %s', [$lastCheckedDate])) ?>"></span>
<?php endif; ?>
<?php } ?>
<p>
<label for="release-channel"><?php p($l->t('Update channel:')) ?></label>

View File

@ -111,7 +111,12 @@ class AdminControllerTest extends TestCase {
$this->updateChecker
->expects($this->once())
->method('getUpdateState')
->willReturn(['updateVersion' => '8.1.2']);
->willReturn([
'updateAvailable' => true,
'updateVersion' => '8.1.2',
'downloadLink' => 'https://downloads.nextcloud.org/server',
'updaterEnabled' => true,
]);
$params = [
'isNewVersionAvailable' => true,
@ -119,6 +124,8 @@ class AdminControllerTest extends TestCase {
'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels,
'newVersionString' => '8.1.2',
'downloadLink' => 'https://downloads.nextcloud.org/server',
'updaterEnabled' => true,
'notify_groups' => 'admin',
];
@ -155,7 +162,7 @@ class AdminControllerTest extends TestCase {
$this->updateChecker
->expects($this->once())
->method('getUpdateState')
->willReturn([]);
->willReturn(['updaterEnabled' => false]);
$params = [
'isNewVersionAvailable' => false,
@ -163,6 +170,8 @@ class AdminControllerTest extends TestCase {
'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels,
'newVersionString' => '',
'downloadLink' => '',
'updaterEnabled' => 0,
'notify_groups' => 'admin',
];

View File

@ -50,11 +50,13 @@ class UpdateCheckerTest extends TestCase {
'versionstring' => 'Nextcloud 123',
'web'=> 'javascript:alert(1)',
'url'=> 'javascript:alert(2)',
'autoupdater'=> '0',
]);
$expected = [
'updateAvailable' => true,
'updateVersion' => 'Nextcloud 123',
'updaterEnabled' => false,
];
$this->assertSame($expected, $this->updateChecker->getUpdateState());
}
@ -68,12 +70,15 @@ class UpdateCheckerTest extends TestCase {
'versionstring' => 'Nextcloud 123',
'web'=> 'https://docs.nextcloud.com/myUrl',
'url'=> 'https://downloads.nextcloud.org/server',
'autoupdater'=> '1',
]);
$expected = [
'updateAvailable' => true,
'updateVersion' => 'Nextcloud 123',
'updaterEnabled' => true,
'updateLink' => 'https://docs.nextcloud.com/myUrl',
'downloadLink' => 'https://downloads.nextcloud.org/server',
];
$this->assertSame($expected, $this->updateChecker->getUpdateState());
}

View File

@ -519,7 +519,7 @@ $CONFIG = array(
/**
* URL that Nextcloud should use to look for updates
*/
'updater.server.url' => 'https://updates.nextcloud.com/update-server/',
'updater.server.url' => 'https://updates.nextcloud.com/updater_server/',
/**
* Is Nextcloud connected to the Internet or running in a closed network?

View File

@ -59,7 +59,7 @@ class VersionCheck {
return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true);
}
$updaterUrl = $this->config->getSystemValue('updater.server.url', 'https://updates.nextcloud.com/update-server/');
$updaterUrl = $this->config->getSystemValue('updater.server.url', 'https://updates.nextcloud.com/updater_server/');
$this->config->setAppValue('core', 'lastupdatedat', time());
@ -89,6 +89,7 @@ class VersionCheck {
$tmp['versionstring'] = (string)$data->versionstring;
$tmp['url'] = (string)$data->url;
$tmp['web'] = (string)$data->web;
$tmp['autoupdater'] = (string)$data->autoupdater;
} else {
libxml_clear_errors();
}

View File

@ -83,6 +83,7 @@ class VersionCheckTest extends \Test\TestCase {
'versionstring' => 'ownCloud 8.0.4',
'url' => 'https://download.owncloud.org/community/owncloud-8.0.4.zip',
'web' => 'http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html',
'autoupdater' => '0',
];
$this->config
@ -93,7 +94,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->config
->expects($this->at(1))
->method('getSystemValue')
->with('updater.server.url', 'https://updates.nextcloud.com/update-server/')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1);
$this->config
->expects($this->at(2))
@ -120,11 +121,12 @@ class VersionCheckTest extends \Test\TestCase {
<versionstring>ownCloud 8.0.4</versionstring>
<url>https://download.owncloud.org/community/owncloud-8.0.4.zip</url>
<web>http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html</web>
<autoupdater>0</autoupdater>
</owncloud>';
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.nextcloud.com/update-server/'))
->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/'))
->will($this->returnValue($updateXml));
$this->assertSame($expectedResult, $this->updater->check());
@ -139,7 +141,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->config
->expects($this->at(1))
->method('getSystemValue')
->with('updater.server.url', 'https://updates.nextcloud.com/update-server/')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1);
$this->config
->expects($this->at(2))
@ -164,7 +166,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.nextcloud.com/update-server/'))
->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/'))
->will($this->returnValue($updateXml));
$this->assertSame([], $this->updater->check());
@ -176,6 +178,7 @@ class VersionCheckTest extends \Test\TestCase {
'versionstring' => '',
'url' => '',
'web' => '',
'autoupdater' => '',
];
$this->config
@ -186,7 +189,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->config
->expects($this->at(1))
->method('getSystemValue')
->with('updater.server.url', 'https://updates.nextcloud.com/update-server/')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1);
$this->config
->expects($this->at(2))
@ -209,11 +212,12 @@ class VersionCheckTest extends \Test\TestCase {
<versionstring></versionstring>
<url></url>
<web></web>
<autoupdater></autoupdater>
</owncloud>';
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.nextcloud.com/update-server/'))
->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/'))
->will($this->returnValue($updateXml));
$this->assertSame($expectedResult, $this->updater->check());
@ -230,7 +234,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->config
->expects($this->at(1))
->method('getSystemValue')
->with('updater.server.url', 'https://updates.nextcloud.com/update-server/')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturnArgument(1);
$this->config
->expects($this->at(2))
@ -255,7 +259,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.nextcloud.com/update-server/'))
->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/'))
->will($this->returnValue($updateXml));
$this->assertSame($expectedResult, $this->updater->check());