예제 #1
0
파일: Fn.php 프로젝트: eschwartz/Fn
function joinAnd(array $predicates)
{
    return joinUsing($predicates, cb('all'));
}
예제 #2
0
 public static function updateActiveCountries(callback $callback = null)
 {
     self::updateCache($callback);
     $db = new DatabaseConnection();
     $cache = base::expand('app:/cache/geonames/');
     // Update hierarchy
     cb($callback, 'Importing hierarchy ...', 1);
     $fin = fopen('compress.zlib://' . $cache . 'hierarchy.gz', 'r');
     $rows = 0;
     $ltime = 0;
     while (!feof($fin)) {
         $fd = trim(fgets($fin));
         $ds = explode("\t", $fd . "\t\t");
         $db->updateRow("REPLACE INTO geonames_hierarchy " . "(parentid,geoid,htype) " . "VALUES " . "(%d,%d,%s)", $ds[0], $ds[1], $ds[2]);
         if (microtime(true) > $ltime + 1) {
             cb($callback, 'Importing hierarchy ... ' . $rows . " records imported", 1);
             $ltime = microtime(true);
         }
         $rows++;
     }
     cb($callback, 'Imported hierarchy (' . $rows . ' records)');
     fclose($fin);
     // Pull the list of countries to import
     $rs = $db->getRows("SELECT * FROM geonames_datasets WHERE active=1");
     foreach ($rs as $ci) {
         cb($callback, 'Importing ' . $ci['setkey'] . ' ...', 1);
         $fin = fopen('compress.zlib://' . $cache . $ci['setkey'] . '.gz', 'r');
         $rows = 0;
         $ltime = 0;
         while (!feof($fin)) {
             $dl = fgets($fin);
             if (trim($dl) != '') {
                 $ds = explode("\t", $dl);
                 $db->updateRow('REPLACE INTO geonames ' . '(geoid,name,asciiname,alternatenames,' . 'latitude,longitude,featureclass,featurecode,' . 'countrycode,countrycodealt,admin1code,admin2code,' . 'admin3code,admin4code,population,elevation,' . 'gtopo30,timezone,modificationdate) ' . 'VALUES ' . '(%d,%s,%s,%s, %.5f,%.5f,%s,%s,' . '%s,%s,%s,%s, %s,%s,%d,%d,' . '%d,%s,%s)', $ds[0], $ds[1], $ds[2], $ds[3], $ds[4], $ds[5], $ds[6], $ds[7], $ds[8], $ds[9], $ds[10], $ds[11], $ds[12], $ds[13], $ds[14], $ds[15], $ds[16], $ds[17], $ds[18]);
             }
             if (microtime(true) > $ltime + 1) {
                 cb($callback, 'Importing ' . $ci['setkey'] . ' ... ' . $rows . " records imported", 1);
                 $ltime = microtime(true);
             }
             $rows++;
         }
         fclose($fin);
         cb($callback, 'Imported ' . $ci['setkey'] . " (" . $rows . " records)");
     }
 }