From 992d3faac81baa105c92874a412ebf5389c0ca14 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Wed, 16 Dec 2020 17:20:58 +0100 Subject: [PATCH] switch all utils to initialising dotenv --- lib/lib.php | 4 ---- utils/check_import_finished.php | 2 +- utils/country_languages.php | 2 ++ utils/export.php | 3 +++ utils/query.php | 6 +++++- utils/setup.php | 4 ++-- utils/specialphrases.php | 2 ++ utils/update.php | 5 ++++- utils/warm.php | 11 +++++++---- 9 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/lib.php b/lib/lib.php index 9f266aeb..aeba499b 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -4,10 +4,6 @@ require('Symfony/Component/Dotenv/autoload.php'); function loadSettings($sProjectDir) { - if (!$sProjectDir) { - $sProjectDir = getcwd(); - } - @define('CONST_InstallDir', $sProjectDir); $dotenv = new \Symfony\Component\Dotenv\Dotenv(); diff --git a/utils/check_import_finished.php b/utils/check_import_finished.php index 6623f0c8..e28053be 100755 --- a/utils/check_import_finished.php +++ b/utils/check_import_finished.php @@ -2,7 +2,7 @@ require_once(CONST_LibDir.'/init-cmd.php'); -loadSettings(false); +loadSettings(getcwd()); $term_colors = array( 'green' => "\033[92m", diff --git a/utils/country_languages.php b/utils/country_languages.php index 38b79460..1a7ea616 100644 --- a/utils/country_languages.php +++ b/utils/country_languages.php @@ -11,9 +11,11 @@ $aCMDOptions array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), + array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'), ); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); +loadSettings($aCMDResult['project-dir'] ?? getcwd()); setupHTTPProxy(); if (true) { diff --git a/utils/export.php b/utils/export.php index 3cf9c651..ae18891e 100644 --- a/utils/export.php +++ b/utils/export.php @@ -21,6 +21,7 @@ array('restrict-to-osm-node', '', 0, 1, 1, 1, 'int', 'Export only objects that are children of this OSM node'), array('restrict-to-osm-way', '', 0, 1, 1, 1, 'int', 'Export only objects that are children of this OSM way'), array('restrict-to-osm-relation', '', 0, 1, 1, 1, 'int', 'Export only objects that are children of this OSM relation'), + array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'), "\nAddress ranks: continent, country, state, county, city, suburb, street, path", 'Additional output types: postcode, placeid (placeid for each object)', "\noutput-format must be a semicolon-separated list of address ranks. Multiple ranks", @@ -30,6 +31,8 @@ ); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); + loadSettings($aCMDResult['project-dir'] ?? getcwd()); + $aRankmap = array( 'continent' => 1, 'country' => 4, diff --git a/utils/query.php b/utils/query.php index aa7361ab..088c14dd 100644 --- a/utils/query.php +++ b/utils/query.php @@ -28,10 +28,14 @@ $aCMDOptions array('exclude_place_ids', '', 0, 1, 1, 1, 'string', 'Comma-separated list of place ids to exclude from results'), array('featureType', '', 0, 1, 1, 1, 'string', 'Restrict results to certain features (country, state,city,settlement)'), array('countrycodes', '', 0, 1, 1, 1, 'string', 'Comma-separated list of countries to restrict search to'), - array('viewbox', '', 0, 1, 1, 1, 'string', 'Prefer results in given view box') + array('viewbox', '', 0, 1, 1, 1, 'string', 'Prefer results in given view box'), + + array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'), ); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); +loadSettings($aCMDResult['project-dir'] ?? getcwd()); + $oDB = new Nominatim\DB; $oDB->connect(); diff --git a/utils/setup.php b/utils/setup.php index dfa27cb6..713fe561 100644 --- a/utils/setup.php +++ b/utils/setup.php @@ -44,13 +44,13 @@ $aCMDOptions array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'), array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'), array('setup-website', '', 0, 1, 0, 0, 'bool', 'Used to compile environment variables for the website'), - array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory for this Nominatim installation'), + array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'), ); // $aCMDOptions passed to getCmdOpt by reference getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); -loadSettings($aCMDResult['project-dir'] ?? false); +loadSettings($aCMDResult['project-dir'] ?? getcwd()); setupHTTPProxy(); $bDidSomething = false; diff --git a/utils/specialphrases.php b/utils/specialphrases.php index 58e06222..8e8ea63c 100644 --- a/utils/specialphrases.php +++ b/utils/specialphrases.php @@ -11,9 +11,11 @@ $aCMDOptions array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '), + array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'), ); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); +loadSettings($aCMDResult['project-dir'] ?? getcwd()); setupHTTPProxy(); include(getSettingConfig('PHRASE_CONFIG', 'phrase_settings.php')); diff --git a/utils/update.php b/utils/update.php index 7f9b7a2d..931ca179 100644 --- a/utils/update.php +++ b/utils/update.php @@ -41,11 +41,14 @@ $aCMDOptions array('recompute-word-counts', '', 0, 1, 0, 0, 'bool', 'Compute frequency of full-word search terms'), array('update-address-levels', '', 0, 1, 0, 0, 'bool', 'Reimport address level configuration (EXPERT)'), - array('recompute-importance', '', 0, 1, 0, 0, 'bool', 'Recompute place importances') + array('recompute-importance', '', 0, 1, 0, 0, 'bool', 'Recompute place importances'), + + array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory of the Nominatim installation (default: .)'), ); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true); +loadSettings($aCMDResult['project-dir'] ?? getcwd()); setupHTTPProxy(); if (!isset($aResult['index-instances'])) $aResult['index-instances'] = 1; diff --git a/utils/warm.php b/utils/warm.php index f86e0dd5..0d8260f1 100644 --- a/utils/warm.php +++ b/utils/warm.php @@ -1,6 +1,11 @@ connect(); -- 2.39.5