3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
11 require_once(CONST_LibDir.'/init-website.php');
12 require_once(CONST_LibDir.'/log.php');
13 require_once(CONST_LibDir.'/output.php');
14 ini_set('memory_limit', '200M');
16 $oParams = new Nominatim\ParameterParser();
17 $sOutputFormat = $oParams->getSet('format', array('json'), 'json');
18 set_exception_handler_by_format($sOutputFormat);
20 $iDays = $oParams->getInt('days', false);
21 $bReduced = $oParams->getBool('reduced', false);
22 $sClass = $oParams->getString('class', false);
24 $oDB = new Nominatim\DB(CONST_Database_DSN);
27 $iTotalBroken = (int) $oDB->getOne('SELECT count(*) FROM import_polygon_error');
30 while ($iTotalBroken && empty($aPolygons)) {
31 $sSQL = 'SELECT osm_type, osm_id, class, type, name->\'name\' as "name",';
32 $sSQL .= 'country_code, errormessage, updated';
33 $sSQL .= ' FROM import_polygon_error';
37 $aWhere[] = "updated > 'now'::timestamp - '".$iDays." day'::interval";
42 $aWhere[] = "errormessage like 'Area reduced%'";
45 $sWhere[] = "class = '".pg_escape_string($sClass)."'";
48 if (!empty($aWhere)) {
49 $sSQL .= ' WHERE '.join(' and ', $aWhere);
52 $sSQL .= ' ORDER BY updated desc LIMIT 1000';
53 $aPolygons = $oDB->getAll($sSQL);
61 if ($sOutputFormat == 'json') {
62 javascript_renderData($aPolygons);