Merge commit 'origin/master' into fusionax
[platal.git] / upgrade / 0.9.14 / geoloc.utf8.php
index 6ec1649..2c772f4 100755 (executable)
@@ -1,16 +1,16 @@
 #!/usr/bin/php5
 <?php
 
+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');
-XDB::execute("SET NAMES 'latin1'");
-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";
@@ -21,10 +21,12 @@ foreach ($tables as $table) {
         $from = array();
         $to   = array();
         foreach ($array as $key=>$value) {
-            $from[] = $key . '="' . mysql_real_escape_string($value) . '"';
+            if (in_array($key, $keys)) {
+                $from[] = $key . '=' . XDB::escape($value);
+            }
             $valued = utf8_decode($value);
             if (is_utf8($value) && $valued != $value) {
-                $to[] = $key . '="' . mysql_real_escape_string($valued) .'"';
+                $to[] = $key . '=' . XDB::escape($valued);
             }
         }
         if (!empty($to)) {
@@ -33,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";
             }
         }
     }