]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/website/status.php
Merge pull request #2314 from lonvia/fix-status-no-import-date
[nominatim.git] / lib-php / website / status.php
1 <?php
2
3 require_once(CONST_LibDir.'/init-website.php');
4 require_once(CONST_LibDir.'/ParameterParser.php');
5 require_once(CONST_LibDir.'/Status.php');
6
7 $oParams = new Nominatim\ParameterParser();
8 $sOutputFormat = $oParams->getSet('format', array('text', 'json'), 'text');
9
10 $oDB = new Nominatim\DB(CONST_Database_DSN);
11
12 if ($sOutputFormat == 'json') {
13     header('content-type: application/json; charset=UTF-8');
14 }
15
16
17 try {
18     $oStatus = new Nominatim\Status($oDB);
19     $oStatus->status();
20
21     if ($sOutputFormat == 'json') {
22         $epoch = $oStatus->dataDate();
23         $aResponse = array(
24                       'status' => 0,
25                       'message' => 'OK',
26                       'data_updated' => (new DateTime('@'.$epoch))->format(DateTime::RFC3339),
27                       'software_version' => CONST_NominatimVersion
28                      );
29         $sDatabaseVersion = $oStatus->databaseVersion();
30         if ($sDatabaseVersion) {
31             $aResponse['database_version'] = $sDatabaseVersion;
32         }
33         javascript_renderData($aResponse);
34     } else {
35         echo 'OK';
36     }
37 } catch (Exception $oErr) {
38     if ($sOutputFormat == 'json') {
39         $aResponse = array(
40                       'status' => $oErr->getCode(),
41                       'message' => $oErr->getMessage()
42                      );
43         javascript_renderData($aResponse);
44     } else {
45         header('HTTP/1.0 500 Internal Server Error');
46         echo 'ERROR: '.$oErr->getMessage();
47     }
48 }