]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/website/polygons.php
88b48ae8e4c22c6d915a76df3299f9fbd3c162e6
[nominatim.git] / lib-php / website / polygons.php
1 <?php
2
3 require_once(CONST_LibDir.'/init-website.php');
4 require_once(CONST_LibDir.'/log.php');
5 require_once(CONST_LibDir.'/output.php');
6 ini_set('memory_limit', '200M');
7
8 $oParams = new Nominatim\ParameterParser();
9 $sOutputFormat = $oParams->getSet('format', array('json'), 'json');
10 set_exception_handler_by_format($sOutputFormat);
11
12 $iDays = $oParams->getInt('days', false);
13 $bReduced = $oParams->getBool('reduced', false);
14 $sClass = $oParams->getString('class', false);
15
16 $oDB = new Nominatim\DB(CONST_Database_DSN);
17 $oDB->connect();
18
19 $iTotalBroken = (int) $oDB->getOne('SELECT count(*) FROM import_polygon_error');
20
21 $aPolygons = array();
22 while ($iTotalBroken && empty($aPolygons)) {
23     $sSQL = 'SELECT osm_type, osm_id, class, type, name->\'name\' as "name",';
24     $sSQL .= 'country_code, errormessage, updated';
25     $sSQL .= ' FROM import_polygon_error';
26
27     $aWhere = array();
28     if ($iDays) {
29         $aWhere[] = "updated > 'now'::timestamp - '".$iDays." day'::interval";
30         $iDays++;
31     }
32
33     if ($bReduced) $aWhere[] = "errormessage like 'Area reduced%'";
34     if ($sClass) $sWhere[] = "class = '".pg_escape_string($sClass)."'";
35
36     if (!empty($aWhere)) {
37         $sSQL .= ' WHERE '.join(' and ', $aWhere);
38     }
39
40     $sSQL .= ' ORDER BY updated desc LIMIT 1000';
41     $aPolygons = $oDB->getAll($sSQL);
42 }
43
44 if (CONST_Debug) {
45     var_dump($aPolygons);
46     exit;
47 }
48
49 if ($sOutputFormat == 'json') {
50     javascript_renderData($aPolygons);
51 }