]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/website/status.php
nominatim -h was priting wrong text for lookup and details
[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 } catch (Exception $oErr) {
21     if ($sOutputFormat == 'json') {
22         $aResponse = array(
23                       'status' => $oErr->getCode(),
24                       'message' => $oErr->getMessage()
25                      );
26         javascript_renderData($aResponse);
27     } else {
28         header('HTTP/1.0 500 Internal Server Error');
29         echo 'ERROR: '.$oErr->getMessage();
30     }
31     exit;
32 }
33
34
35 if ($sOutputFormat == 'json') {
36     $epoch = $oStatus->dataDate();
37     $aResponse = array(
38                   'status' => 0,
39                   'message' => 'OK',
40                   'data_updated' => (new DateTime('@'.$epoch))->format(DateTime::RFC3339),
41                   'software_version' => CONST_NominatimVersion
42                  );
43     $sDatabaseVersion = $oStatus->databaseVersion();
44     if ($sDatabaseVersion) {
45         $aResponse['database_version'] = $sDatabaseVersion;
46     }
47     javascript_renderData($aResponse);
48 } else {
49     echo 'OK';
50 }
51
52 exit;