Commit | Line | Data |
---|---|---|
74e1e725 SJ |
1 | #!/usr/bin/php5 |
2 | <?php | |
0444be72 | 3 | // WARNING: this script takes a few minutes to be executed completly, thus run it into a screen. |
74e1e725 SJ |
4 | |
5 | require_once 'connect.db.inc.php'; | |
6 | require_once '../../classes/phone.php'; | |
7 | ||
8 | $globals->debug = 0; // Do not store backtraces. | |
9 | ||
0444be72 | 10 | print "Formats non formated phones. (1/2)\n"; |
74e1e725 SJ |
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 | |
13 | FROM profile_phones | |
14 | WHERE search_tel = '' OR search_tel IS NULL | |
15 | ORDER BY pid, link_id, tel_id"); | |
0444be72 SJ |
16 | $total = $it->total(); |
17 | $i = 0; | |
18 | $j = 0; | |
19 | while ($item = $it->next()) { | |
20 | $phone = new Phone($item); | |
21 | $phone->delete(); | |
22 | $phone->save(); | |
23 | ||
24 | ++$i; | |
25 | ++$j; | |
26 | if ($j == 100) { | |
27 | $j = 0; | |
28 | printf("\r%u / %u", $i, $total); | |
29 | } | |
74e1e725 | 30 | } |
ded51efe | 31 | printf("\r%u / %u", $i, $total); |
0444be72 | 32 | print "\nFormating done.\n\n"; |
74e1e725 | 33 | |
0444be72 SJ |
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) | |
40 | ORDER BY pid"); | |
41 | $total = count($pids); | |
42 | $done = 0; | |
43 | $aux = 0; | |
ded51efe | 44 | $deleted = 0; |
74e1e725 SJ |
45 | $phones = array(); |
46 | $duplicates = array(); | |
0444be72 SJ |
47 | foreach ($pids as $pid) { |
48 | $count = 0; | |
ded51efe | 49 | Phone::iterate(array($pid), array(Phone::LINK_PROFILE), array(0)); |
0444be72 | 50 | while ($item = $it->next()) { |
ded51efe | 51 | $phones[] = $item; |
0444be72 SJ |
52 | ++$count; |
53 | } | |
54 | for ($i = 0; $i < $count; ++$i) { | |
74e1e725 | 55 | for ($j = $i + 1; $j < $count; ++$j) { |
0444be72 SJ |
56 | if ($phones[$i]->search() == $phones[$j]->search()) { |
57 | $duplicates[$i] = true; | |
58 | } | |
74e1e725 | 59 | } |
0444be72 SJ |
60 | } |
61 | foreach ($duplicates as $key => $bool) { | |
74e1e725 | 62 | unset($phones[$key]); |
0444be72 SJ |
63 | } |
64 | if (count($phones) != $count) { | |
ded51efe | 65 | $deleted += ($count - count($phones)); |
74e1e725 SJ |
66 | Phone::deletePhones($pid, 'user'); |
67 | $id = 0; | |
68 | foreach ($phones as $phone) { | |
0444be72 SJ |
69 | $phone->setId($id); |
70 | $phone->save(); | |
71 | ++$id; | |
74e1e725 | 72 | } |
0444be72 SJ |
73 | XDB::execute('UPDATE IGNORE profile_merge_issues |
74 | SET issues = REPLACE(issues, \'phone\', \'\') | |
75 | WHERE pid = {?}', $pid); | |
74e1e725 | 76 | } |
0444be72 | 77 | unset($duplicates); |
74e1e725 | 78 | unset($phones); |
74e1e725 | 79 | |
0444be72 SJ |
80 | ++$done; |
81 | ++$aux; | |
82 | if ($aux == 10) { | |
83 | $aux = 0; | |
84 | printf("\r%u / %u", $done, $total); | |
85 | } | |
86 | } | |
87 | printf("\r%u / %u", $done, $total); | |
ded51efe SJ |
88 | print "\n$deleted phones deleted.\n\n"; |
89 | ||
90 | print "That's all folks!\n"; | |
74e1e725 SJ |
91 | |
92 | /* vim:set et sw=4 sts=4 ts=4: */ | |
93 | ?> |