4 require('./connect.db.inc.php');
5 require_once('profil.func.inc.php');
7 $globals->debug
= 0; //do not store backtraces
10 function do_update_by_block($values)
12 // Update display_tel by block
13 // Because there is no mysql update syntax for multiple updates in one query
14 // we use a multiple insert syntax which will fail because the key already exist
15 // and then update the display_tel
16 XDB
::execute("INSERT INTO profile_phones (uid, link_type, link_id, tel_id ,tel_type,
17 search_tel, display_tel, pub, comment)
18 VALUES " . $values . "
19 ON DUPLICATE KEY UPDATE display_tel = VALUES(display_tel)");
22 $res = XDB
::query("SELECT DISTINCT g.phoneprf FROM geoloc_pays AS g WHERE g.phoneprf IS NOT NULL");
23 $prefixes = $res->fetchColumn();
24 foreach ($prefixes as $i => $prefix) {
25 $res = XDB
::query("SELECT g.phoneformat FROM geoloc_pays AS g
26 WHERE g.phoneprf = {?} AND g.phoneformat != '' LIMIT 1",
28 if ($res->numRows() > 0) {
29 $format = $res->fetchOneCell();
30 //Build regexp for mysql query
31 $len = strlen($format);
34 for ($i = 0; $i < $len; $i++
) {
49 //Appends the char after escaping it if necessary
50 $escape = array('[', ']', '{', '}', '(', ')', '*', '+', '?', '.', '^', '$', '|', '\\');
51 if (in_array($char, $escape)) {
52 $regexp .= '[' . $char . ']';
58 //allows additionnal spaces and numbers
61 for ($i = 0; $i < $nbPar; $i++
) {
65 $res = XDB
::iterator("SELECT uid, link_type, link_id, tel_id, tel_type, search_tel,
66 display_tel, pub, comment
68 WHERE search_tel LIKE {?} AND display_tel NOT REGEXP {?}",
69 $prefix . '%', $regexp);
70 if ($res->numRows() > 0)
72 //To speed up the update of phone numbers, theses updates are grouped by block of 1000
75 while ($phone = $res->next()) {
76 $disp = format_display_number($phone['search_tel'], $error, array('format' => $format, 'phoneprf' => $prefix));
80 $values .= "('" . addslashes($phone['uid']) . "', '" . addslashes($phone['link_type'])
81 . "', '" . addslashes($phone['link_id'])
82 . "', '" . addslashes($phone['tel_id']) . "', '" . addslashes($phone['tel_type'])
83 . "', '" . addslashes($phone['search_tel']) . "', '" . addslashes($disp)
84 . "', '" . addslashes($phone['pub']) . "', '" . addslashes($phone['comment']) . "')";
87 do_update_by_block($values);
93 do_update_by_block($values);
99 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: