]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/website/polygons.php
Merge pull request #2391 from lonvia/fix-sonar-issues
[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) {
34         $aWhere[] = "errormessage like 'Area reduced%'";
35     }
36     if ($sClass) {
37         $sWhere[] = "class = '".pg_escape_string($sClass)."'";
38     }
39
40     if (!empty($aWhere)) {
41         $sSQL .= ' WHERE '.join(' and ', $aWhere);
42     }
43
44     $sSQL .= ' ORDER BY updated desc LIMIT 1000';
45     $aPolygons = $oDB->getAll($sSQL);
46 }
47
48 if (CONST_Debug) {
49     var_dump($aPolygons);
50     exit;
51 }
52
53 if ($sOutputFormat == 'json') {
54     javascript_renderData($aPolygons);
55 }