X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=upgrade%2Fnewdirectory-0.0.1%2Faddresses.php;h=01193d82249c4e706e43074b7bea2f3f9ac59396;hb=c67b874fd8d442bfded35295a819e7ce11a2d6dc;hp=ad5a4ee9fea76d590793a9288c3b2eeb5f93d70a;hpb=00ca0ad5370df5be4a0272364fb16a4385ffabfe;p=platal.git diff --git a/upgrade/newdirectory-0.0.1/addresses.php b/upgrade/newdirectory-0.0.1/addresses.php index ad5a4ee..01193d8 100755 --- a/upgrade/newdirectory-0.0.1/addresses.php +++ b/upgrade/newdirectory-0.0.1/addresses.php @@ -17,6 +17,7 @@ echo "This will take a few minutes.\n"; // Fills the 'text' field in profile_addresses. for ($pid = $minPid; $pid < $maxPid + 1; ++$pid) { + // First deals with home addresses (located in #x4dat#.adresses). $res = XDB::iterator("SELECT a.adrid AS id, a.adr1, a.adr2, a.adr3, UNIX_TIMESTAMP(a.datemaj) AS datemaj, a.postcode, a.city, a.cityid, a.region, a.regiontxt, @@ -37,63 +38,34 @@ for ($pid = $minPid; $pid < $maxPid + 1; ++$pid) { while ($address = $res->next()) { $text = get_address_text($address); - XDB::iterator('UPDATE profile_addresses - SET text = {?} - WHERE pid = {?} AND type = {?} AND id = {?}', - $text, $pid, $address['pro'] ? 'job' : 'home', $address['id']); + XDB::execute('UPDATE profile_addresses + SET text = {?} + WHERE pid = {?} AND type = {?} AND id = {?}', + $text, $pid, $address['pro'] ? 'job' : 'home', $address['id']); } -} - -echo "Filling the 'text' filles is over. Geocoding will start now and will take a few days\n"; -// Tries to geocode all the addresses. -for ($pid = $minPid; $pid < $maxPid + 1; ++$pid) { - $res = XDB::iterator('SELECT * - FROM profile_addresses - WHERE pid = {?}', - $pid); + // Then deals with job addresses (located in #x4dat#.entreprises). + $res = XDB::iterator("SELECT e.entrid AS id, j.id AS jobid, e.adr1, e.adr2, e.adr3, + e.postcode, e.city, e.cityid, e.region, e.regiontxt, + e.adr_pub AS pub, e.country, gp.pays AS countrytxt, gp.display, + e.glat AS precise_lat, e.glng AS precise_lon + FROM #x4dat#.entreprises AS e + INNER JOIN #x4dat#.geoloc_pays AS gp ON (gp.a2 = e.country) + INNER JOIN account_profiles AS ap ON (e.uid = ap.uid AND FIND_IN_SET('owner', ap.perms)) + INNER JOIN profile_job_enum AS j ON (e.entreprise = j.name) + WHERE ap.pid = {?} + ORDER BY e.entrid", + $pid); while ($address = $res->next()) { - $updateTime = $address['updateTime']; - $gmapsGeocoder = new GMapsGeocoder(); - $address = $gmapsGeocoder->getGeocodedAddress($address); - - if (!isset($address['geoloc'])) { - // TODO: use address and phone classes to update profile_job_enum and profile_phones once they are done. - - XDB::execute('DELETE FROM profile_addresses - WHERE pid = {?} AND id = {?} AND type = {?}', - $address['pid'], $address['id'], $address['type']); - - Geocoder::getAreaId($address, 'administrativeArea'); - Geocoder::getAreaId($address, 'subAdministrativeArea'); - Geocoder::getAreaId($address, 'locality'); - XDB::execute('INSERT INTO profile_addresses (pid, type, id, flags, accuracy, - text, postalText, postalCode, localityId, - subAdministrativeAreaId, administrativeAreaId, - countryId, latitude, longitude, updateTime, pub, comment, - north, south, east, west) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, - {?}, {?}, FROM_UNIXTIME({?}), {?}, {?}, {?}, {?}, {?}, {?})', - $address['pid'], $address['type'], $address['id'], $flags, $address['accuracy'], - $address['text'], $address['postalText'], $address['postalCode'], $address['localityId'], - $address['subAdministrativeAreaId'], $address['administrativeAreaId'], - $address['countryId'], $address['latitude'], $address['longitude'], - $updateTime, $address['pub'], $address['comment'], - $address['north'], $address['south'], $address['east'], $address['west']); - } else { - XDB::execute('UPDATE profile_addresses - SET postalText = {?} - WHERE pid = {?} AND id = {?} AND type = {?}', - $address['postalText'], $address['pid'], $address['id'], $address['type']); - } - - sleep(60); // So we don't get blacklisted by Google. + $text = get_address_text($address); + XDB::execute('UPDATE profile_addresses + SET text = {?} + WHERE pid = {?} AND type = {?} AND id = {?} AND jobid = {?}', + $text, $pid, 'job', $address['id'], $address['jobid']); } } -echo "Geocoding is over.\n"; - function get_address_text($adr) { $t = '';