Use httphelper and cache response even when it empty
This commit is contained in:
parent
94eb2e782f
commit
303fce44f4
|
@ -9,7 +9,10 @@ if (OC::checkUpgrade(false)) {
|
||||||
|
|
||||||
$l = new \OC_L10N('core');
|
$l = new \OC_L10N('core');
|
||||||
$eventSource = \OC::$server->createEventSource();
|
$eventSource = \OC::$server->createEventSource();
|
||||||
$updater = new \OC\Updater(\OC_Log::$object);
|
$updater = new \OC\Updater(
|
||||||
|
\OC::$server->getHTTPHelper(),
|
||||||
|
\OC_Log::$object
|
||||||
|
);
|
||||||
$updater->listen('\OC\Updater', 'maintenanceStart', function () use ($eventSource, $l) {
|
$updater->listen('\OC\Updater', 'maintenanceStart', function () use ($eventSource, $l) {
|
||||||
$eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
|
$eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
|
||||||
});
|
});
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Upgrade extends Command {
|
||||||
|
|
||||||
if(\OC::checkUpgrade(false)) {
|
if(\OC::checkUpgrade(false)) {
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$updater = new Updater();
|
$updater = new Updater(\OC::$server->getHTTPHelper());
|
||||||
|
|
||||||
$updater->setSimulateStepEnabled($simulateStepEnabled);
|
$updater->setSimulateStepEnabled($simulateStepEnabled);
|
||||||
$updater->setUpdateStepEnabled($updateStepEnabled);
|
$updater->setUpdateStepEnabled($updateStepEnabled);
|
||||||
|
|
|
@ -44,7 +44,7 @@ class OC_TemplateLayout extends OC_Template {
|
||||||
// Update notification
|
// Update notification
|
||||||
if($this->config->getSystemValue('updatechecker', true) === true &&
|
if($this->config->getSystemValue('updatechecker', true) === true &&
|
||||||
OC_User::isAdminUser(OC_User::getUser())) {
|
OC_User::isAdminUser(OC_User::getUser())) {
|
||||||
$updater = new \OC\Updater();
|
$updater = new \OC\Updater(\OC::$server->getHTTPHelper());
|
||||||
$data = $updater->check();
|
$data = $updater->check();
|
||||||
|
|
||||||
if(isset($data['version']) && $data['version'] != '' and $data['version'] !== Array()) {
|
if(isset($data['version']) && $data['version'] != '' and $data['version'] !== Array()) {
|
||||||
|
|
|
@ -26,6 +26,11 @@ class Updater extends BasicEmitter {
|
||||||
*/
|
*/
|
||||||
private $log;
|
private $log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \OC\HTTPHelper $helper;
|
||||||
|
*/
|
||||||
|
private $httpHelper;
|
||||||
|
|
||||||
private $simulateStepEnabled;
|
private $simulateStepEnabled;
|
||||||
|
|
||||||
private $updateStepEnabled;
|
private $updateStepEnabled;
|
||||||
|
@ -33,7 +38,8 @@ class Updater extends BasicEmitter {
|
||||||
/**
|
/**
|
||||||
* @param \OC\Log $log
|
* @param \OC\Log $log
|
||||||
*/
|
*/
|
||||||
public function __construct($log = null) {
|
public function __construct($httpHelper, $log = null) {
|
||||||
|
$this->httpHelper = $httpHelper;
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
$this->simulateStepEnabled = true;
|
$this->simulateStepEnabled = true;
|
||||||
$this->updateStepEnabled = true;
|
$this->updateStepEnabled = true;
|
||||||
|
@ -95,30 +101,24 @@ class Updater extends BasicEmitter {
|
||||||
$url = $updaterUrl . '?version=' . $versionString;
|
$url = $updaterUrl . '?version=' . $versionString;
|
||||||
|
|
||||||
// set a sensible timeout of 10 sec to stay responsive even if the update server is down.
|
// set a sensible timeout of 10 sec to stay responsive even if the update server is down.
|
||||||
$ctx = stream_context_create(
|
|
||||||
array(
|
|
||||||
'http' => array(
|
|
||||||
'timeout' => 10
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$xml = @file_get_contents($url, 0, $ctx);
|
|
||||||
if ($xml == false) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
$loadEntities = libxml_disable_entity_loader(true);
|
|
||||||
$data = @simplexml_load_string($xml);
|
|
||||||
libxml_disable_entity_loader($loadEntities);
|
|
||||||
|
|
||||||
$tmp = array();
|
$tmp = array();
|
||||||
$tmp['version'] = $data->version;
|
$xml = $this->httpHelper->getUrlContent($url);
|
||||||
$tmp['versionstring'] = $data->versionstring;
|
if ($xml !== false) {
|
||||||
$tmp['url'] = $data->url;
|
$loadEntities = libxml_disable_entity_loader(true);
|
||||||
$tmp['web'] = $data->web;
|
$data = @simplexml_load_string($xml);
|
||||||
|
libxml_disable_entity_loader($loadEntities);
|
||||||
|
|
||||||
|
$tmp['version'] = $data->version;
|
||||||
|
$tmp['versionstring'] = $data->versionstring;
|
||||||
|
$tmp['url'] = $data->url;
|
||||||
|
$tmp['web'] = $data->web;
|
||||||
|
} else {
|
||||||
|
$data = array();
|
||||||
|
}
|
||||||
|
|
||||||
// Cache the result
|
// Cache the result
|
||||||
\OC_Appconfig::setValue('core', 'lastupdateResult', json_encode($data));
|
\OC_Appconfig::setValue('core', 'lastupdateResult', json_encode($data));
|
||||||
|
|
||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue