first commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
echo "[".date("Y-m-d H:i:s")."] update_address_data job is starting.\n";
|
||||
|
||||
require('../backend.php');
|
||||
|
||||
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
|
||||
|
||||
$db_host = $savvyext->cfgReadChar('database.host');
|
||||
$db_name = $savvyext->cfgReadChar('database.name');
|
||||
$db_user = $savvyext->cfgReadChar('database.user');
|
||||
$db_pass = $savvyext->cfgReadChar('database.pass');
|
||||
$db_port = $savvyext->cfgReadLong('database.port');
|
||||
$connstr = "host=${db_host} port=${db_port} dbname=${db_name} user=${db_user} password=${db_pass}";
|
||||
$conn = pg_connect($connstr) or die ("Could not connect to server\n");
|
||||
|
||||
$db_host = $savvyext->cfgReadChar('database_replica.host');
|
||||
$db_name = $savvyext->cfgReadChar('database_replica.name');
|
||||
$db_user = $savvyext->cfgReadChar('database_replica.user');
|
||||
$db_pass = $savvyext->cfgReadChar('database_replica.pass');
|
||||
$db_port = $savvyext->cfgReadLong('database_replica.port');
|
||||
$readOnlyReplicaConnstr = "host=${db_host} port=${db_port} dbname=${db_name} user=${db_user} password=${db_pass}";
|
||||
$readOnlyReplicaConn = pg_connect($readOnlyReplicaConnstr);
|
||||
|
||||
$query = "SELECT * FROM address WHERE geometry IS NULL";
|
||||
|
||||
$rs = pg_query($readOnlyReplicaConn, $query) or die("Cannot execute query: $query\n");
|
||||
|
||||
while ($row = pg_fetch_assoc($rs)) {
|
||||
$id = $row['id'];
|
||||
$latitude = $row['latitude'];
|
||||
$longitude = $row['longitude'];
|
||||
|
||||
$updateQuery = "UPDATE address SET geometry = ST_SetSRID(ST_MakePoint($longitude, $latitude), 4326) where id = $id";
|
||||
|
||||
$result = pg_query($conn, $updateQuery);
|
||||
|
||||
echo "[".date("Y-m-d H:i:s")."] Update Geometric data for record: " . $row['id'] . " | " . $row['latitude'] . " | " . $row['longitude'];
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
pg_close($conn);
|
||||
pg_close($readOnlyReplicaConn);
|
||||
|
||||
echo "[".date("Y-m-d H:i:s")."] update_address_data job complete.\n";
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user