diff --git a/administrator/components/com_installer/models/update.php b/administrator/components/com_installer/models/update.php index e1bbde987e7ee..2bd2b7c236ee7 100644 --- a/administrator/components/com_installer/models/update.php +++ b/administrator/components/com_installer/models/update.php @@ -405,7 +405,8 @@ private function install($update) return false; } - $url = $update->downloadurl->_data; + $url = $update->downloadurl->_data; + $mirrors = $update->get('mirrors', array()); if ($extra_query = $update->get('extra_query')) { @@ -413,7 +414,18 @@ private function install($update) $url .= $extra_query; } - $p_file = JInstallerHelper::downloadPackage($url); + $mirror = 0; + while (!($p_file = JInstallerHelper::downloadPackage($url)) && isset($mirrors[$mirror])) + { + $name = $mirrors[$mirror]; + $url = $update->$name->_data; + if ($extra_query) + { + $url .= (strpos($url, '?') === false) ? '?' : '&'; + $url .= $extra_query; + } + $mirror++; + } // Was the package downloaded? if (!$p_file) diff --git a/administrator/components/com_joomlaupdate/models/default.php b/administrator/components/com_joomlaupdate/models/default.php index 106c9804e7aed..9260049115614 100644 --- a/administrator/components/com_joomlaupdate/models/default.php +++ b/administrator/components/com_joomlaupdate/models/default.php @@ -251,6 +251,7 @@ public function download() { $updateInfo = $this->getUpdateInformation(); $packageURL = $updateInfo['object']->downloadurl->_data; + $mirrors = $updateInfo['object']->get('mirrors', array()); $headers = get_headers($packageURL, 1); // Follow the Location headers until the actual download URL is known @@ -279,7 +280,15 @@ public function download() if (!$exists) { // Not there, let's fetch it. - return $this->downloadPackage($packageURL, $target); + $mirror = 0; + while (!($download = $this->downloadPackage($packageURL, $target)) && isset($mirrors[$mirror])) + { + $name = $mirrors[$mirror]; + $packageURL = $updateInfo['object']->$name->_data; + $mirror++; + } + + return $download; } else { @@ -288,7 +297,15 @@ public function download() if (empty($filesize)) { - return $this->downloadPackage($packageURL, $target); + $mirror = 0; + while (!($download = $this->downloadPackage($packageURL, $target)) && isset($mirrors[$mirror])) + { + $name = $mirrors[$mirror]; + $packageURL = $updateInfo['object']->$name->_data; + $mirror++; + } + + return $download; } // Yes, it's there, skip downloading. @@ -335,7 +352,15 @@ protected function downloadPackage($url, $target) JFile::delete($target); // Download the package - $result = $http->get($url); + try + { + $result = $http->get($url); + } + catch (RuntimeException $e) + { + return false; + } + if (!$result || ($result->code != 200 && $result->code != 310)) { diff --git a/libraries/src/Updater/Update.php b/libraries/src/Updater/Update.php index dced0de77cf75..0e8a48dfd2914 100644 --- a/libraries/src/Updater/Update.php +++ b/libraries/src/Updater/Update.php @@ -89,6 +89,14 @@ class Update extends \JObject */ protected $group; + /** + * The mirrors name array + * + * @var array + * @since 11.1 + */ + protected $mirrors = array(); + /** * Update manifest `` element * @@ -246,6 +254,13 @@ protected function _getLastTag() */ public function _startElement($parser, $name, $attrs = array()) { + // Change name if is mirror + if ($name == 'DOWNLOADURL' && isset($this->currentUpdate->downloadurl)) + { + $name = 'MIRROR' . count($this->mirrors); + $this->mirrors[] = strtolower($name); + } + $this->stack[] = $name; $tag = $this->_getStackLocation();