]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use httphelper and cache response even when it empty
authorVictor Dubiniuk <victor.dubiniuk@gmail.com>
Tue, 25 Nov 2014 19:41:15 +0000 (22:41 +0300)
committerVictor Dubiniuk <victor.dubiniuk@gmail.com>
Sat, 6 Dec 2014 17:17:47 +0000 (20:17 +0300)
core/ajax/update.php
core/command/upgrade.php
lib/private/templatelayout.php
lib/private/updater.php

index 419992c989161c73c426e323f08e37ef29d576c0..85d5dc83ccf2065cb7fcc15f3f90b6caf61b3aa4 100644 (file)
@@ -9,7 +9,10 @@ if (OC::checkUpgrade(false)) {
 
        $l = new \OC_L10N('core');
        $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) {
                $eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
        });
index aaeb63a31240e71522fea4199a6b11cc3cafe972..1d74ad0a90e88a725b5b3b98bbad1358b1a54bba 100644 (file)
@@ -84,7 +84,7 @@ class Upgrade extends Command {
 
                if(\OC::checkUpgrade(false)) {
                        $self = $this;
-                       $updater = new Updater();
+                       $updater = new Updater(\OC::$server->getHTTPHelper());
 
                        $updater->setSimulateStepEnabled($simulateStepEnabled);
                        $updater->setUpdateStepEnabled($updateStepEnabled);
index a066f90bb23e14e7677265cedd93a2abd7d8ccee..aefb93ec266ab8f0380c62e3ecfc81bc145c7aee 100644 (file)
@@ -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()) {
index e07ff03ffc400dca814ff08d12e771c0f1cf97e1..5846a6a655a41b50923865ab2aebee66f6f816f7 100644 (file)
@@ -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;
        }