Skip to content

Commit e550a3d

Browse files
authored
Merge pull request #7562 from nextcloud/fix-wrongly-cached-result
Cache final result of update check
2 parents b01d20c + 1beffa0 commit e550a3d

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

lib/private/Updater/VersionCheck.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,10 @@ public function check() {
101101
} else {
102102
libxml_clear_errors();
103103
}
104-
} else {
105-
$data = [];
106104
}
107105

108106
// Cache the result
109-
$this->config->setAppValue('core', 'lastupdateResult', json_encode($data));
107+
$this->config->setAppValue('core', 'lastupdateResult', json_encode($tmp));
110108
return $tmp;
111109
}
112110

tests/lib/Updater/VersionCheckTest.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function testCheckWithInvalidXml() {
161161
$this->config
162162
->expects($this->at(6))
163163
->method('setAppValue')
164-
->with('core', 'lastupdateResult', 'false');
164+
->with('core', 'lastupdateResult', '[]');
165165

166166
$updateXml = 'Invalid XML Response!';
167167
$this->updater
@@ -265,4 +265,55 @@ public function testCheckWithEmptyInvalidXmlResponse() {
265265

266266
$this->assertSame($expectedResult, $this->updater->check());
267267
}
268+
269+
public function testCheckWithMissingAttributeXmlResponse() {
270+
$expectedResult = [
271+
'version' => '',
272+
'versionstring' => '',
273+
'url' => '',
274+
'web' => '',
275+
'autoupdater' => '',
276+
];
277+
278+
$this->config
279+
->expects($this->at(0))
280+
->method('getAppValue')
281+
->with('core', 'lastupdatedat')
282+
->will($this->returnValue(0));
283+
$this->config
284+
->expects($this->at(1))
285+
->method('getSystemValue')
286+
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
287+
->willReturnArgument(1);
288+
$this->config
289+
->expects($this->at(2))
290+
->method('setAppValue')
291+
->with('core', 'lastupdatedat', $this->isType('integer'));
292+
$this->config
293+
->expects($this->at(4))
294+
->method('getAppValue')
295+
->with('core', 'installedat')
296+
->will($this->returnValue('installedat'));
297+
$this->config
298+
->expects($this->at(5))
299+
->method('getAppValue')
300+
->with('core', 'lastupdatedat')
301+
->will($this->returnValue('lastupdatedat'));
302+
303+
// missing autoupdater element should still not fail
304+
$updateXml = '<?xml version="1.0"?>
305+
<owncloud>
306+
<version></version>
307+
<versionstring></versionstring>
308+
<url></url>
309+
<web></web>
310+
</owncloud>';
311+
$this->updater
312+
->expects($this->once())
313+
->method('getUrlContent')
314+
->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/'))
315+
->will($this->returnValue($updateXml));
316+
317+
$this->assertSame($expectedResult, $this->updater->check());
318+
}
268319
}

0 commit comments

Comments
 (0)