3 // WARNING: this script takes a few minutes to be executed completly, thus run it into a screen.
5 require_once 'connect.db.inc.php';
6 require_once '../../classes/phone.php';
8 $globals->debug
= 0; // Do not store backtraces.
10 print "Formats non formated phones. (1/2)\n";
11 $it = XDB
::rawIterator("SELECT search_tel AS search, display_tel AS display, comment, link_id,
12 tel_type AS type, link_type, tel_id AS id, pid, pub
14 WHERE search_tel = '' OR search_tel IS NULL
15 ORDER BY pid, link_id, tel_id");
16 $total = $it->total();
19 while ($item = $it->next()) {
20 $phone = new Phone($item);
28 printf("\r%u / %u", $i, $total);
31 printf("\r%u / %u", $i, $total);
32 print "\nFormating done.\n\n";
34 print "Deletes duplicated phones. (2/2)\n";
35 $pids = XDB
::rawFetchColumn("SELECT DISTINCT(pid)
36 FROM profile_phones AS p1
37 WHERE link_type = 'user' AND EXISTS (SELECT *
38 FROM profile_phones AS p2
39 WHERE p2.link_type = 'user' AND p2.pid = p1.pid AND p2.tel_id != p1.tel_id)
41 $total = count($pids);
46 $duplicates = array();
47 foreach ($pids as $pid) {
49 Phone
::iterate(array($pid), array(Phone
::LINK_PROFILE
), array(0));
50 while ($item = $it->next()) {
54 for ($i = 0; $i < $count; ++
$i) {
55 for ($j = $i +
1; $j < $count; ++
$j) {
56 if ($phones[$i]->search() == $phones[$j]->search()) {
57 $duplicates[$i] = true
;
61 foreach ($duplicates as $key => $bool) {
64 if (count($phones) != $count) {
65 $deleted +
= ($count - count($phones));
66 Phone
::deletePhones($pid, 'user');
68 foreach ($phones as $phone) {
73 XDB
::execute('UPDATE IGNORE profile_merge_issues
74 SET issues = REPLACE(issues, \'phone\', \'\')
75 WHERE pid = {?}', $pid);
84 printf("\r%u / %u", $done, $total);
87 printf("\r%u / %u", $done, $total);
88 print "\n$deleted phones deleted.\n\n";
90 print "That's all folks!\n";
92 /* vim:set et sw=4 sts=4 ts=4: */