Do not check for updates if we have no internet
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
a61d88f473
commit
529623e749
|
@ -33,7 +33,7 @@ class VersionCheck {
|
||||||
|
|
||||||
/** @var IClientService */
|
/** @var IClientService */
|
||||||
private $clientService;
|
private $clientService;
|
||||||
|
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
|
@ -54,6 +54,11 @@ class VersionCheck {
|
||||||
* @return array|bool
|
* @return array|bool
|
||||||
*/
|
*/
|
||||||
public function check() {
|
public function check() {
|
||||||
|
// If this server is set to have no internet connection this is all not needed
|
||||||
|
if (!$this->config->getSystemValueBool('has_internet_connection', true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Look up the cache - it is invalidated all 30 minutes
|
// Look up the cache - it is invalidated all 30 minutes
|
||||||
if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) {
|
if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) {
|
||||||
return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true);
|
return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true);
|
||||||
|
|
|
@ -67,11 +67,16 @@ class VersionCheckTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(0))
|
->expects($this->at(0))
|
||||||
|
->method('getSystemValueBool')
|
||||||
|
->with('has_internet_connection', true)
|
||||||
|
->willReturn(true);
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(1))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue(time()));
|
->will($this->returnValue(time()));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(1))
|
->expects($this->at(2))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdateResult')
|
->with('core', 'lastupdateResult')
|
||||||
->will($this->returnValue(json_encode($expectedResult)));
|
->will($this->returnValue(json_encode($expectedResult)));
|
||||||
|
@ -92,30 +97,35 @@ class VersionCheckTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(0))
|
->expects($this->at(0))
|
||||||
|
->method('getSystemValueBool')
|
||||||
|
->with('has_internet_connection', true)
|
||||||
|
->willReturn(true);
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(1))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(1))
|
->expects($this->at(2))
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
||||||
->willReturnArgument(1);
|
->willReturnArgument(1);
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(2))
|
->expects($this->at(3))
|
||||||
->method('setAppValue')
|
->method('setAppValue')
|
||||||
->with('core', 'lastupdatedat', $this->isType('integer'));
|
->with('core', 'lastupdatedat', $this->isType('integer'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(4))
|
->expects($this->at(5))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'installedat')
|
->with('core', 'installedat')
|
||||||
->will($this->returnValue('installedat'));
|
->will($this->returnValue('installedat'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(5))
|
->expects($this->at(6))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue('lastupdatedat'));
|
->will($this->returnValue('lastupdatedat'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(6))
|
->expects($this->at(7))
|
||||||
->method('setAppValue')
|
->method('setAppValue')
|
||||||
->with('core', 'lastupdateResult', json_encode($expectedResult));
|
->with('core', 'lastupdateResult', json_encode($expectedResult));
|
||||||
|
|
||||||
|
@ -140,30 +150,35 @@ class VersionCheckTest extends \Test\TestCase {
|
||||||
public function testCheckWithInvalidXml() {
|
public function testCheckWithInvalidXml() {
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(0))
|
->expects($this->at(0))
|
||||||
|
->method('getSystemValueBool')
|
||||||
|
->with('has_internet_connection', true)
|
||||||
|
->willReturn(true);
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(1))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(1))
|
->expects($this->at(2))
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
||||||
->willReturnArgument(1);
|
->willReturnArgument(1);
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(2))
|
->expects($this->at(3))
|
||||||
->method('setAppValue')
|
->method('setAppValue')
|
||||||
->with('core', 'lastupdatedat', $this->isType('integer'));
|
->with('core', 'lastupdatedat', $this->isType('integer'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(4))
|
->expects($this->at(5))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'installedat')
|
->with('core', 'installedat')
|
||||||
->will($this->returnValue('installedat'));
|
->will($this->returnValue('installedat'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(5))
|
->expects($this->at(6))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue('lastupdatedat'));
|
->will($this->returnValue('lastupdatedat'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(6))
|
->expects($this->at(7))
|
||||||
->method('setAppValue')
|
->method('setAppValue')
|
||||||
->with('core', 'lastupdateResult', '[]');
|
->with('core', 'lastupdateResult', '[]');
|
||||||
|
|
||||||
|
@ -190,25 +205,30 @@ class VersionCheckTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(0))
|
->expects($this->at(0))
|
||||||
|
->method('getSystemValueBool')
|
||||||
|
->with('has_internet_connection', true)
|
||||||
|
->willReturn(true);
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(1))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(1))
|
->expects($this->at(2))
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
||||||
->willReturnArgument(1);
|
->willReturnArgument(1);
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(2))
|
->expects($this->at(3))
|
||||||
->method('setAppValue')
|
->method('setAppValue')
|
||||||
->with('core', 'lastupdatedat', $this->isType('integer'));
|
->with('core', 'lastupdatedat', $this->isType('integer'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(4))
|
->expects($this->at(5))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'installedat')
|
->with('core', 'installedat')
|
||||||
->will($this->returnValue('installedat'));
|
->will($this->returnValue('installedat'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(5))
|
->expects($this->at(6))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue('lastupdatedat'));
|
->will($this->returnValue('lastupdatedat'));
|
||||||
|
@ -235,30 +255,35 @@ class VersionCheckTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(0))
|
->expects($this->at(0))
|
||||||
|
->method('getSystemValueBool')
|
||||||
|
->with('has_internet_connection', true)
|
||||||
|
->willReturn(true);
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(1))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(1))
|
->expects($this->at(2))
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
||||||
->willReturnArgument(1);
|
->willReturnArgument(1);
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(2))
|
->expects($this->at(3))
|
||||||
->method('setAppValue')
|
->method('setAppValue')
|
||||||
->with('core', 'lastupdatedat', $this->isType('integer'));
|
->with('core', 'lastupdatedat', $this->isType('integer'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(4))
|
->expects($this->at(5))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'installedat')
|
->with('core', 'installedat')
|
||||||
->will($this->returnValue('installedat'));
|
->will($this->returnValue('installedat'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(5))
|
->expects($this->at(6))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue('lastupdatedat'));
|
->will($this->returnValue('lastupdatedat'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(6))
|
->expects($this->at(7))
|
||||||
->method('setAppValue')
|
->method('setAppValue')
|
||||||
->with('core', 'lastupdateResult', json_encode($expectedResult));
|
->with('core', 'lastupdateResult', json_encode($expectedResult));
|
||||||
|
|
||||||
|
@ -285,25 +310,30 @@ class VersionCheckTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(0))
|
->expects($this->at(0))
|
||||||
|
->method('getSystemValueBool')
|
||||||
|
->with('has_internet_connection', true)
|
||||||
|
->willReturn(true);
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(1))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(1))
|
->expects($this->at(2))
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
|
||||||
->willReturnArgument(1);
|
->willReturnArgument(1);
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(2))
|
->expects($this->at(3))
|
||||||
->method('setAppValue')
|
->method('setAppValue')
|
||||||
->with('core', 'lastupdatedat', $this->isType('integer'));
|
->with('core', 'lastupdatedat', $this->isType('integer'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(4))
|
->expects($this->at(5))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'installedat')
|
->with('core', 'installedat')
|
||||||
->will($this->returnValue('installedat'));
|
->will($this->returnValue('installedat'));
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->at(5))
|
->expects($this->at(6))
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('core', 'lastupdatedat')
|
->with('core', 'lastupdatedat')
|
||||||
->will($this->returnValue('lastupdatedat'));
|
->will($this->returnValue('lastupdatedat'));
|
||||||
|
@ -324,4 +354,14 @@ class VersionCheckTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->assertSame($expectedResult, $this->updater->check());
|
$this->assertSame($expectedResult, $this->updater->check());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNoInternet() {
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(0))
|
||||||
|
->method('getSystemValueBool')
|
||||||
|
->with('has_internet_connection', true)
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$this->assertFalse($this->updater->check());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue