Example #1
0
 function testQueryForMirrorsStandalone()
 {
     $sdo_mock = new SDO_Mock();
     $mirrors = queryForMirrors($sdo_mock, 'http', 1, 1);
     $this->assertTrue(empty($mirrors), 'Mirrors not empty.');
     $this->assertEqual($sdo_mock->requestCount, 2, 'Incorrect number of requests made to database');
     $sdo_mock->resetCount();
     $sdo_mock->returnJunk = true;
     $mirrors = queryForMirrors($sdo_mock, 'http', 1, 1);
     $this->assertFalse(empty($mirrors), 'Mirrors are empty');
     $this->assertEqual($sdo_mock->requestCount, 1, 'Incorrect number of requests made to database');
 }
Example #2
0
function queryForMirrors($sdo, $http_type, $where_lang, $location_id, $client_region = null, $recurse = false)
{
    $arguments = array($where_lang, $location_id);
    // If we are using GEOIP, we need to customize the SQL accordingly.
    if ($client_region) {
        $cr_sql = ' geoip_mirror_region_map.region_id = ? AND ';
        $arguments[] = $client_region;
    } else {
        $cr_sql = null;
    }
    // If we have recursed into this function, we have failed over to unhealthy
    // mirrors.
    if ($recurse) {
        $healthy = 0;
    } else {
        $healthy = 1;
    }
    $arguments[] = $healthy;
    // Let's fetch the mirrors.
    $mirrors = $sdo->get("\n        SELECT\n            mirror_mirrors.id,\n            baseurl,\n            rating\n        FROM \n            mirror_mirrors\n        JOIN\n            mirror_location_mirror_map ON mirror_mirrors.id = mirror_location_mirror_map.mirror_id\n        LEFT JOIN\n            mirror_lmm_lang_exceptions AS lang_exc ON (mirror_location_mirror_map.id = lang_exc.location_mirror_map_id AND NOT lang_exc.language = ?)\n        INNER JOIN\n            geoip_mirror_region_map ON (geoip_mirror_region_map.mirror_id = mirror_mirrors.id)\n        WHERE\n            mirror_location_mirror_map.location_id = ? AND\n            {$cr_sql}\n            mirror_mirrors.active='1' AND \n            mirror_location_mirror_map.active ='1' AND\n            mirror_location_mirror_map.healthy = ? AND\n            mirror_mirrors.baseurl LIKE '{$http_type}%'\n        ORDER BY rating", $arguments, SDO2::FETCH_NAMED, 'id');
    // If we found no mirrors and we are not in the second execution of this
    // function, let's try finding some unhealthy mirrors.
    if (!$mirrors && !$recurse) {
        return queryForMirrors($sdo, $http_type, $where_lang, $location_id, $client_region, true);
    }
    return $mirrors;
}
Example #3
0
             $region_id = $fallback_region;
         }
     }
     if ($region_id) {
         $http_type = setHttpType($ssl_only);
         $mirrors = queryForMirrors($sdo, $http_type, $where_lang, $location['id'], $client_region);
     }
 }
 // If we're here we've fallen back to global
 if (empty($mirrors) && !$fallback_global) {
     if (GEOIP) {
         $fallback_global = getGlobalFallbackProhibited($sdo, $client_region);
     }
     // either no region chosen or no mirror found in the given region
     $http_type = setHttpType($ssl_only);
     $mirrors = queryForMirrors($sdo, $http_type, $where_lang, $location['id']);
 }
 $mirrors_rand = array();
 $sum = 0;
 foreach ($mirrors as $buf) {
     $mirrors_rand[$buf['id']] = $buf['rating'];
     $sum += $buf['rating'];
 }
 $mirror_rand_id = getRandElement($mirrors_rand, $sum);
 $mirror = $mirrors[$mirror_rand_id];
 // did we get a valid mirror?
 if (!empty($mirror)) {
     // if logging is enabled, insert log
     if (LOGGING) {
         $sdo->query("UPDATE mirror_mirrors SET count=count+1 WHERE id = ?", array($mirror['id']), false);
         $sdo->query("UPDATE mirror_products SET count=count+1 WHERE id = ?", array($product_id), false);