-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateSchoolCoordinates.php
More file actions
48 lines (42 loc) · 1.42 KB
/
updateSchoolCoordinates.php
File metadata and controls
48 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/* Copyright (c) 2012 Association France-ioi, MIT License http://opensource.org/licenses/MIT */
require_once("../shared/common.php");
require_once("googleMap.inc.php");
function addSchoolCoordinates()
{
global $db;
$onlyComplete = true; // set false to replace all (about 25 minutes in total)
$execRequests = true; // set false for debugging
$query = "SELECT `school`.* FROM `school` WHERE 1";
if ($onlyComplete) {
$query .= " AND `school`.coords = '0,0,0'";
}
// for step by step
// $query .= " LIMIT 5";
$stmt = $db->prepare($query);
$stmt->execute();
$all = array();
while($row = $stmt->fetchObject())
{
$all[] = $row;
}
echo "Number of queries to be made: " . count($all). "\n<br>";
flush(); ob_flush();
foreach ($all as $id => $row)
{
list($lat, $lng, $msg) = getCoordinatesSchool((array)$row);
$coords = "$lng,$lat,0";
if ($execRequests)
{
$query = "UPDATE school SET coords = :coords, saniMsg = CONCAT(saniMsg, :msg) WHERE ID = :ID";
$stmt = $db->prepare($query);
$stmt->execute(array(':ID' => $row->ID, ':coords' => $coords, ':msg' => $msg));
}
sleep(1);
echo "Completed query: " . ($id+1). " for ID=".$row->ID." [".$msg. "]<br>";
flush(); ob_flush();
}
}
header('Content-type: text/html; charset=utf-8');
addSchoolCoordinates();
?>