]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/website/status.php
don't even try heavily penalized searches
[nominatim.git] / lib-php / website / status.php
1 <?php
2 /**
3  * SPDX-License-Identifier: GPL-2.0-only
4  *
5  * This file is part of Nominatim. (https://nominatim.org)
6  *
7  * Copyright (C) 2022 by the Nominatim developer community.
8  * For a full list of authors see the git log.
9  */
10
11 require_once(CONST_LibDir.'/init-website.php');
12 require_once(CONST_LibDir.'/ParameterParser.php');
13 require_once(CONST_LibDir.'/Status.php');
14
15 $oParams = new Nominatim\ParameterParser();
16 $sOutputFormat = $oParams->getSet('format', array('text', 'json'), 'text');
17
18 $oDB = new Nominatim\DB(CONST_Database_DSN);
19
20 if ($sOutputFormat == 'json') {
21     header('content-type: application/json; charset=UTF-8');
22 }
23
24
25 try {
26     $oStatus = new Nominatim\Status($oDB);
27     $oStatus->status();
28
29     if ($sOutputFormat == 'json') {
30         $epoch = $oStatus->dataDate();
31         $aResponse = array(
32                       'status' => 0,
33                       'message' => 'OK',
34                       'data_updated' => (new DateTime('@'.$epoch))->format(DateTime::RFC3339),
35                       'software_version' => CONST_NominatimVersion
36                      );
37         $sDatabaseVersion = $oStatus->databaseVersion();
38         if ($sDatabaseVersion) {
39             $aResponse['database_version'] = $sDatabaseVersion;
40         }
41         javascript_renderData($aResponse);
42     } else {
43         echo 'OK';
44     }
45 } catch (Exception $oErr) {
46     if ($sOutputFormat == 'json') {
47         $aResponse = array(
48                       'status' => $oErr->getCode(),
49                       'message' => $oErr->getMessage()
50                      );
51         javascript_renderData($aResponse);
52     } else {
53         header('HTTP/1.0 500 Internal Server Error');
54         echo 'ERROR: '.$oErr->getMessage();
55     }
56 }