]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/Status.php
Merge pull request #3363 from mtmail/docs-link-correction
[nominatim.git] / lib-php / 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 namespace Nominatim;
12
13 require_once(CONST_TokenizerDir.'/tokenizer.php');
14
15 use Exception;
16
17 class Status
18 {
19     protected $oDB;
20
21     public function __construct(&$oDB)
22     {
23         $this->oDB =& $oDB;
24     }
25
26     public function status()
27     {
28         if (!$this->oDB) {
29             throw new Exception('No database', 700);
30         }
31
32         try {
33             $this->oDB->connect();
34         } catch (\Nominatim\DatabaseError $e) {
35             throw new Exception('Database connection failed', 700);
36         }
37
38         $oTokenizer = new \Nominatim\Tokenizer($this->oDB);
39         $oTokenizer->checkStatus();
40     }
41
42     public function dataDate()
43     {
44         $sSQL = 'SELECT EXTRACT(EPOCH FROM lastimportdate) FROM import_status LIMIT 1';
45         $iDataDateEpoch = $this->oDB->getOne($sSQL);
46
47         if ($iDataDateEpoch === false) {
48             throw new Exception('Import date is not available', 705);
49         }
50
51         return $iDataDateEpoch;
52     }
53
54     public function databaseVersion()
55     {
56         $sSQL = 'SELECT value FROM nominatim_properties WHERE property = \'database_version\'';
57         return $this->oDB->getOne($sSQL);
58     }
59 }