Adds new ax_id.
[platal.git] / upgrade / newdirectory-0.0.1 / geocoding.php
CommitLineData
b4cb22fb
SJ
1#!/usr/bin/php5
2<?php
3require_once 'connect.db.inc.php';
4require_once 'geocoding.inc.php';
5
6$globals->debug = 0; // Do not store backtraces.
7
8$res = XDB::query('SELECT MIN(pid), MAX(pid)
9 FROM profiles');
10
11$pids = $res->fetchOneRow();
12
13$minPid = $pids[0];
14$maxPid = $pids[1];
15
16echo "Filling the 'text' fied is over. Geocoding will start now and will take a few days.\n";
17
18// Tries to geocode all the addresses.
19for ($pid = $minPid; $pid < $maxPid + 1; ++$pid) {
20 $res = XDB::iterator('SELECT *
21 FROM profile_addresses
22 WHERE pid = {?}',
23 $pid);
24
25 while ($address = $res->next()) {
26 $updateTime = $address['updateTime'];
27 $gmapsGeocoder = new GMapsGeocoder();
28 $address = $gmapsGeocoder->getGeocodedAddress($address);
29
30 if (!isset($address['geoloc'])) {
31 // TODO: use address and phone classes to update profile_job_enum and profile_phones once they are done.
32
33 XDB::execute('DELETE FROM profile_addresses
34 WHERE pid = {?} AND id = {?} AND type = {?}',
35 $address['pid'], $address['id'], $address['type']);
36
37 Geocoder::getAreaId($address, 'administrativeArea');
38 Geocoder::getAreaId($address, 'subAdministrativeArea');
39 Geocoder::getAreaId($address, 'locality');
40 XDB::execute('INSERT INTO profile_addresses (pid, type, id, flags, accuracy,
41 text, postalText, postalCode, localityId,
42 subAdministrativeAreaId, administrativeAreaId,
43 countryId, latitude, longitude, updateTime, pub, comment,
44 north, south, east, west)
45 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?},
46 {?}, {?}, FROM_UNIXTIME({?}), {?}, {?}, {?}, {?}, {?}, {?})',
47 $address['pid'], $address['type'], $address['id'], $flags, $address['accuracy'],
48 $address['text'], $address['postalText'], $address['postalCode'], $address['localityId'],
49 $address['subAdministrativeAreaId'], $address['administrativeAreaId'],
50 $address['countryId'], $address['latitude'], $address['longitude'],
51 $updateTime, $address['pub'], $address['comment'],
52 $address['north'], $address['south'], $address['east'], $address['west']);
53 } else {
54 XDB::execute('UPDATE profile_addresses
55 SET postalText = {?}
56 WHERE pid = {?} AND id = {?} AND type = {?}',
57 $address['postalText'], $address['pid'], $address['id'], $address['type']);
58 }
59
60 sleep(60); // So we don't get blacklisted by Google.
61 }
62}
63
64echo "Geocoding is over.\n";
65
66/* vim:set et sw=4 sts=4 ts=4: */
67?>