diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-12-10 05:42:08 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-12-10 05:42:08 +0100 |
commit | 7028c7150dd3181c3416ad77ca675e85514cdae3 (patch) | |
tree | 3466360277aebfd91cbd6b26b3c54ebbc6c0ea58 /lib/private | |
parent | 263e008d7b0df17071a9d8ef915586d0cb5abab3 (diff) | |
parent | adab0ca98a9ab8f3d4f27909c6d46bb170595d20 (diff) | |
download | nextcloud-server-7028c7150dd3181c3416ad77ca675e85514cdae3.tar.gz nextcloud-server-7028c7150dd3181c3416ad77ca675e85514cdae3.zip |
Merge pull request #12664 from owncloud/fix-12164
Use httphelper and cache response even when it is empty
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/templatelayout.php | 2 | ||||
-rw-r--r-- | lib/private/updater.php | 65 |
2 files changed, 37 insertions, 30 deletions
diff --git a/lib/private/templatelayout.php b/lib/private/templatelayout.php index a066f90bb23..fa025721e53 100644 --- a/lib/private/templatelayout.php +++ b/lib/private/templatelayout.php @@ -44,7 +44,7 @@ class OC_TemplateLayout extends OC_Template { // Update notification if($this->config->getSystemValue('updatechecker', true) === true && OC_User::isAdminUser(OC_User::getUser())) { - $updater = new \OC\Updater(); + $updater = new \OC\Updater(\OC::$server->getHTTPHelper(), \OC::$server->getAppConfig()); $data = $updater->check(); if(isset($data['version']) && $data['version'] != '' and $data['version'] !== Array()) { diff --git a/lib/private/updater.php b/lib/private/updater.php index e07ff03ffc4..6272f77cfc2 100644 --- a/lib/private/updater.php +++ b/lib/private/updater.php @@ -25,6 +25,16 @@ class Updater extends BasicEmitter { * @var \OC\Log $log */ private $log; + + /** + * @var \OC\HTTPHelper $helper; + */ + private $httpHelper; + + /** + * @var \OCP\IAppConfig; + */ + private $config; private $simulateStepEnabled; @@ -33,8 +43,10 @@ class Updater extends BasicEmitter { /** * @param \OC\Log $log */ - public function __construct($log = null) { + public function __construct($httpHelper, $config, $log = null) { + $this->httpHelper = $httpHelper; $this->log = $log; + $this->config = $config; $this->simulateStepEnabled = true; $this->updateStepEnabled = true; } @@ -69,23 +81,23 @@ class Updater extends BasicEmitter { public function check($updaterUrl = null) { // Look up the cache - it is invalidated all 30 minutes - if ((\OC_Appconfig::getValue('core', 'lastupdatedat') + 1800) > time()) { - return json_decode(\OC_Appconfig::getValue('core', 'lastupdateResult'), true); + if (($this->config->getValue('core', 'lastupdatedat') + 1800) > time()) { + return json_decode($this->config->getValue('core', 'lastupdateResult'), true); } if (is_null($updaterUrl)) { $updaterUrl = 'https://apps.owncloud.com/updater.php'; } - \OC_Appconfig::setValue('core', 'lastupdatedat', time()); + $this->config->setValue('core', 'lastupdatedat', time()); - if (\OC_Appconfig::getValue('core', 'installedat', '') == '') { - \OC_Appconfig::setValue('core', 'installedat', microtime(true)); + if ($this->config->getValue('core', 'installedat', '') == '') { + $this->config->setValue('core', 'installedat', microtime(true)); } $version = \OC_Util::getVersion(); - $version['installed'] = \OC_Appconfig::getValue('core', 'installedat'); - $version['updated'] = \OC_Appconfig::getValue('core', 'lastupdatedat'); + $version['installed'] = $this->config->getValue('core', 'installedat'); + $version['updated'] = $this->config->getValue('core', 'lastupdatedat'); $version['updatechannel'] = \OC_Util::getChannel(); $version['edition'] = \OC_Util::getEditionString(); $version['build'] = \OC_Util::getBuild(); @@ -95,30 +107,25 @@ class Updater extends BasicEmitter { $url = $updaterUrl . '?version=' . $versionString; // 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['version'] = $data->version; - $tmp['versionstring'] = $data->versionstring; - $tmp['url'] = $data->url; - $tmp['web'] = $data->web; + $xml = $this->httpHelper->getUrlContent($url); + if ($xml) { + $loadEntities = libxml_disable_entity_loader(true); + $data = @simplexml_load_string($xml); + libxml_disable_entity_loader($loadEntities); + if ($data !== false) { + $tmp['version'] = $data->version; + $tmp['versionstring'] = $data->versionstring; + $tmp['url'] = $data->url; + $tmp['web'] = $data->web; + } + } else { + $data = array(); + } // Cache the result - \OC_Appconfig::setValue('core', 'lastupdateResult', json_encode($data)); - + $this->config->setValue('core', 'lastupdateResult', json_encode($data)); return $tmp; } @@ -218,7 +225,7 @@ class Updater extends BasicEmitter { $repair->run(); //Invalidate update feed - \OC_Appconfig::setValue('core', 'lastupdatedat', 0); + $this->config->setValue('core', 'lastupdatedat', 0); // only set the final version if everything went well \OC_Config::setValue('version', implode('.', \OC_Util::getVersion())); |