X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=bin%2FformatAddresses.php;h=f73b288258bae7627bbf726055e8268324f3366b;hb=fe5ccad978199cfbe71c583280b999769a27c9b2;hp=6b8a8dd4f9b69f43653fa2b80b5feab5d590e130;hpb=e999a40a812f8a2f350d69c5e1611669ff8937d1;p=platal.git diff --git a/bin/formatAddresses.php b/bin/formatAddresses.php index 6b8a8dd..f73b288 100755 --- a/bin/formatAddresses.php +++ b/bin/formatAddresses.php @@ -24,17 +24,18 @@ require './connect.db.inc.php'; require_once '../classes/address.php'; require_once '../classes/geocoder.php'; require_once '../classes/gmapsgeocoder.php'; +require_once '../classes/visibility.php'; $globals->debug = 0; // Do not store backtraces $targets = array( - 'g' => 'formatted_address', - 'p' => 'postalText' + 'g' => 'pa.formatted_address', + 'p' => 'pa.postalText' ); $ranges = array( 'f' => ' != \'\'', 'e' => ' = \'\'', - 'a' => 'IS NOT NULL' + 'a' => ' IS NOT NULL' ); $options = getopt('g::t:r:h::', array('geocode::', 'target:', 'range:', 'help::')); @@ -85,11 +86,12 @@ EOF; exit; } -print "Formats addresses addresses.\n"; +print "Formats addresses.\n"; -$where = ''; if ($range != 'a') { - $where = 'WHERE ' . $targets[$target] . $ranges[$range]; + $where = $targets[$target] . $ranges[$range]; +} else { + $where = null; } if ($geocoding_required) { @@ -102,10 +104,7 @@ if ($geocoding_required) { $display_limit = 100; } -$it = XDB::rawIterator('SELECT * - FROM profile_addresses - ' . $where . ' - ORDER BY pid, jobid, type, id'); +$it = Address::iterate(array(), array(), array(), Visibility::get(Visibility::VIEW_PRIVATE), $where); $total = $it->total(); $i = 0; @@ -113,12 +112,11 @@ $j = 0; $skipped = 0; printf("\r%u / %u", $i, $total); -while ($item = $it->next()) { - $address = new Address($item); +while ($address = $it->next()) { $address->changed = ($geocoding_required ? 1 : 0); $address->format(); if ($address->delete()) { - $address->save(); + $address->save(false); } else { ++$skipped; }