3 /***************************************************************************
4 * Copyright (C) 2003-2014 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
23 require './connect.db.inc.php';
24 require_once '../classes/address.php';
25 require_once '../classes/geocoder.php';
26 require_once '../classes/gmapsgeocoder.php';
27 require_once '../classes/visibility.php';
29 $globals->debug
= 0; // Do not store backtraces
32 'g' => 'pa.formatted_address',
33 'p' => 'pa.postalText'
41 $options = getopt('g::t:r:h::', array('geocode::', 'target:', 'range:', 'help::'));
43 $help_required = isset($options['h']) ||
isset($options['help']);
44 $geocoding_required = isset($options['g']) ||
isset($options['geocode']);
48 if (isset($options['t'])) {
49 $target = $options['t'];
50 } elseif (isset($options['target'])) {
51 $target = $options['target'];
54 if (isset($options['r'])) {
55 $range = $options['r'];
56 } elseif ($options['range']) {
57 $range = $options['range'];
60 $missing_option = !array_key_exists($target, $targets) ||
!array_key_exists($range, $ranges);
62 if ($missing_option ||
$help_required) {
65 formatAddresses.php [-g] -t [g|p] -r [f|e|a]
68 formatAddresses.php formats addresses. If the addresses need geocoding, this
69 must be specified (-g). The targetted group of addresses must be specified
70 (non formatted addresses, formatted addresses, all addresses).
74 Geocodes the adresses. If not required, the address will not be
76 -t, --target [ g | p ]
77 The selection will be made either on the geocoding
78 (formatted_address) or the postal address (postalText).
79 -r, --range [ f | e | a ]
80 The selection will include the addresses corresponding to the right
81 target, which are formatted, empty (non formatted) or all addresses.
89 print "Formats addresses.\n";
92 $where = $targets[$target] . $ranges[$range];
97 if ($geocoding_required) {
98 // Waiting time is computed as follows: 3600 * 24 / LIMIT,
99 // where LIMIT is google's limit reduced to take into account site geocoding.
100 $wait = ceil(3600 * 24 / 2000);
104 $display_limit = 100;
107 $it = Address
::iterate(array(), array(), array(), Visibility
::get(Visibility
::VIEW_PRIVATE
), $where);
109 $total = $it->total();
113 printf("\r%u / %u", $i, $total);
115 while ($address = $it->next()) {
116 $address->changed
= ($geocoding_required ?
1 : 0);
118 if ($address->delete()) {
119 $address->save(false
);
125 if ($i == $display_limit) {
128 printf("\r%u / %u", $i +
$display_limit * $j, $total);
130 sleep($wait * $address->geocoding_calls
);
132 printf("\r%u / %u", $i +
$display_limit * $j, $total);
135 printf("\n%u addresses skipped.\n", $skipped);
140 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: