checkModulePresence now raises exception instead of its callers

This commit is contained in:
marc tobias
2019-04-02 18:37:11 +02:00
parent 2a4198f94d
commit 84149f26df
4 changed files with 9 additions and 30 deletions

View File

@@ -229,12 +229,6 @@ class DB
return 'ARRAY['.join(',', $a).']';
}
public function getLastError()
{
// https://secure.php.net/manual/en/pdo.errorinfo.php
return $this->connection->errorInfo();
}
/**
* Check if a table exists in the database. Returns true if it does.
*

View File

@@ -144,9 +144,7 @@ class SetupFunctions
}
// Try accessing the C module, so we know early if something is wrong
if (!checkModulePresence()) {
fail('error loading nominatim.so module');
}
checkModulePresence(); // raises exception on failure
if (!file_exists(CONST_ExtraDataPath.'/country_osm_grid.sql.gz')) {
echo 'Error: you need to download the country_osm_grid first:';
@@ -227,11 +225,9 @@ class SetupFunctions
{
info('Create Functions');
// Try accessing the C module, so we know eif something is wrong
// update.php calls this function
if (!checkModulePresence()) {
fail('error loading nominatim.so module');
}
// Try accessing the C module, so we know early if something is wrong
checkModulePresence(); // raises exception on failure
$this->createSqlFunctions();
}

View File

@@ -17,8 +17,9 @@ function checkInFile($sOSMFile)
function checkModulePresence()
{
// Try accessing the C module, so we know early if something is wrong
// and can simply error out.
// Try accessing the C module, so we know early if something is wrong.
// Raises Nominatim\DatabaseError on failure
$sModulePath = CONST_Database_Module_Path;
$sSQL = "CREATE FUNCTION nominatim_test_import_func(text) RETURNS text AS '";
$sSQL .= $sModulePath . "/nominatim.so', 'transliteration' LANGUAGE c IMMUTABLE STRICT";
@@ -26,15 +27,5 @@ function checkModulePresence()
$oDB = new \Nominatim\DB();
$oDB->connect();
$bResult = true;
try {
$oDB->exec($sSQL);
} catch (\Nominatim\DatabaseError $e) {
echo "\nERROR: Failed to load nominatim module. Reason:\n";
echo $oDB->getLastError()[2] . "\n\n";
$bResult = false;
}
return $bResult;
$oDB->exec($sSQL, null, 'Database server failed to load '.$sModulePath.'/nominatim.so module');
}

View File

@@ -84,9 +84,7 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
}
// Try accessing the C module, so we know early if something is wrong
if (!checkModulePresence()) {
fail('error loading nominatim.so module');
}
checkModulePresence(); // raises exception on failure
if ($aCMDResult['import-data'] || $aCMDResult['all']) {
$bDidSomething = true;