mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
Guard against network failures in getDatabaseDate()
When updating use the date from the diff file instead as we are guaranteed to get this if the file has been successfully loaded.
This commit is contained in:
@@ -38,8 +38,13 @@ function getDatabaseDate(&$oDB)
|
|||||||
// Find the newest node in the DB
|
// Find the newest node in the DB
|
||||||
$iLastOSMID = $oDB->getOne("select max(osm_id) from place where osm_type = 'N'");
|
$iLastOSMID = $oDB->getOne("select max(osm_id) from place where osm_type = 'N'");
|
||||||
// Lookup the timestamp that node was created
|
// Lookup the timestamp that node was created
|
||||||
$sLastNodeURL = 'http://www.openstreetmap.org/api/0.6/node/'.$iLastOSMID."/1";
|
$sLastNodeURL = 'https://www.openstreetmap.org/api/0.6/node/'.$iLastOSMID."/1";
|
||||||
$sLastNodeXML = file_get_contents($sLastNodeURL);
|
$sLastNodeXML = file_get_contents($sLastNodeURL);
|
||||||
|
|
||||||
|
if ($sLastNodeXML === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
preg_match('#timestamp="(([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z)"#', $sLastNodeXML, $aLastNodeDate);
|
preg_match('#timestamp="(([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z)"#', $sLastNodeXML, $aLastNodeDate);
|
||||||
|
|
||||||
return $aLastNodeDate[1];
|
return $aLastNodeDate[1];
|
||||||
|
|||||||
33
utils/osm_file_date.py
Executable file
33
utils/osm_file_date.py
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import osmium
|
||||||
|
import sys
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
|
class Datecounter(osmium.SimpleHandler):
|
||||||
|
|
||||||
|
filedate = None
|
||||||
|
|
||||||
|
def date(self, o):
|
||||||
|
ts = o.timestamp
|
||||||
|
if self.filedate is None or ts > self.filedate:
|
||||||
|
self.filedate = ts
|
||||||
|
|
||||||
|
node = date
|
||||||
|
way = date
|
||||||
|
relation = date
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Usage: python osm_file_date.py <osmfile>")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
h = Datecounter()
|
||||||
|
|
||||||
|
h.apply_file(sys.argv[1])
|
||||||
|
|
||||||
|
print(h.filedate)
|
||||||
|
|
||||||
|
|
||||||
@@ -407,9 +407,13 @@ if ($aCMDResult['load-data'] || $aCMDResult['all']) {
|
|||||||
|
|
||||||
$sDatabaseDate = getDatabaseDate($oDB);
|
$sDatabaseDate = getDatabaseDate($oDB);
|
||||||
pg_query($oDB->connection, 'TRUNCATE import_status');
|
pg_query($oDB->connection, 'TRUNCATE import_status');
|
||||||
$sSQL = "INSERT INTO import_status (lastimportdate) VALUES('".$sDatabaseDate."')";
|
if ($sDatabaseDate === false) {
|
||||||
pg_query($oDB->connection, $sSQL);
|
echo "WARNING: could not determine database date.\n";
|
||||||
echo "Latest data imported from $sDatabaseDate.\n";
|
} else {
|
||||||
|
$sSQL = "INSERT INTO import_status (lastimportdate) VALUES('".$sDatabaseDate."')";
|
||||||
|
pg_query($oDB->connection, $sSQL);
|
||||||
|
echo "Latest data imported from $sDatabaseDate.\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($aCMDResult['import-tiger-data']) {
|
if ($aCMDResult['import-tiger-data']) {
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ if ($aResult['init-updates']) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sDatabaseDate = getDatabaseDate($oDB);
|
$sDatabaseDate = getDatabaseDate($oDB);
|
||||||
|
if ($sDatabaseDate === false) {
|
||||||
|
fail("Cannot determine date of database.");
|
||||||
|
}
|
||||||
$sWindBack = strftime('%Y-%m-%dT%H:%M:%SZ',
|
$sWindBack = strftime('%Y-%m-%dT%H:%M:%SZ',
|
||||||
strtotime($sDatabaseDate) - (3*60*60));
|
strtotime($sDatabaseDate) - (3*60*60));
|
||||||
|
|
||||||
@@ -293,7 +296,14 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) {
|
|||||||
|
|
||||||
// write the update logs
|
// write the update logs
|
||||||
$iFileSize = filesize($sImportFile);
|
$iFileSize = filesize($sImportFile);
|
||||||
$sBatchEnd = getDatabaseDate($oDB);
|
// get the newest object from the diff file
|
||||||
|
$sBatchEnd = 0;
|
||||||
|
$iRet = 0;
|
||||||
|
exec(CONST_BasePath.'/utils/osm_file_date.py '.$sImportFile, $sBatchEnd, $iRet);
|
||||||
|
if ($iRet != 0) {
|
||||||
|
fail('Error getting date from diff file.');
|
||||||
|
}
|
||||||
|
$sBatchEnd = $sBatchEnd[0];
|
||||||
$sSQL = "INSERT INTO import_osmosis_log (batchend, batchseq, batchsize, starttime, endtime, event) values ('$sBatchEnd',$iEndSequence,$iFileSize,'".date('Y-m-d H:i:s', $fCMDStartTime)."','".date('Y-m-d H:i:s')."','import')";
|
$sSQL = "INSERT INTO import_osmosis_log (batchend, batchseq, batchsize, starttime, endtime, event) values ('$sBatchEnd',$iEndSequence,$iFileSize,'".date('Y-m-d H:i:s', $fCMDStartTime)."','".date('Y-m-d H:i:s')."','import')";
|
||||||
var_Dump($sSQL);
|
var_Dump($sSQL);
|
||||||
chksql($oDB->query($sSQL));
|
chksql($oDB->query($sSQL));
|
||||||
|
|||||||
Reference in New Issue
Block a user