8ec2ba33877d0110bc1011057e2efc475270ee57
[platal.git] / upgrade / 1.0.1 / merge_issues_geocoding.php
1 #!/usr/bin/php5
2 <?php
3 // WARNING: this script takes a few weeks to be executed completly, thus run it into a screen.
4
5 require_once 'connect.db.inc.php';
6 require_once '../../classes/address.php';
7
8 $globals->debug = 0; // Do not store backtraces.
9
10 print "Tries to geocode addresses (due a bug in the previous release, all addresses must run once again).\n";
11 $time = XDB::fetchOneCell('SELECT COUNT(distinct(pid), jobid)
12 FROM profile_addresses');
13 $time = ceil($time / 60 / 24);
14 print "It will approximately take $time days.\n";
15
16 $it = XDB::rawIterator('SELECT *
17 FROM profile_addresses
18 ORDER BY pid, jobid, type, id');
19 $total = $it->total();
20 $i = 0;
21 $j = 0;
22 printf("\r%u / %u", $i, $total);
23 $pid = 0;
24 $jobid = 0;
25 while ($item = $it->next()) {
26 $address = new Address($item);
27 $address->format(array(true, true));
28 $address->delete();
29 $address->save();
30 if (!($pid == $address->pid && $jobid == $address->jobid)) {
31 $pid = $address->pid;
32 $jobid = $address->jobid;
33 sleep(60);
34 }
35
36 ++$i;
37 ++$j;
38 if ($j == 10) {
39 $j = 0;
40 printf("\r%u / %u", $i, $total);
41 }
42 }
43 printf("\r%u / %u", $i, $total);
44 print "\nGeocoding done.\n\n";
45 print "That's all folks!\n";
46
47 /* vim:set et sw=4 sts=4 ts=4: */
48 ?>