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

View File

@@ -17,8 +17,9 @@ function checkInFile($sOSMFile)
function checkModulePresence() function checkModulePresence()
{ {
// Try accessing the C module, so we know early if something is wrong // Try accessing the C module, so we know early if something is wrong.
// and can simply error out. // Raises Nominatim\DatabaseError on failure
$sModulePath = CONST_Database_Module_Path; $sModulePath = CONST_Database_Module_Path;
$sSQL = "CREATE FUNCTION nominatim_test_import_func(text) RETURNS text AS '"; $sSQL = "CREATE FUNCTION nominatim_test_import_func(text) RETURNS text AS '";
$sSQL .= $sModulePath . "/nominatim.so', 'transliteration' LANGUAGE c IMMUTABLE STRICT"; $sSQL .= $sModulePath . "/nominatim.so', 'transliteration' LANGUAGE c IMMUTABLE STRICT";
@@ -26,15 +27,5 @@ function checkModulePresence()
$oDB = new \Nominatim\DB(); $oDB = new \Nominatim\DB();
$oDB->connect(); $oDB->connect();
$oDB->exec($sSQL, null, 'Database server failed to load '.$sModulePath.'/nominatim.so module');
$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;
} }

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