Split merge_issues.php into two to fix merges faster.
[platal.git] / upgrade / 1.0.1 / merge_issues_phones.php
CommitLineData
74e1e725
SJ
1#!/usr/bin/php5
2<?php
3// WARNING: this script takes a few days to be executed completly, thus run it into a screen.
4
5require_once 'connect.db.inc.php';
6require_once '../../classes/phone.php';
7
8$globals->debug = 0; // Do not store backtraces.
9
10echo "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
13 FROM profile_phones
14 WHERE search_tel = '' OR search_tel IS NULL
15 ORDER BY pid, link_id, tel_id");
16while ($phone = new Phone($it->next())) {
17 $phone->delete();
18 $phone->save();
19}
20
21echo "Deletes duplicated phones. (2/2)\n";
22$it = XDB::rawIterator("SELECT search_tel AS search, display_tel AS display, comment, link_id,
23 tel_type AS type, link_type, tel_id AS id, pid, pub
24 FROM profile_phones
25 WHERE link_type = 'user'
26 ORDER BY pid, tel_id");
27$phones = array();
28$duplicates = array();
29$phone = new Phone($it->next());
30$pid = $phone->pid();
31$phones[] = $phone;
32$count = 1;
33while ($phone = new Phone($it->next())) {
34 if ($phone->pid() == $pid) {
35 $phone[] = $phone;
36 ++$count;
37 } else {
38 if ($count != 1) {
39 for ($i = 0; $i < $count; ++$i) {
40 for ($j = $i + 1; $j < $count; ++$j) {
41 if ($phones[$i]->search() == $phones[$j]->search()) {
42 $duplicates[$i] = true;
43 }
44 }
45 }
46 foreach ($duplicates as $key => $bool) {
47 unset($phones[$key]);
48 }
49 if (count($phones) != $count) {
50 Phone::deletePhones($pid, 'user');
51 $id = 0;
52 foreach ($phones as $phone) {
53 $phone->setId($id);
54 $phone->save();
55 ++$id;
56 }
57 XDB::execute('UPDATE profile_merge_issues
58 SET issues = REPLACE(issues, \'phone\', \'\')
59 WHERE pid = {?}', $pid);
60 }
61 unset($duplicates);
62 }
63 unset($phones);
64 $pid = $phone->pid();
65 $phones[] = $phone;
66 $count = 1;
67 }
68}
69
70echo "That's all folks!\n";
71
72/* vim:set et sw=4 sts=4 ts=4: */
73?>