From 0444be72cfbbaa4241d1d1041d7b5a99b9e73fb9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Tue, 2 Nov 2010 12:01:38 +0100 Subject: [PATCH] Improves and fixes script about merge issues linked to phone. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- upgrade/1.0.1/merge_issues_phones.php | 106 ++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/upgrade/1.0.1/merge_issues_phones.php b/upgrade/1.0.1/merge_issues_phones.php index fbbda81..94651f4 100755 --- a/upgrade/1.0.1/merge_issues_phones.php +++ b/upgrade/1.0.1/merge_issues_phones.php @@ -1,73 +1,93 @@ #!/usr/bin/php5 debug = 0; // Do not store backtraces. -echo "Formats non formated phones. (1/2)\n"; +print "Formats non formated phones. (1/2)\n"; $it = XDB::rawIterator("SELECT search_tel AS search, display_tel AS display, comment, link_id, tel_type AS type, link_type, tel_id AS id, pid, pub FROM profile_phones WHERE search_tel = '' OR search_tel IS NULL ORDER BY pid, link_id, tel_id"); -while ($phone = new Phone($it->next())) { - $phone->delete(); - $phone->save(); +$total = $it->total(); +$i = 0; +$j = 0; +while ($item = $it->next()) { + $phone = new Phone($item); + $phone->delete(); + $phone->save(); + + ++$i; + ++$j; + if ($j == 100) { + $j = 0; + printf("\r%u / %u", $i, $total); + } } +printf("\r%u / %u", $i, $n); +print "\nFormating done.\n\n"; -echo "Deletes duplicated phones. (2/2)\n"; -$it = XDB::rawIterator("SELECT search_tel AS search, display_tel AS display, comment, link_id, - tel_type AS type, link_type, tel_id AS id, pid, pub - FROM profile_phones - WHERE link_type = 'user' - ORDER BY pid, tel_id"); +print "Deletes duplicated phones. (2/2)\n"; +$pids = XDB::rawFetchColumn("SELECT DISTINCT(pid) + FROM profile_phones AS p1 + WHERE link_type = 'user' AND EXISTS (SELECT * + FROM profile_phones AS p2 + WHERE p2.link_type = 'user' AND p2.pid = p1.pid AND p2.tel_id != p1.tel_id) + ORDER BY pid"); +$total = count($pids); +$done = 0; +$aux = 0; $phones = array(); $duplicates = array(); -$phone = new Phone($it->next()); -$pid = $phone->pid(); -$phones[] = $phone; -$count = 1; -while ($phone = new Phone($it->next())) { - if ($phone->pid() == $pid) { - $phone[] = $phone; - ++$count; - } else { - if ($count != 1) { - for ($i = 0; $i < $count; ++$i) { +foreach ($pids as $pid) { + $count = 0; + $it = XDB::iterator("SELECT search_tel AS search, display_tel AS display, comment, link_id, + tel_type AS type, link_type, tel_id AS id, pid, pub + FROM profile_phones + WHERE link_type = 'user' AND pid = {?} + ORDER BY tel_id", $pid); + while ($item = $it->next()) { + $phones[] = new Phone($item); + ++$count; + } + for ($i = 0; $i < $count; ++$i) { for ($j = $i + 1; $j < $count; ++$j) { - if ($phones[$i]->search() == $phones[$j]->search()) { - $duplicates[$i] = true; - } + if ($phones[$i]->search() == $phones[$j]->search()) { + $duplicates[$i] = true; + } } - } - foreach ($duplicates as $key => $bool) { + } + foreach ($duplicates as $key => $bool) { unset($phones[$key]); - } - if (count($phones) != $count) { + } + if (count($phones) != $count) { Phone::deletePhones($pid, 'user'); $id = 0; foreach ($phones as $phone) { - $phone->setId($id); - $phone->save(); - ++$id; + $phone->setId($id); + $phone->save(); + ++$id; } - XDB::execute('UPDATE profile_merge_issues - SET issues = REPLACE(issues, \'phone\', \'\') - WHERE pid = {?}', $pid); - } - unset($duplicates); + XDB::execute('UPDATE IGNORE profile_merge_issues + SET issues = REPLACE(issues, \'phone\', \'\') + WHERE pid = {?}', $pid); } + unset($duplicates); unset($phones); - $pid = $phone->pid(); - $phones[] = $phone; - $count = 1; - } -} -echo "That's all folks!\n"; + ++$done; + ++$aux; + if ($aux == 10) { + $aux = 0; + printf("\r%u / %u", $done, $total); + } +} +printf("\r%u / %u", $done, $total); +print "\n\nThat's all folks!\n"; /* vim:set et sw=4 sts=4 ts=4: */ ?> -- 2.1.4