diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2014-11-25 22:41:15 +0300 |
---|---|---|
committer | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2014-12-06 20:17:47 +0300 |
commit | 303fce44f487e50a09910acdb28bc6c99b4b04b8 (patch) | |
tree | dce2dc668f47b72ca6da5982f0ba1bc335461eaa /lib | |
parent | 94eb2e782fa164492dd2665e6651eaa7068039aa (diff) | |
download | nextcloud-server-303fce44f487e50a09910acdb28bc6c99b4b04b8.tar.gz nextcloud-server-303fce44f487e50a09910acdb28bc6c99b4b04b8.zip |
Use httphelper and cache response even when it empty
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/templatelayout.php | 2 | ||||
-rw-r--r-- | lib/private/updater.php | 40 |
2 files changed, 21 insertions, 21 deletions
diff --git a/lib/private/templatelayout.php b/lib/private/templatelayout.php index a066f90bb23..aefb93ec266 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()); $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..5846a6a655a 100644 --- a/lib/private/updater.php +++ b/lib/private/updater.php @@ -25,6 +25,11 @@ class Updater extends BasicEmitter { * @var \OC\Log $log */ private $log; + + /** + * @var \OC\HTTPHelper $helper; + */ + private $httpHelper; private $simulateStepEnabled; @@ -33,7 +38,8 @@ class Updater extends BasicEmitter { /** * @param \OC\Log $log */ - public function __construct($log = null) { + public function __construct($httpHelper, $log = null) { + $this->httpHelper = $httpHelper; $this->log = $log; $this->simulateStepEnabled = true; $this->updateStepEnabled = true; @@ -95,30 +101,24 @@ 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 !== false) { + $loadEntities = libxml_disable_entity_loader(true); + $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 \OC_Appconfig::setValue('core', 'lastupdateResult', json_encode($data)); - return $tmp; } |