From 84149f26dfc97a5a78914f8d355468da2ea88e7d Mon Sep 17 00:00:00 2001 From: marc tobias Date: Tue, 2 Apr 2019 18:37:11 +0200 Subject: [PATCH] checkModulePresence now raises exception instead of its callers --- lib/DB.php | 6 ------ lib/setup/SetupClass.php | 12 ++++-------- lib/setup_functions.php | 17 ++++------------- utils/setup.php | 4 +--- 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/lib/DB.php b/lib/DB.php index 033e23f7..17dfe67d 100644 --- a/lib/DB.php +++ b/lib/DB.php @@ -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. * diff --git a/lib/setup/SetupClass.php b/lib/setup/SetupClass.php index 9fcec2f0..c14190c3 100755 --- a/lib/setup/SetupClass.php +++ b/lib/setup/SetupClass.php @@ -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(); } diff --git a/lib/setup_functions.php b/lib/setup_functions.php index 89736ae0..43f30a09 100755 --- a/lib/setup_functions.php +++ b/lib/setup_functions.php @@ -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'); } diff --git a/utils/setup.php b/utils/setup.php index 66b71920..8ad96a95 100644 --- a/utils/setup.php +++ b/utils/setup.php @@ -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; -- 2.39.5