diff options
author | filip <filip.komar@gmail.com> | 2016-06-05 14:48:24 +0200 |
---|---|---|
committer | filip <filip.komar@gmail.com> | 2016-06-05 14:48:24 +0200 |
commit | 5552b0c89cf71b9b847f9c424255255c40c59877 (patch) | |
tree | f77a599a033829f826399d90817759f2b8a94512 /lib | |
parent | 7907ddd13e53da6b7b064ea4c9462520d2143437 (diff) | |
download | www-5552b0c89cf71b9b847f9c424255255c40c59877.tar www-5552b0c89cf71b9b847f9c424255255c40c59877.tar.gz www-5552b0c89cf71b9b847f9c424255255c40c59877.tar.bz2 www-5552b0c89cf71b9b847f9c424255255c40c59877.tar.xz www-5552b0c89cf71b9b847f9c424255255c40c59877.zip |
improve mirrorlist function
+ it now returns a shuffled list of ten mirrors with priority:
within the country, then continent and others
+ exclude source server (distrib-coffee.ipsl.jussieu.fr) to drop it's DL load
as a first choice in ISO and doc DL page and entirely from mirrorlist
+ some small bugfixes noted during testing
+ added some small code doc parts
+ some small code style polish
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Downloads.php | 84 |
1 files changed, 76 insertions, 8 deletions
diff --git a/lib/Downloads.php b/lib/Downloads.php index 9ea8ec756..85cff758b 100644 --- a/lib/Downloads.php +++ b/lib/Downloads.php @@ -129,6 +129,10 @@ class Downloads * Note that the mirrors list doesn't change with versions, for now; * it's a full or nothing list. * + * @param boolean $prod + * @param boolean $documentation + * @param boolean $mirrorlist + * * @return array */ public static function get_all_mirrors($prod = true, $documentation = false, $mirrorlist = false) @@ -205,9 +209,13 @@ class Downloads * - if it exists in the country otherwise * - on continent if it exists otherwise * - random mirror + * It can also prepare a list of mirrors for mirrorlist page * * @param string $country * @param string $continent + * @param boolean $prod + * @param boolean $documentation + * @param boolean $mirrorlist * * @return array */ @@ -216,31 +224,66 @@ class Downloads $mirs = self::get_all_mirrors($prod, $documentation, $mirrorlist); $continent = '_C:' . $continent; - $mirrors = array(); + $mirrors = array(); $fr_mirr_asist = array(); + $list_of_mirrs = array( + 'country' => array(), + 'continent_minus_country' => array(), + 'other_continents' => array() + ); foreach ($mirs as $curr_continent => $continent_mirrors) { - if (!is_null($continent) && $continent != $curr_continent) + if ($continent != $curr_continent) { + if ($mirrorlist) + { + foreach ($continent_mirrors as $mirror) { + $list_of_mirrs['other_continents'][] = $mirror['url']; + } + } continue; } foreach ($continent_mirrors as $mirror) { + if (strpos($mirror['url'], 'distrib-coffee.ipsl.jussieu.fr') !== false) + { + // exclude source server to drop it's DL load + continue; + } // keep assisting the french mirrors with german ones if ($mirror['country'] == 'DE') { $fr_mirr_asist[] = $mirror; } // only add german mirrors when french are on turn - // sorting of mirror db cache must be kept to work properly + // sorting of mirror db cache must be kept to work properly (DE before FR) if ($country == 'FR' && $mirror['country'] == 'FR' && count($fr_mirr_asist) > 0) { $mirrors[$continent] = $fr_mirr_asist; $fr_mirr_asist = array(); } - if ($mirror['country'] == $country) + if ($mirrorlist) { - $mirrors[$continent][] = $mirror; + if ($mirror['country'] == $country) + { + $list_of_mirrs['country'][] = $mirror['url']; + } + else + { + $list_of_mirrs['continent_minus_country'][] = $mirror['url']; + } + } + else + { + if ($mirror['country'] == $country) + { + $mirrors[$continent][] = $mirror; + } } } + if (count($mirrors) == 0) + { + // add all continent mirrors if country doesn't have any + $mirrors[$continent] = $continent_mirrors; + } } if (count($mirrors) > 0) { @@ -254,6 +297,19 @@ class Downloads $one_mirror = array_shift($mirs); $one_mirror['continent'] = $mirr_continent; + if ($mirrorlist) + { + shuffle($list_of_mirrs['country']); + shuffle($list_of_mirrs['continent_minus_country']); + shuffle($list_of_mirrs['other_continents']); + $resulting_mirrs = array_merge( + $list_of_mirrs['country'], + $list_of_mirrs['continent_minus_country'], + $list_of_mirrs['other_continents'] + ); + $one_mirror['mirrors_list'] = array_slice($resulting_mirrs, 0, 10); + } + return $one_mirror; } @@ -266,6 +322,10 @@ class Downloads * Setup session data about current visitor for downloads. * * @param boolean $force + * @param string $country + * @param boolean $prod + * @param boolean $documentation + * @param boolean $mirrorlist * * @return array * @@ -328,10 +388,14 @@ class Downloads $_SESSION['country'] = $country; $_SESSION['continent'] = $continent; } + if (!isset($continent)) + { + $continent = null; + } $mirror = $this->get_mirror($country, $continent, $prod, $documentation, $mirrorlist); $mirror['purl'] = parse_url($mirror['url']); - + // reassign country, as get_one_mirror() may have decided // to return a mirror from another country than the one // requested initially - @see get_one_mirror() @@ -351,7 +415,10 @@ class Downloads 'mirror' => $mirror ); } - // + if (!isset($mirror['mirrors_list'])) + { + $mirror['mirrors_list'] = array(); + } return array( 'arch' => $system['arch'], 'mirror_host' => $mirror['purl']['host'], @@ -360,7 +427,8 @@ class Downloads 'country' => $country, 'continent' => $continent, 'city' => $mirror['city'], - 'fuzzy_mirror' => $fuzzy_mirror + 'fuzzy_mirror' => $fuzzy_mirror, + 'mirrors_list' => $mirror['mirrors_list'], ); } } |