X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=upgrade%2F0.9.14%2Fgeoloc.utf8.php;h=2c772f4a73f726c573272ce7b22487778d6534ed;hb=f3bfd6c9a14b70736b9416a1892d7548e160880b;hp=32d07cddeba287da1ce6500e9a42b653e5b353c2;hpb=f62bd784d0c37b8cbf773310e2c6457d856bceef;p=platal.git diff --git a/upgrade/0.9.14/geoloc.utf8.php b/upgrade/0.9.14/geoloc.utf8.php index 32d07cd..2c772f4 100755 --- a/upgrade/0.9.14/geoloc.utf8.php +++ b/upgrade/0.9.14/geoloc.utf8.php @@ -5,13 +5,12 @@ global $globals; require_once 'connect.db.inc.php'; $globals->dbcharset = 'latin1'; -function is_utf8($s) -{ - return @iconv('utf-8', 'utf-8', $s) == $s; -} - -$tables = array ('city', 'city_in_maps', 'maps', 'pays', 'region'); -foreach ($tables as $table) { +$tables = array ('city' => array('id', 'alias'), + 'city_in_maps' => array('city_id', 'map_id', 'infos'), + 'maps' => array('map_id'), + 'pays' => array('a2'), + 'region' => array('a2', 'region')); +foreach ($tables as $table => $keys) { $res = XDB::query("SELECT * FROM geoloc_$table"); if (!$res) { echo "$table\n"; @@ -22,10 +21,12 @@ foreach ($tables as $table) { $from = array(); $to = array(); foreach ($array as $key=>$value) { - $from[] = $key . '="' . XDB::escape($value) . '"'; + if (in_array($key, $keys)) { + $from[] = $key . '=' . XDB::escape($value); + } $valued = utf8_decode($value); if (is_utf8($value) && $valued != $value) { - $to[] = $key . '="' . XDB::escape($valued) .'"'; + $to[] = $key . '=' . XDB::escape($valued); } } if (!empty($to)) { @@ -34,6 +35,8 @@ foreach ($tables as $table) { $sql = "UPDATE geoloc_$table SET $to WHERE $from"; if (!XDB::execute($sql)) { echo "Echec : $sql\n"; + } elseif (XDB::affectedRows() == 0) { + echo "$sql\n"; } } }