From 4ea29d3e39c5be282fc76f08d2e2f56f331e3840 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sun, 23 Oct 2011 23:01:47 +0200 Subject: [PATCH] Fixes bin/formatAddresses.php. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- bin/formatAddresses.php | 20 +++++++++----------- classes/address.php | 9 ++++++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/bin/formatAddresses.php b/bin/formatAddresses.php index 6b8a8dd..d207748 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::')); @@ -87,9 +88,10 @@ EOF; print "Formats addresses 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,8 +112,7 @@ $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()) { diff --git a/classes/address.php b/classes/address.php index 871526a..915152f 100644 --- a/classes/address.php +++ b/classes/address.php @@ -878,9 +878,9 @@ class Address } static public function iterate(array $pids = array(), array $types = array(), - array $jobids = array(), $visibility = null) + array $jobids = array(), $visibility = null, $where = null) { - return new AddressIterator($pids, $types, $jobids, $visibility); + return new AddressIterator($pids, $types, $jobids, $visibility, $where); } } @@ -895,9 +895,12 @@ class AddressIterator implements PlIterator { private $dbiter; - public function __construct(array $pids, array $types, array $jobids, $visibility) + public function __construct(array $pids, array $types, array $jobids, $visibility, $_where) { $where = array(); + if (!is_null($_where)) { + $where[] = $_where; + } if (count($pids) != 0) { $where[] = XDB::format('(pa.pid IN {?})', $pids); } -- 2.1.4