2018-05-05 00:37:48 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Nominatim;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
class Status
|
|
|
|
{
|
|
|
|
protected $oDB;
|
|
|
|
|
|
|
|
public function __construct(&$oDB)
|
|
|
|
{
|
|
|
|
$this->oDB =& $oDB;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function status()
|
|
|
|
{
|
2019-02-24 18:14:36 +03:00
|
|
|
if (!$this->oDB) {
|
2018-05-05 00:37:48 +03:00
|
|
|
throw new Exception('No database', 700);
|
|
|
|
}
|
|
|
|
|
2019-02-24 18:14:36 +03:00
|
|
|
try {
|
|
|
|
$this->oDB->connect();
|
|
|
|
} catch (\Nominatim\DatabaseError $e) {
|
|
|
|
throw new Exception('Database connection failed', 700);
|
|
|
|
}
|
|
|
|
|
2018-05-05 00:37:48 +03:00
|
|
|
$sStandardWord = $this->oDB->getOne("SELECT make_standard_name('a')");
|
2019-02-24 18:14:36 +03:00
|
|
|
if ($sStandardWord === false) {
|
2018-05-05 00:37:48 +03:00
|
|
|
throw new Exception('Module failed', 701);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sStandardWord != 'a') {
|
|
|
|
throw new Exception('Module call failed', 702);
|
|
|
|
}
|
|
|
|
|
|
|
|
$sSQL = 'SELECT word_id, word_token, word, class, type, country_code, ';
|
|
|
|
$sSQL .= "operator, search_name_count FROM word WHERE word_token IN (' a')";
|
|
|
|
$iWordID = $this->oDB->getOne($sSQL);
|
2019-02-24 18:14:36 +03:00
|
|
|
if ($iWordID === false) {
|
2018-05-05 00:37:48 +03:00
|
|
|
throw new Exception('Query failed', 703);
|
|
|
|
}
|
|
|
|
if (!$iWordID) {
|
|
|
|
throw new Exception('No value', 704);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataDate()
|
|
|
|
{
|
|
|
|
$sSQL = 'SELECT EXTRACT(EPOCH FROM lastimportdate) FROM import_status LIMIT 1';
|
|
|
|
$iDataDateEpoch = $this->oDB->getOne($sSQL);
|
|
|
|
|
2019-02-24 18:14:36 +03:00
|
|
|
if ($iDataDateEpoch === false) {
|
2018-05-05 00:37:48 +03:00
|
|
|
throw Exception('Data date query failed '.$iDataDateEpoch->getMessage(), 705);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $iDataDateEpoch;
|
|
|
|
}
|
2021-03-02 00:17:16 +03:00
|
|
|
|
|
|
|
public function databaseVersion()
|
|
|
|
{
|
|
|
|
$sSQL = 'SELECT value FROM nominatim_properties WHERE property = \'database_version\'';
|
|
|
|
return $this->oDB->getOne($sSQL);
|
|
|
|
}
|
2018-05-05 00:37:48 +03:00
|
|
|
}
|