Split merge_issues.php into two to fix merges faster.
authorStéphane Jacob <sj@m4x.org>
Mon, 25 Oct 2010 21:55:59 +0000 (23:55 +0200)
committerStéphane Jacob <sj@m4x.org>
Mon, 25 Oct 2010 21:56:07 +0000 (23:56 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
upgrade/1.0.1/README
upgrade/1.0.1/merge_issues_addresses.php [moved from upgrade/1.0.1/merge_issues.php with 50% similarity]
upgrade/1.0.1/merge_issues_phones.php [new file with mode: 0755]

index 65f0c11..4b789df 100644 (file)
@@ -1,3 +1,3 @@
 99_jobs.sql must be run after php scripts.
-Both merge.php and merge-issues.php must not be run during the release. They are only for merge purpose.
-On top of that, merge-issues.php requires to be run in a screen as it takes a couple of weeks to complete.
+Both merge.php and merge_issues_*.php must not be run during the release. They are only for merge purpose.
+On top of that, merge_issues_*.php require to be run in a screen in parallel as they take a couple of days/weeks to complete.
similarity index 50%
rename from upgrade/1.0.1/merge_issues.php
rename to upgrade/1.0.1/merge_issues_addresses.php
index c1a553d..2557586 100755 (executable)
@@ -3,72 +3,11 @@
 // WARNING: this script takes a few weeks to be executed completly, thus run it into a screen.
 
 require_once 'connect.db.inc.php';
-require_once '../../classes/phone.php';
 require_once '../../classes/address.php';
 
 $globals->debug = 0; // Do not store backtraces.
 
-echo "Formats non formated phones. (1/4)\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();
-}
-
-echo "Deletes duplicated phones. (2/4)\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");
-$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) {
-        for ($j = $i + 1; $j < $count; ++$j) {
-          if ($phones[$i]->search() == $phones[$j]->search()) {
-            $duplicates[$i] = true;
-          }
-        }
-      }
-      foreach ($duplicates as $key => $bool) {
-        unset($phones[$key]);
-      }
-      if (count($phones) != $count) {
-        Phone::deletePhones($pid, 'user');
-        $id = 0;
-        foreach ($phones as $phone) {
-          $phone->setId($id);
-          $phone->save();
-          ++$id;
-        }
-        XDB::execute('UPDATE  profile_merge_issues
-                         SET  issues = REPLACE(issues, \'phone\', \'\')
-                       WHERE  pid = {?}', $pid);
-      }
-      unset($duplicates);
-    }
-    unset($phones);
-    $pid = $phone->pid();
-    $phones[] = $phone;
-    $count = 1;
-  }
-}
-
-echo "Tries to geocode addresses (due a bug in the previous release, all addresses must run once again). (3/4)\n";
+echo "Tries to geocode addresses (due a bug in the previous release, all addresses must run once again). (1/2)\n";
 $it = XDB::rawIterator('SELECT  *
                           FROM  profile_addresses
                       ORDER BY  pid, jobid, type, id');
@@ -85,7 +24,7 @@ while ($address = new Address($it->next())) {
   }
 }
 
-echo "Deletes duplicated addresses. (4/4)\n";
+echo "Deletes duplicated addresses. (2/2)\n";
 $it = XDB::rawIterator("SELECT  *
                           FROM  profile_addresses
                          WHERE  type = 'home'
@@ -132,6 +71,7 @@ while ($address = new Address($it->next())) {
     $count = 1;
   }
 }
+
 echo "That's all folks!\n";
 
 /* vim:set et sw=4 sts=4 ts=4: */
diff --git a/upgrade/1.0.1/merge_issues_phones.php b/upgrade/1.0.1/merge_issues_phones.php
new file mode 100755 (executable)
index 0000000..fbbda81
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/php5
+<?php
+// WARNING: this script takes a few days to be executed completly, thus run it into a screen.
+
+require_once 'connect.db.inc.php';
+require_once '../../classes/phone.php';
+
+$globals->debug = 0; // Do not store backtraces.
+
+echo "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();
+}
+
+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");
+$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) {
+        for ($j = $i + 1; $j < $count; ++$j) {
+          if ($phones[$i]->search() == $phones[$j]->search()) {
+            $duplicates[$i] = true;
+          }
+        }
+      }
+      foreach ($duplicates as $key => $bool) {
+        unset($phones[$key]);
+      }
+      if (count($phones) != $count) {
+        Phone::deletePhones($pid, 'user');
+        $id = 0;
+        foreach ($phones as $phone) {
+          $phone->setId($id);
+          $phone->save();
+          ++$id;
+        }
+        XDB::execute('UPDATE  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";
+
+/* vim:set et sw=4 sts=4 ts=4: */
+?>