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::'));
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) {
$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;
$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()) {
}
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);
}
}
{
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);
}