3a824ce3 |
1 | #!/usr/bin/php5 |
2 | <?php |
3 | |
0380bf85 |
4 | global $globals; |
3a824ce3 |
5 | require_once 'connect.db.inc.php'; |
0380bf85 |
6 | $globals->dbcharset = 'latin1'; |
3a824ce3 |
7 | |
629e500f |
8 | $tables = array ('city' => array('id', 'alias'), |
9 | 'city_in_maps' => array('city_id', 'map_id', 'infos'), |
10 | 'maps' => array('map_id'), |
11 | 'pays' => array('a2'), |
12 | 'region' => array('a2', 'region')); |
13 | foreach ($tables as $table => $keys) { |
3a824ce3 |
14 | $res = XDB::query("SELECT * FROM geoloc_$table"); |
15 | if (!$res) { |
16 | echo "$table\n"; |
17 | continue; |
18 | } |
19 | $all = $res->fetchAllAssoc(); |
20 | foreach ($all as &$array) { |
21 | $from = array(); |
22 | $to = array(); |
23 | foreach ($array as $key=>$value) { |
629e500f |
24 | if (in_array($key, $keys)) { |
25 | $from[] = $key . '=' . XDB::escape($value); |
26 | } |
3a824ce3 |
27 | $valued = utf8_decode($value); |
28 | if (is_utf8($value) && $valued != $value) { |
629e500f |
29 | $to[] = $key . '=' . XDB::escape($valued); |
3a824ce3 |
30 | } |
31 | } |
32 | if (!empty($to)) { |
33 | $to = implode(', ', $to); |
34 | $from = implode(' AND ', $from); |
35 | $sql = "UPDATE geoloc_$table SET $to WHERE $from"; |
36 | if (!XDB::execute($sql)) { |
37 | echo "Echec : $sql\n"; |
629e500f |
38 | } elseif (XDB::affectedRows() == 0) { |
39 | echo "$sql\n"; |
3a824ce3 |
40 | } |
41 | } |
42 | } |
43 | } |
44 | |
45 | ?> |