From: Sarah Hoffmann Date: Mon, 21 Dec 2020 10:33:38 +0000 (+0100) Subject: Merge pull request #2115 from lonvia/use-dotenv X-Git-Tag: v3.7.0~66 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/301fd7f7e8d97755849e26427c12eed070f21b5f?hp=aeeee0d5dab4586d1346db91a76427cc81a95945 Merge pull request #2115 from lonvia/use-dotenv Switch configuration to dotenv --- diff --git a/.github/actions/build-nominatim/action.yml b/.github/actions/build-nominatim/action.yml index 9bb66df3..555d7ee2 100644 --- a/.github/actions/build-nominatim/action.yml +++ b/.github/actions/build-nominatim/action.yml @@ -5,7 +5,8 @@ runs: steps: - name: Install prerequisits - run: sudo apt-get install -y -qq libboost-system-dev libboost-filesystem-dev libexpat1-dev zlib1g-dev libbz2-dev libpq-dev libproj-dev python3-psycopg2 python3-pyosmium + run: | + sudo apt-get install -y -qq libboost-system-dev libboost-filesystem-dev libexpat1-dev zlib1g-dev libbz2-dev libpq-dev libproj-dev python3-psycopg2 python3-pyosmium php-symfony-dotenv shell: bash - name: Configure diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 1f64df27..cbb7aa6c 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -35,8 +35,8 @@ jobs: - uses: actions/cache@v2 with: path: | - data/country_osm_grid.sql.gz - monaco-latest.osm.pbf + {{ github.workspace }}/data/country_osm_grid.sql.gz + {{ github.workspace }}/monaco-latest.osm.pbf key: nominatim-data-${{ steps.get-date.outputs.date }} - uses: ./.github/actions/setup-postgresql @@ -78,8 +78,8 @@ jobs: - uses: actions/cache@v2 with: path: | - data/country_osm_grid.sql.gz - monaco-latest.osm.pbf + {{ github.workspace }}/data/country_osm_grid.sql.gz + {{ github.workspace }}/monaco-latest.osm.pbf key: nominatim-data-${{ steps.get-date.outputs.date }} - uses: ./.github/actions/setup-postgresql @@ -90,8 +90,7 @@ jobs: - name: Create configuration run: | - echo ' settings/local.php - echo " @define('CONST_Pyosmium_Binary', '/usr/lib/python3-pyosmium/pyosmium-get-changes');" >> settings/local.php + echo "NOMINATIM_PYOSMIUM_BINARY=/usr/lib/python3-pyosmium/pyosmium-get-changes" >> .env working-directory: build - name: Download import data diff --git a/CMakeLists.txt b/CMakeLists.txt index 59d9e3a6..b4f4ddb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,51 +96,28 @@ endif() if (BUILD_IMPORTER) set(CUSTOMSCRIPTS - utils/check_import_finished.php - utils/country_languages.php - utils/importWikipedia.php - utils/export.php - utils/query.php - utils/setup.php - utils/specialphrases.php - utils/update.php - utils/warm.php + check_import_finished.php + country_languages.php + importWikipedia.php + export.php + query.php + setup.php + specialphrases.php + update.php + warm.php ) foreach (script_source ${CUSTOMSCRIPTS}) configure_file(${PROJECT_SOURCE_DIR}/cmake/script.tmpl - ${PROJECT_BINARY_DIR}/${script_source}) + ${PROJECT_BINARY_DIR}/utils/${script_source}) endforeach() endif() #----------------------------------------------------------------------------- -# webserver scripts (API only) +# Targets for running a development webserver from the build directory. #----------------------------------------------------------------------------- if (BUILD_API) - set(WEBSITESCRIPTS - website/deletable.php - website/details.php - website/lookup.php - website/polygons.php - website/reverse.php - website/search.php - website/status.php - ) - - foreach (script_source ${WEBSITESCRIPTS}) - configure_file(${PROJECT_SOURCE_DIR}/cmake/website.tmpl - ${PROJECT_BINARY_DIR}/${script_source}) - endforeach() - - set(WEBPATHS css images js) - - foreach (wp ${WEBPATHS}) - execute_process( - COMMAND ln -sf ${PROJECT_SOURCE_DIR}/website/${wp} ${PROJECT_BINARY_DIR}/website/ - ) - endforeach() - add_custom_target(serve php -S 127.0.0.1:8088 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/website @@ -152,13 +129,6 @@ if (BUILD_API) ) endif() -#----------------------------------------------------------------------------- -# default settings -#----------------------------------------------------------------------------- - -configure_file(${PROJECT_SOURCE_DIR}/settings/defaults.php - ${PROJECT_BINARY_DIR}/settings/settings.php) - #----------------------------------------------------------------------------- # Tests #----------------------------------------------------------------------------- diff --git a/cmake/script.tmpl b/cmake/script.tmpl index 8146ca8b..4d9224b0 100755 --- a/cmake/script.tmpl +++ b/cmake/script.tmpl @@ -1,4 +1,7 @@ #!@PHP_BIN@ -Cq '); +NOMINATIM_DATABASE_MODULE_PATH="" ``` -Now change the `CONST_Database_DSN` to point to your remote server and continue +Now change the `NOMINATIM_DATABASE_DSN` to point to your remote server and continue to follow the [standard instructions for importing](/admin/Import). diff --git a/docs/admin/Faq.md b/docs/admin/Faq.md index bca6b49d..6203959d 100644 --- a/docs/admin/Faq.md +++ b/docs/admin/Faq.md @@ -211,11 +211,3 @@ for more information. ### Can I import negative OSM ids into Nominatim? See [this question of Stackoverflow](https://help.openstreetmap.org/questions/64662/nominatim-flatnode-with-negative-id). - -### Missing XML or text declaration - -The website might show: `XML Parsing Error: XML or text declaration not at start of entity Location.` - -Make sure there are no spaces at the beginning of your `settings/local.php` file. - - diff --git a/docs/admin/Import.md b/docs/admin/Import.md index 792070e4..41942d6f 100644 --- a/docs/admin/Import.md +++ b/docs/admin/Import.md @@ -5,18 +5,17 @@ from an OSM planet file and how to keep the database up to date. It is assumed that you have already successfully installed the Nominatim software itself, if not return to the [installation page](Installation.md). -## Configuration setup in settings/local.php +## Configuration setup in `.env` -The Nominatim server can be customized via the file `settings/local.php` -in the build directory. Note that this is a PHP file, so it must always -start like this: - - sDSN = $sDSN; + $this->sDSN = $sDSN ?? getSetting('DATABASE_DSN'); } public function connect($bNew = false, $bPersistent = true) diff --git a/lib/Geocode.php b/lib/Geocode.php index ed02848e..12f9da37 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -2,12 +2,12 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/PlaceLookup.php'); -require_once(CONST_BasePath.'/lib/Phrase.php'); -require_once(CONST_BasePath.'/lib/ReverseGeocode.php'); -require_once(CONST_BasePath.'/lib/SearchDescription.php'); -require_once(CONST_BasePath.'/lib/SearchContext.php'); -require_once(CONST_BasePath.'/lib/TokenList.php'); +require_once(CONST_LibDir.'/PlaceLookup.php'); +require_once(CONST_LibDir.'/Phrase.php'); +require_once(CONST_LibDir.'/ReverseGeocode.php'); +require_once(CONST_LibDir.'/SearchDescription.php'); +require_once(CONST_LibDir.'/SearchContext.php'); +require_once(CONST_LibDir.'/TokenList.php'); class Geocode { @@ -18,7 +18,7 @@ class Geocode protected $aLangPrefOrder = array(); protected $aExcludePlaceIDs = array(); - protected $bReverseInPlan = false; + protected $bReverseInPlan = true; protected $iLimit = 20; protected $iFinalLimit = 10; diff --git a/lib/PlaceLookup.php b/lib/PlaceLookup.php index a2f39ea3..6d7b6be1 100644 --- a/lib/PlaceLookup.php +++ b/lib/PlaceLookup.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/AddressDetails.php'); -require_once(CONST_BasePath.'/lib/Result.php'); +require_once(CONST_LibDir.'/AddressDetails.php'); +require_once(CONST_LibDir.'/Result.php'); class PlaceLookup { @@ -486,65 +486,63 @@ class PlaceLookup $aOutlineResult = array(); if (!$iPlaceID) return $aOutlineResult; - if (CONST_Search_AreaPolygons) { - // Get the bounding box and outline polygon - $sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,'; - if ($fLonReverse != null && $fLatReverse != null) { - $sSQL .= ' ST_Y(closest_point) as centrelat,'; - $sSQL .= ' ST_X(closest_point) as centrelon,'; - } else { - $sSQL .= ' ST_Y(centroid) as centrelat, ST_X(centroid) as centrelon,'; - } - $sSQL .= ' ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,'; - $sSQL .= ' ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon'; - if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson'; - if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml'; - if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg'; - if ($this->bIncludePolygonAsText) $sSQL .= ',ST_AsText(geometry) as astext'; - if ($fLonReverse != null && $fLatReverse != null) { - $sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN '; - $sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))'; - $sFrom .=' ELSE centroid END AS closest_point'; - $sFrom .= ' from placex where place_id = '.$iPlaceID.') as plx'; - } else { - $sFrom = ' from placex where place_id = '.$iPlaceID; - } - if ($this->fPolygonSimplificationThreshold > 0) { - $sSQL .= ' from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry'.$sFrom.') as plx'; - } else { - $sSQL .= $sFrom; - } - - $aPointPolygon = $this->oDB->getRow($sSQL, null, 'Could not get outline'); + // Get the bounding box and outline polygon + $sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,'; + if ($fLonReverse != null && $fLatReverse != null) { + $sSQL .= ' ST_Y(closest_point) as centrelat,'; + $sSQL .= ' ST_X(closest_point) as centrelon,'; + } else { + $sSQL .= ' ST_Y(centroid) as centrelat, ST_X(centroid) as centrelon,'; + } + $sSQL .= ' ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,'; + $sSQL .= ' ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon'; + if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson'; + if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml'; + if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg'; + if ($this->bIncludePolygonAsText) $sSQL .= ',ST_AsText(geometry) as astext'; + if ($fLonReverse != null && $fLatReverse != null) { + $sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN '; + $sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))'; + $sFrom .=' ELSE centroid END AS closest_point'; + $sFrom .= ' from placex where place_id = '.$iPlaceID.') as plx'; + } else { + $sFrom = ' from placex where place_id = '.$iPlaceID; + } + if ($this->fPolygonSimplificationThreshold > 0) { + $sSQL .= ' from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry'.$sFrom.') as plx'; + } else { + $sSQL .= $sFrom; + } - if ($aPointPolygon && $aPointPolygon['place_id']) { - if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) { - $aOutlineResult['lat'] = $aPointPolygon['centrelat']; - $aOutlineResult['lon'] = $aPointPolygon['centrelon']; - } + $aPointPolygon = $this->oDB->getRow($sSQL, null, 'Could not get outline'); - if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson']; - if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml']; - if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg']; - if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext']; + if ($aPointPolygon && $aPointPolygon['place_id']) { + if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) { + $aOutlineResult['lat'] = $aPointPolygon['centrelat']; + $aOutlineResult['lon'] = $aPointPolygon['centrelon']; + } - if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) { - $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius; - $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius; - } + if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson']; + if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml']; + if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg']; + if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext']; - if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) { - $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius; - $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius; - } + if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) { + $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius; + $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius; + } - $aOutlineResult['aBoundingBox'] = array( - (string)$aPointPolygon['minlat'], - (string)$aPointPolygon['maxlat'], - (string)$aPointPolygon['minlon'], - (string)$aPointPolygon['maxlon'] - ); + if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) { + $aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius; + $aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius; } + + $aOutlineResult['aBoundingBox'] = array( + (string)$aPointPolygon['minlat'], + (string)$aPointPolygon['maxlat'], + (string)$aPointPolygon['minlon'], + (string)$aPointPolygon['maxlon'] + ); } // as a fallback we generate a bounding box without knowing the size of the geometry diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index 032f442e..b420e5dd 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/Result.php'); +require_once(CONST_LibDir.'/Result.php'); class ReverseGeocode { diff --git a/lib/SearchContext.php b/lib/SearchContext.php index c2898d27..8316a012 100644 --- a/lib/SearchContext.php +++ b/lib/SearchContext.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/lib.php'); +require_once(CONST_LibDir.'/lib.php'); /** diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index 15c6bf23..f0106063 100644 --- a/lib/SearchDescription.php +++ b/lib/SearchDescription.php @@ -2,9 +2,9 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/SpecialSearchOperator.php'); -require_once(CONST_BasePath.'/lib/SearchContext.php'); -require_once(CONST_BasePath.'/lib/Result.php'); +require_once(CONST_LibDir.'/SpecialSearchOperator.php'); +require_once(CONST_LibDir.'/SearchContext.php'); +require_once(CONST_LibDir.'/Result.php'); /** * Description of a single interpretation of a search query. diff --git a/lib/TokenList.php b/lib/TokenList.php index 1b6a1dcf..a419da6a 100644 --- a/lib/TokenList.php +++ b/lib/TokenList.php @@ -2,12 +2,12 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/TokenCountry.php'); -require_once(CONST_BasePath.'/lib/TokenHousenumber.php'); -require_once(CONST_BasePath.'/lib/TokenPostcode.php'); -require_once(CONST_BasePath.'/lib/TokenSpecialTerm.php'); -require_once(CONST_BasePath.'/lib/TokenWord.php'); -require_once(CONST_BasePath.'/lib/SpecialSearchOperator.php'); +require_once(CONST_LibDir.'/TokenCountry.php'); +require_once(CONST_LibDir.'/TokenHousenumber.php'); +require_once(CONST_LibDir.'/TokenPostcode.php'); +require_once(CONST_LibDir.'/TokenSpecialTerm.php'); +require_once(CONST_LibDir.'/TokenWord.php'); +require_once(CONST_LibDir.'/SpecialSearchOperator.php'); /** * Saves information about the tokens that appear in a search query. diff --git a/lib/TokenSpecialTerm.php b/lib/TokenSpecialTerm.php index 64e4b3d4..b2c312ec 100644 --- a/lib/TokenSpecialTerm.php +++ b/lib/TokenSpecialTerm.php @@ -2,7 +2,7 @@ namespace Nominatim\Token; -require_once(CONST_BasePath.'/lib/SpecialSearchOperator.php'); +require_once(CONST_LibDir.'/SpecialSearchOperator.php'); /** * A word token describing a place type. diff --git a/lib/cmd.php b/lib/cmd.php index 72b66608..5a12f99a 100644 --- a/lib/cmd.php +++ b/lib/cmd.php @@ -1,6 +1,6 @@ $sProxy, + 'request_fulluri' => true, + 'header' => $aHeaders + ); + + $aContext = array('http' => $aProxyHeader, 'https' => $aProxyHeader); + stream_context_set_default($aContext); +} diff --git a/lib/init-cmd.php b/lib/init-cmd.php index 50c709c9..b7645cd5 100644 --- a/lib/init-cmd.php +++ b/lib/init-cmd.php @@ -3,26 +3,3 @@ require_once('init.php'); require_once('cmd.php'); require_once('DebugNone.php'); - -// handle http proxy when using file_get_contents -if (CONST_HTTP_Proxy) { - $proxy = 'tcp://' . CONST_HTTP_Proxy_Host . ':' . CONST_HTTP_Proxy_Port; - $aHeaders = array(); - if (CONST_HTTP_Proxy_Login != null && CONST_HTTP_Proxy_Login != '' && CONST_HTTP_Proxy_Password != null && CONST_HTTP_Proxy_Password != '') { - $auth = base64_encode(CONST_HTTP_Proxy_Login . ':' . CONST_HTTP_Proxy_Password); - $aHeaders = array("Proxy-Authorization: Basic $auth"); - } - $aContext = array( - 'http' => array( - 'proxy' => $proxy, - 'request_fulluri' => true, - 'header' => $aHeaders - ), - 'https' => array( - 'proxy' => $proxy, - 'request_fulluri' => true, - 'header' => $aHeaders - ) - ); - stream_context_set_default($aContext); -} diff --git a/lib/init-website.php b/lib/init-website.php index 302a9478..f2d52980 100644 --- a/lib/init-website.php +++ b/lib/init-website.php @@ -20,7 +20,7 @@ function exception_handler_json($exception) { http_response_code($exception->getCode()); header('Content-type: application/json; charset=utf-8'); - include(CONST_BasePath.'/lib/template/error-json.php'); + include(CONST_LibDir.'/template/error-json.php'); exit(); } @@ -29,7 +29,7 @@ function exception_handler_xml($exception) http_response_code($exception->getCode()); header('Content-type: text/xml; charset=utf-8'); echo ''."\n"; - include(CONST_BasePath.'/lib/template/error-xml.php'); + include(CONST_LibDir.'/template/error-xml.php'); exit(); } diff --git a/lib/init.php b/lib/init.php index 082d1bf5..cc50aaf3 100644 --- a/lib/init.php +++ b/lib/init.php @@ -1,4 +1,4 @@ load(CONST_DataDir.'/settings/env.defaults'); + + if (file_exists($sProjectDir.'/.env')) { + $dotenv->load($sProjectDir.'/.env'); + } +} + +function getSetting($sConfName, $sDefault = null) +{ + $sValue = $_SERVER['NOMINATIM_'.$sConfName]; + + if ($sDefault !== null && !$sValue) { + return $sDefault; + } + + return $sValue; +} + +function getSettingBool($sConfName) +{ + $sVal = strtolower(getSetting($sConfName)); + + return strcmp($sVal, 'yes') == 0 + || strcmp($sVal, 'true') == 0 + || strcmp($sVal, '1') == 0; +} + +function getSettingConfig($sConfName, $sSystemConfig) +{ + $sValue = $_ENV['NOMINATIM_'.$sConfName]; + + if (!$sValue) { + return CONST_DataDir.'/settings/'.$sSystemConfig; + } + + return $sValue; +} + function fail($sError, $sUserError = false) { if (!$sUserError) $sUserError = $sError; @@ -89,6 +134,24 @@ function addQuotes($s) return "'".$s."'"; } +function fwriteConstDef($rFile, $sConstName, $value) +{ + $sEscapedValue; + + if (is_bool($value)) { + $sEscapedValue = $value ? 'true' : 'false'; + } elseif (is_numeric($value)) { + $sEscapedValue = strval($value); + } elseif (!$value) { + $sEscapedValue = 'false'; + } else { + $sEscapedValue = addQuotes(str_replace("'", "\\'", (string)$value)); + } + + fwrite($rFile, "@define('CONST_$sConstName', $sEscapedValue);\n"); +} + + function parseLatLon($sQuery) { $sFound = null; diff --git a/lib/setup/SetupClass.php b/lib/setup/SetupClass.php index f16c9e60..d3c4c4eb 100755 --- a/lib/setup/SetupClass.php +++ b/lib/setup/SetupClass.php @@ -2,8 +2,8 @@ namespace Nominatim\Setup; -require_once(CONST_BasePath.'/lib/setup/AddressLevelParser.php'); -require_once(CONST_BasePath.'/lib/Shell.php'); +require_once(CONST_LibDir.'/setup/AddressLevelParser.php'); +require_once(CONST_LibDir.'/Shell.php'); class SetupFunctions { @@ -34,7 +34,7 @@ class SetupFunctions if (isset($aCMDResult['osm2pgsql-cache'])) { $this->iCacheMemory = $aCMDResult['osm2pgsql-cache']; - } elseif (!is_null(CONST_Osm2pgsql_Flatnode_File)) { + } elseif (getSetting('FLATNODE_FILE')) { // When flatnode files are enabled then disable cache per default. $this->iCacheMemory = 0; } else { @@ -42,11 +42,11 @@ class SetupFunctions $this->iCacheMemory = getCacheMemoryMB(); } - $this->sModulePath = CONST_Database_Module_Path; + $this->sModulePath = getSetting('DATABASE_MODULE_PATH', CONST_InstallDir.'/module'); info('module path: ' . $this->sModulePath); // parse database string - $this->aDSNInfo = \Nominatim\DB::parseDSN(CONST_Database_DSN); + $this->aDSNInfo = \Nominatim\DB::parseDSN(getSetting('DATABASE_DSN')); if (!isset($this->aDSNInfo['port'])) { $this->aDSNInfo['port'] = 5432; } @@ -86,7 +86,7 @@ class SetupFunctions $oDB = new \Nominatim\DB; if ($oDB->checkConnection()) { - fail('database already exists ('.CONST_Database_DSN.')'); + fail('database already exists ('.getSetting('DATABASE_DSN').')'); } $oCmd = (new \Nominatim\Shell('createdb')) @@ -130,34 +130,35 @@ class SetupFunctions exit(1); } - $i = $this->db()->getOne("select count(*) from pg_user where usename = '".CONST_Database_Web_User."'"); + $sPgUser = getSetting('DATABASE_WEBUSER'); + $i = $this->db()->getOne("select count(*) from pg_user where usename = '$sPgUser'"); if ($i == 0) { - echo "\nERROR: Web user '".CONST_Database_Web_User."' does not exist. Create it with:\n"; - echo "\n createuser ".CONST_Database_Web_User."\n\n"; + echo "\nERROR: Web user '".$sPgUser."' does not exist. Create it with:\n"; + echo "\n createuser ".$sPgUser."\n\n"; exit(1); } // Try accessing the C module, so we know early if something is wrong - checkModulePresence(); // raises exception on failure + $this->checkModulePresence(); // raises exception on failure - if (!file_exists(CONST_ExtraDataPath.'/country_osm_grid.sql.gz')) { + if (!file_exists(CONST_DataDir.'/data/country_osm_grid.sql.gz')) { echo 'Error: you need to download the country_osm_grid first:'; - echo "\n wget -O ".CONST_ExtraDataPath."/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz\n"; + echo "\n wget -O ".CONST_DataDir."/data/country_osm_grid.sql.gz https://www.nominatim.org/data/country_grid.sql.gz\n"; exit(1); } - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_name.sql'); - $this->pgsqlRunScriptFile(CONST_ExtraDataPath.'/country_osm_grid.sql.gz'); - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_table.sql'); - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/us_postcode_table.sql'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/country_name.sql'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/country_osm_grid.sql.gz'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/gb_postcode_table.sql'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/us_postcode_table.sql'); - $sPostcodeFilename = CONST_BasePath.'/data/gb_postcode_data.sql.gz'; + $sPostcodeFilename = CONST_DataDir.'/data/gb_postcode_data.sql.gz'; if (file_exists($sPostcodeFilename)) { $this->pgsqlRunScriptFile($sPostcodeFilename); } else { warn('optional external GB postcode table file ('.$sPostcodeFilename.') not found. Skipping.'); } - $sPostcodeFilename = CONST_BasePath.'/data/us_postcode_data.sql.gz'; + $sPostcodeFilename = CONST_DataDir.'/data/us_postcode_data.sql.gz'; if (file_exists($sPostcodeFilename)) { $this->pgsqlRunScriptFile($sPostcodeFilename); } else { @@ -173,29 +174,29 @@ class SetupFunctions { info('Import data'); - if (!file_exists(CONST_Osm2pgsql_Binary)) { - echo "Check CONST_Osm2pgsql_Binary in your local settings file.\n"; + if (!file_exists(getOsm2pgsqlBinary())) { + echo "Check NOMINATIM_OSM2PGSQL_BINARY in your local .env file.\n"; echo "Normally you should not need to set this manually.\n"; - fail("osm2pgsql not found in '".CONST_Osm2pgsql_Binary."'"); + fail("osm2pgsql not found in '".getOsm2pgsqlBinary()."'"); } - $oCmd = new \Nominatim\Shell(CONST_Osm2pgsql_Binary); - $oCmd->addParams('--style', CONST_Import_Style); + $oCmd = new \Nominatim\Shell(getOsm2pgsqlBinary()); + $oCmd->addParams('--style', getImportStyle()); - if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) { - $oCmd->addParams('--flat-nodes', CONST_Osm2pgsql_Flatnode_File); + if (getSetting('FLATNODE_FILE')) { + $oCmd->addParams('--flat-nodes', getSetting('FLATNODE_FILE')); } - if (CONST_Tablespace_Osm2pgsql_Data) { - $oCmd->addParams('--tablespace-slim-data', CONST_Tablespace_Osm2pgsql_Data); + if (getSetting('TABLESPACE_OSM_DATA')) { + $oCmd->addParams('--tablespace-slim-data', getSetting('TABLESPACE_OSM_DATA')); } - if (CONST_Tablespace_Osm2pgsql_Index) { - $oCmd->addParams('--tablespace-slim-index', CONST_Tablespace_Osm2pgsql_Index); + if (getSetting('TABLESPACE_OSM_INDEX')) { + $oCmd->addParams('--tablespace-slim-index', getSetting('TABLESPACE_OSM_INDEX')); } - if (CONST_Tablespace_Place_Data) { - $oCmd->addParams('--tablespace-main-data', CONST_Tablespace_Place_Data); + if (getSetting('TABLESPACE_PLACE_DATA')) { + $oCmd->addParams('--tablespace-main-data', getSetting('TABLESPACE_PLACE_DATA')); } - if (CONST_Tablespace_Place_Index) { - $oCmd->addParams('--tablespace-main-index', CONST_Tablespace_Place_Index); + if (getSetting('TABLESPACE_PLACE_INDEX')) { + $oCmd->addParams('--tablespace-main-index', getSetting('TABLESPACE_PLACE_INDEX')); } $oCmd->addParams('--latlong', '--slim', '--create'); $oCmd->addParams('--output', 'gazetteer'); @@ -234,7 +235,7 @@ class SetupFunctions info('Create Functions'); // Try accessing the C module, so we know early if something is wrong - checkModulePresence(); // raises exception on failure + $this->checkModulePresence(); // raises exception on failure $this->createSqlFunctions(); } @@ -243,7 +244,7 @@ class SetupFunctions { info('Create Tables'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/tables.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/tables.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunScript($sTemplate, false); @@ -252,7 +253,7 @@ class SetupFunctions $this->dropTable('search_name'); } - $oAlParser = new AddressLevelParser(CONST_Address_Level_Config); + $oAlParser = new AddressLevelParser(getSettingConfig('ADDRESS_LEVEL_CONFIG', 'address-levels.json')); $oAlParser->createTable($this->db(), 'address_levels'); } @@ -260,7 +261,7 @@ class SetupFunctions { info('Create Tables'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/table-triggers.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/table-triggers.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunScript($sTemplate, false); @@ -270,7 +271,7 @@ class SetupFunctions { info('Create Partition Tables'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/partition-tables.src.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/partition-tables.src.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunPartitionScript($sTemplate); @@ -280,13 +281,14 @@ class SetupFunctions { info('Create Partition Functions'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/partition-functions.src.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/partition-functions.src.sql'); $this->pgsqlRunPartitionScript($sTemplate); } public function importWikipediaArticles() { - $sWikiArticlesFile = CONST_Wikipedia_Data_Path.'/wikimedia-importance.sql.gz'; + $sWikiArticlePath = getSetting('WIKIPEDIA_DATA_PATH', CONST_DataDir.'/data'); + $sWikiArticlesFile = $sWikiArticlePath.'/wikimedia-importance.sql.gz'; if (file_exists($sWikiArticlesFile)) { info('Importing wikipedia articles and redirects'); $this->dropTable('wikipedia_article'); @@ -335,14 +337,14 @@ class SetupFunctions // used by getorcreate_word_id to ignore frequent partial words $sSQL = 'CREATE OR REPLACE FUNCTION get_maxwordfreq() RETURNS integer AS '; - $sSQL .= '$$ SELECT '.CONST_Max_Word_Frequency.' as maxwordfreq; $$ LANGUAGE SQL IMMUTABLE'; + $sSQL .= '$$ SELECT '.getSetting('MAX_WORD_FREQUENCY').' as maxwordfreq; $$ LANGUAGE SQL IMMUTABLE'; $oDB->exec($sSQL); echo ".\n"; // pre-create the word list if (!$bDisableTokenPrecalc) { info('Loading word list'); - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/words.sql'); + $this->pgsqlRunScriptFile(CONST_DataDir.'/data/words.sql'); } info('Load Data'); @@ -352,7 +354,7 @@ class SetupFunctions $iLoadThreads = max(1, $this->iInstances - 1); for ($i = 0; $i < $iLoadThreads; $i++) { // https://secure.php.net/manual/en/function.pg-connect.php - $DSN = CONST_Database_DSN; + $DSN = getSetting('DATABASE_DSN'); $DSN = preg_replace('/^pgsql:/', '', $DSN); $DSN = preg_replace('/;/', ' ', $DSN); $aDBInstances[$i] = pg_connect($DSN, PGSQL_CONNECT_FORCE_NEW); @@ -372,7 +374,7 @@ class SetupFunctions // last thread for interpolation lines // https://secure.php.net/manual/en/function.pg-connect.php - $DSN = CONST_Database_DSN; + $DSN = getSetting('DATABASE_DSN'); $DSN = preg_replace('/^pgsql:/', '', $DSN); $DSN = preg_replace('/;/', ' ', $DSN); $aDBInstances[$iLoadThreads] = pg_connect($DSN, PGSQL_CONNECT_FORCE_NEW); @@ -424,17 +426,17 @@ class SetupFunctions } } - public function importTigerData() + public function importTigerData($sTigerPath) { info('Import Tiger data'); - $aFilenames = glob(CONST_Tiger_Data_Path.'/*.sql'); - info('Found '.count($aFilenames).' SQL files in path '.CONST_Tiger_Data_Path); + $aFilenames = glob($sTigerPath.'/*.sql'); + info('Found '.count($aFilenames).' SQL files in path '.$sTigerPath); if (empty($aFilenames)) { - warn('Tiger data import selected but no files found in path '.CONST_Tiger_Data_Path); + warn('Tiger data import selected but no files found in path '.$sTigerPath); return; } - $sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_start.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/tiger_import_start.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunScript($sTemplate, false); @@ -442,7 +444,7 @@ class SetupFunctions $aDBInstances = array(); for ($i = 0; $i < $this->iInstances; $i++) { // https://secure.php.net/manual/en/function.pg-connect.php - $DSN = CONST_Database_DSN; + $DSN = getSetting('DATABASE_DSN'); $DSN = preg_replace('/^pgsql:/', '', $DSN); $DSN = preg_replace('/;/', ' ', $DSN); $aDBInstances[$i] = pg_connect($DSN, PGSQL_CONNECT_FORCE_NEW | PGSQL_CONNECT_ASYNC); @@ -488,7 +490,7 @@ class SetupFunctions } info('Creating indexes on Tiger data'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_finish.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/tiger_import_finish.sql'); $sTemplate = $this->replaceSqlPatterns($sTemplate); $this->pgsqlRunScript($sTemplate, false); @@ -542,9 +544,9 @@ class SetupFunctions public function index($bIndexNoanalyse) { - checkModulePresence(); // raises exception on failure + $this->checkModulePresence(); // raises exception on failure - $oBaseCmd = (new \Nominatim\Shell(CONST_BasePath.'/nominatim/nominatim.py')) + $oBaseCmd = (new \Nominatim\Shell(CONST_DataDir.'/nominatim/nominatim.py')) ->addParams('--database', $this->aDSNInfo['database']) ->addParams('--port', $this->aDSNInfo['port']) ->addParams('--threads', $this->iInstances); @@ -616,12 +618,12 @@ class SetupFunctions $this->db()->exec("DROP INDEX $sIndexName;"); } - $sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/indices.src.sql'); if (!$this->bDrop) { - $sTemplate .= file_get_contents(CONST_BasePath.'/sql/indices_updates.src.sql'); + $sTemplate .= file_get_contents(CONST_DataDir.'/sql/indices_updates.src.sql'); } if (!$this->dbReverseOnly()) { - $sTemplate .= file_get_contents(CONST_BasePath.'/sql/indices_search.src.sql'); + $sTemplate .= file_get_contents(CONST_DataDir.'/sql/indices_search.src.sql'); } $sTemplate = $this->replaceSqlPatterns($sTemplate); @@ -638,10 +640,11 @@ class SetupFunctions $this->pgsqlRunScript("select count(*) from (select getorcreate_country(make_standard_name(name->'name'), country_code) from country_name where name ? 'name') as x"); $sSQL = 'select count(*) from (select getorcreate_country(make_standard_name(v),' .'country_code) from (select country_code, skeys(name) as k, svals(name) as v from country_name) x where k '; - if (CONST_Languages) { + $sLanguages = getSetting('LANGUAGES'); + if ($sLanguages) { $sSQL .= 'in '; $sDelim = '('; - foreach (explode(',', CONST_Languages) as $sLang) { + foreach (explode(',', $sLanguages) as $sLang) { $sSQL .= $sDelim."'name:$sLang'"; $sDelim = ','; } @@ -703,36 +706,60 @@ class SetupFunctions } /** - * Setup settings-frontend.php in the build/website directory + * Setup the directory for the API scripts. * * @return null */ public function setupWebsite() { - $rOutputFile = fopen(CONST_InstallPath.'/settings/settings-frontend.php', 'w'); - - fwrite($rOutputFile, "bVerbose) echo 'Deleting '.CONST_Osm2pgsql_Flatnode_File."\n"; - unlink(CONST_Osm2pgsql_Flatnode_File); - } + $sFName = getSetting('FLATNODE_FILE'); + if ($sFName && file_exists($sFName)) { + if ($this->bVerbose) echo 'Deleting '.$sFName."\n"; + unlink($sFName); } } @@ -775,7 +801,7 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE private function createSqlFunctions() { - $sBasePath = CONST_BasePath.'/sql/functions/'; + $sBasePath = CONST_DataDir.'/sql/functions/'; $sTemplate = file_get_contents($sBasePath.'utils.sql'); $sTemplate .= file_get_contents($sBasePath.'normalization.sql'); $sTemplate .= file_get_contents($sBasePath.'ranking.sql'); @@ -798,13 +824,13 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE if ($this->bEnableDebugStatements) { $sTemplate = str_replace('--DEBUG:', '', $sTemplate); } - if (CONST_Limit_Reindexing) { + if (getSettingBool('LIMIT_REINDEXING')) { $sTemplate = str_replace('--LIMIT INDEXING:', '', $sTemplate); } - if (!CONST_Use_US_Tiger_Data) { + if (!getSettingBool('USE_US_TIGER_DATA')) { $sTemplate = str_replace('-- %NOTIGERDATA% ', '', $sTemplate); } - if (!CONST_Use_Aux_Location_data) { + if (!getSettingBool('USE_AUX_LOCATION_DATA')) { $sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate); } @@ -895,15 +921,15 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE private function replaceSqlPatterns($sSql) { - $sSql = str_replace('{www-user}', CONST_Database_Web_User, $sSql); + $sSql = str_replace('{www-user}', getSetting('DATABASE_WEBUSER'), $sSql); $aPatterns = array( - '{ts:address-data}' => CONST_Tablespace_Address_Data, - '{ts:address-index}' => CONST_Tablespace_Address_Index, - '{ts:search-data}' => CONST_Tablespace_Search_Data, - '{ts:search-index}' => CONST_Tablespace_Search_Index, - '{ts:aux-data}' => CONST_Tablespace_Aux_Data, - '{ts:aux-index}' => CONST_Tablespace_Aux_Index, + '{ts:address-data}' => getSetting('TABLESPACE_ADDRESS_DATA'), + '{ts:address-index}' => getSetting('TABLESPACE_ADDRESS_INDEX'), + '{ts:search-data}' => getSetting('TABLESPACE_SEARCH_DATA'), + '{ts:search-index}' => getSetting('TABLESPACE_SEARCH_INDEX'), + '{ts:aux-data}' => getSetting('TABLESPACE_AUX_DATA'), + '{ts:aux-index}' => getSetting('TABLESPACE_AUX_INDEX') ); foreach ($aPatterns as $sPattern => $sTablespace) { @@ -939,4 +965,20 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE { return !($this->db()->tableExists('search_name')); } + + /** + * Try accessing the C module, so we know early if something is wrong. + * + * Raises Nominatim\DatabaseError on failure + */ + private function checkModulePresence() + { + $sSQL = "CREATE FUNCTION nominatim_test_import_func(text) RETURNS text AS '"; + $sSQL .= $this->sModulePath . "/nominatim.so', 'transliteration' LANGUAGE c IMMUTABLE STRICT"; + $sSQL .= ';DROP FUNCTION nominatim_test_import_func(text);'; + + $oDB = new \Nominatim\DB(); + $oDB->connect(); + $oDB->exec($sSQL, null, 'Database server failed to load '.$this->sModulePath.'/nominatim.so module'); + } } diff --git a/lib/setup_functions.php b/lib/setup_functions.php index 43f30a09..a2287d9b 100755 --- a/lib/setup_functions.php +++ b/lib/setup_functions.php @@ -15,17 +15,23 @@ function checkInFile($sOSMFile) } } -function checkModulePresence() +function getOsm2pgsqlBinary() { - // Try accessing the C module, so we know early if something is wrong. - // Raises Nominatim\DatabaseError on failure + $sBinary = getSetting('OSM2PGSQL_BINARY'); + if (!$sBinary) { + $sBinary = CONST_InstallDir.'/osm2pgsql/osm2pgsql'; + } + + return $sBinary; +} - $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"; - $sSQL .= ';DROP FUNCTION nominatim_test_import_func(text);'; +function getImportStyle() +{ + $sStyle = getSetting('IMPORT_STYLE'); + + if (in_array($sStyle, array('admin', 'street', 'address', 'full', 'extratags'))) { + return CONST_DataDir.'/settings/import-'.$sStyle.'.style'; + } - $oDB = new \Nominatim\DB(); - $oDB->connect(); - $oDB->exec($sSQL, null, 'Database server failed to load '.$sModulePath.'/nominatim.so module'); + return $sStyle; } diff --git a/settings/defaults.php b/settings/defaults.php deleted file mode 100644 index 2ecbb514..00000000 --- a/settings/defaults.php +++ /dev/null @@ -1,118 +0,0 @@ -; :: lower (); [[:Punctuation:][:Space:]]+ > ' '; :: NFC ();"); - -/* Set to true after importing Tiger house number data for the US. - Note: The tables must already exist or queries will throw errors. - After changing this setting run ./utils/setup --create-functions - again. */ -@define('CONST_Use_US_Tiger_Data', false); -/* Set to true after importing other external house number data. - Note: the aux tables must already exist or queries will throw errors. - After changing this setting run ./utils/setup --create-functions - again. */ -@define('CONST_Use_Aux_Location_data', false); - -// Proxy settings -@define('CONST_HTTP_Proxy', false); -@define('CONST_HTTP_Proxy_Host', 'proxy.mydomain.com'); -@define('CONST_HTTP_Proxy_Port', '3128'); -@define('CONST_HTTP_Proxy_Login', ''); -@define('CONST_HTTP_Proxy_Password', ''); - -// Paths -@define('CONST_ExtraDataPath', CONST_BasePath.'/data'); -@define('CONST_Osm2pgsql_Binary', CONST_InstallPath.'/osm2pgsql/osm2pgsql'); -@define('CONST_Pyosmium_Binary', '@PYOSMIUM_PATH@'); -@define('CONST_Tiger_Data_Path', CONST_ExtraDataPath.'/tiger'); -@define('CONST_Wikipedia_Data_Path', CONST_ExtraDataPath); -@define('CONST_Phrase_Config', CONST_BasePath.'/settings/phrase_settings.php'); -@define('CONST_Address_Level_Config', CONST_BasePath.'/settings/address-levels.json'); -@define('CONST_Import_Style', CONST_BasePath.'/settings/import-full.style'); - -// osm2pgsql settings -@define('CONST_Osm2pgsql_Flatnode_File', null); - -// tablespace settings -// osm2pgsql caching tables (aka slim mode tables) - update only -@define('CONST_Tablespace_Osm2pgsql_Data', false); -@define('CONST_Tablespace_Osm2pgsql_Index', false); -// osm2pgsql output tables (aka main table) - update only -@define('CONST_Tablespace_Place_Data', false); -@define('CONST_Tablespace_Place_Index', false); -// address computation tables - update only -@define('CONST_Tablespace_Address_Data', false); -@define('CONST_Tablespace_Address_Index', false); -// search tables - needed for lookups -@define('CONST_Tablespace_Search_Data', false); -@define('CONST_Tablespace_Search_Index', false); -// additional data, e.g. TIGER data, type searches - needed for lookups -@define('CONST_Tablespace_Aux_Data', false); -@define('CONST_Tablespace_Aux_Index', false); - -//// Replication settings - -// Base URL of replication service -@define('CONST_Replication_Url', 'https://planet.openstreetmap.org/replication/minute'); - -// Maximum size in MB of data to download per batch -@define('CONST_Replication_Max_Diff_size', '30'); -// How long until the service publishes the next diff -// (relative to the age of data in the diff). -@define('CONST_Replication_Update_Interval', '75'); -// How long to sleep when no update could be found -@define('CONST_Replication_Recheck_Interval', '60'); - -// If true, send CORS headers to allow access -@define('CONST_NoAccessControl', true); - -// Set this to the /mapicon directory of your nominatim-ui to enable returning -// icon URLs with the results. -@define('CONST_MapIcon_URL', false); -// Language to assume when none is supplied with the query. -// When set to false, the local language (i.e. the name tag without suffix) -// will be used. -@define('CONST_Default_Language', false); - -@define('CONST_Search_AreaPolygons', true); - -@define('CONST_Search_BatchMode', false); - -@define('CONST_Search_NameOnlySearchFrequencyThreshold', 500); -// If set to true, then reverse order of queries will be tried by default. -// When set to false only selected languages allow reverse search. -@define('CONST_Search_ReversePlanForAll', true); - -// Maximum number of OSM ids that may be queried at once -// for the places endpoint. -@define('CONST_Places_Max_ID_count', 50); - -// Number of different geometry formats that may be queried in parallel. -// Set to zero to disable polygon output. -@define('CONST_PolygonOutput_MaximumTypes', 1); - -// Log settings -// Set to true to log into new_query_log table. -// You should set up a cron job that regularly clears out this table. -@define('CONST_Log_DB', false); -// Set to a file name to enable logging to a file. -@define('CONST_Log_File', false); diff --git a/settings/env.defaults b/settings/env.defaults new file mode 100644 index 00000000..fbad3e33 --- /dev/null +++ b/settings/env.defaults @@ -0,0 +1,213 @@ +# .env +# Default configuration settings for Nominatim. +# This file uses the dotenv format. + +# Database connection string. +# Add host, port, user etc through additional semicolon-separated attributes. +# e.g. ;host=...;port=...;user=...;password=... +# Changing this variable requires to run 'setup.php --setup-website'. +NOMINATIM_DATABASE_DSN="pgsql:dbname=nominatim" + +# Database web user. +# Nominatim sets up read-only access for this user during installation. +NOMINATIM_DATABASE_WEBUSER="www-data" + +# Directory where to find the PostgreSQL server module. +# When empty the module is expected to be located in the 'module' subdirectory +# in the project directory. +# Changing this value requires to run ./utils/setup --create-functions. +NOMINATIM_DATABASE_MODULE_PATH= + +# Number of occurances of a word before it is considered frequent. +# Similar to the concept of stop words. Frequent partial words get ignored +# or handled differently during search. +# Changing this value requires a reimport. +NOMINATIM_MAX_WORD_FREQUENCY=50000 + +# If true, admin level changes on places with many contained children are blocked. +NOMINATIM_LIMIT_REINDEXING=yes + +# Restrict search languages. +# Normally Nominatim will include all language variants of name:XX +# in the search index. Set this to a comma separated list of language +# codes, to restrict import to a subset of languages. +# Currently only affects the initial import of country names and special phrases. +NOMINATIM_LANGUAGES= + +# Rules for normalizing terms for comparisons. +# The default is to remove accents and punctuation and to lower-case the +# term. Spaces are kept but collapsed to one standard space. +# Changing this value requires a reimport. +NOMINATIM_TERM_NORMALIZATION=":: NFD (); [[:Nonspacing Mark:] [:Cf:]] >; :: lower (); [[:Punctuation:][:Space:]]+ > ' '; :: NFC ();" + +# Search in the Tiger house number data for the US. +# Note: The tables must already exist or queries will throw errors. +# Changing this value requires to run ./utils/setup --create-functions --setup-website. +NOMINATIM_USE_US_TIGER_DATA=no + +# Search in the auxilary housenumber table. +# Changing this value requires to run ./utils/setup --create-functions --setup-website. +NOMINATIM_USE_AUX_LOCATION_DATA=no + +# Proxy settings +# The following settings allow to set a proxy to use when remotely downloading +# data. Host and port are required. Login and password are optional. +NOMINATIM_HTTP_PROXY=no +NOMINATIM_HTTP_PROXY_HOST=proxy.mydomain.com +NOMINATIM_HTTP_PROXY_PORT=3128 +NOMINATIM_HTTP_PROXY_LOGIN= +NOMINATIM_HTTP_PROXY_PASSWORD= + +# Location of the osm2pgsql binary. +# When empty, osm2pgsql is expected to reside in the osm2pgsql directory in +# the project directory. +# EXPERT ONLY. You should usually use the supplied osm2pgsql. +NOMINATIM_OSM2PGSQL_BINARY= + +# Location of pyosmium-get-changes. +# Only needed when running updates. +NOMINATIM_PYOSMIUM_BINARY= + +# Directory where to find US Tiger data files to import. +# Used with setup.php --import-tiger-data. When unset, the data is expected +# to be located under 'data/tiger' in the source tree. +NOMINATIM_TIGER_DATA_PATH= + +# Directory where to find pre-computed Wikipedia importance files. +# When unset, the data is expected to be located in the 'data' directory +# in the source tree. +NOMINATIM_WIKIPEDIA_DATA_PATH= + +# Configuration file for special phrase import. +# When unset, the internal default settings from 'settings/phrase_settings.php' +# are used. +NOMINATIM_PHRASE_CONFIG= + +# Configuration file for rank assignments. +# When unset, the internal default settings from 'settings/address-levels.json' +# are used. +NOMINATIM_ADDRESS_LEVEL_CONFIG= + +# Configuration file for OSM data import. +# This may either be the name of one of an internal style or point +# to a file with a custom style. +# Internal styles are: admin, street, address, full, extratags +NOMINATIM_IMPORT_STYLE=extratags + +# Location of the flatnode file used by osm2pgsql to store node locations. +# When unset, osm2pgsql stores the location in the PostgreSQL database. This +# is especially useful for imports of larger areas, like continents or the +# full planet. The file needs at least 70GB storage. +NOMINATIM_FLATNODE_FILE= + +### Tablespace settings +# +# The following settings allow to move parts of the database tables into +# different tablespaces. This is especially interesting if you have disks +# with different speeds. When unset, the default tablespace is used. +# Only has an effect during import. + +# Tablespace used for tables used when searching. +NOMINATIM_TABLESPACE_SEARCH_DATA= +# Tablespace used for indexes used when searching. +NOMINATIM_TABLESPACE_SEARCH_INDEX= + +# Tablespace used for the OSM data cache tables. Used for import and update only. +NOMINATIM_TABLESPACE_OSM_DATA= +# Tablespace used for the OSM data cache indexes. Used for import and update only. +NOMINATIM_TABLESPACE_OSM_INDEX= + +# Tablespace used for place import table. Used for import and update only. +NOMINATIM_TABLESPACE_PLACE_DATA= +# Tablespace used for place import indexes. Used for import and update only. +NOMINATIM_TABLESPACE_PLACE_INDEX= + +# Tablespace for tables used during address computation. Used for import and update only. +NOMINATIM_TABLESPACE_ADDRESS_DATA= +# Tablespace for indexes used during address computation. Used for import and update only. +NOMINATIM_TABLESPACE_ADDRESS_INDEX= + +# Tablespace for tables for auxilary data, e.g. TIGER data, postcodes. +NOMINATIM_TABLESPACE_AUX_DATA= +# Tablespace for indexes for auxilary data, e.g. TIGER data, postcodes. +NOMINATIM_TABLESPACE_AUX_INDEX= + + +### Replication settings +# +# The following settings control where and how updates for the database are +# retrieved. +# + +# +# Base URL of replication service. +# A replication service provides change files of OSM data at regular intervals. +# These are used to keep the database up to date. Per default it points to +# the minutely updates for the main OSM database. There are other services +# geared towards larger update intervals or data extracts. +# Changing this value requires to rerun 'update/php --init-updates'. +NOMINATIM_REPLICATION_URL="https://planet.openstreetmap.org/replication/minute" + +# Maximum amount of data to download per batch. +# Size is in MB. +NOMINATIM_REPLICATION_MAX_DIFF=50 + +# Publication interval of the replication service. +# Determines when Nominatim will attempt again to download again a new +# update. The time is computed from the publication date of the last diff +# downloaded. Setting this to a slightly higher value than the actual +# publication interval avoids unnecessary rechecks. +NOMINATIM_REPLICATION_UPDATE_INTERVAL=75 + +# Wait time to recheck for a pending update. +# Time to wait after an expected update was not available on the server. +NOMINATIM_REPLICATION_RECHECK_INTERVAL=60 + +### API settings +# +# The following settings configure the API responses. You must rerun +# setup.php --setup-website after changing any of them. + +# Send permissive CORS access headers. +# When enabled, send CORS headers to allow access to everybody. +NOMINATIM_CORS_NOACCESSCONTROL=yes + +# URL for static icon images. +# Set this to the /mapicon directory of your nominatim-ui to enable returning +# icon URLs with the results. +NOMINATIM_MAPICON_URL= + +# Language to assume when no particular language is requested. +# When unset, the local language (i.e. the name tag without suffix) will be used. +NOMINATIM_DEFAULT_LANGUAGE= + +# Enable a special batch query mode. +# This features is currently undocumented and potentially broken. +NOMINATIM_SEARCH_BATCH_MODE=no + +# Threshold for searches by name only. +# Threshold where the lookup strategy in the database is switched. If there +# are less occurences of a tem than given, the search does the lookup only +# against the name, otherwise it uses indexes for name and address. +NOMINATIM_SEARCH_NAME_ONLY_THRESHOLD=500 + +# Maximum number of OSM ids accepted by /lookup. +NOMINATIM_LOOKUP_MAX_COUNT=50 + +# Number of different geometry formats that may be queried in parallel. +# Set to zero to disable polygon output. +NOMINATIM_POLYGON_OUTPUT_MAX_TYPES=1 + +### Log settings +# +# The following options allow to enable logging of API requests. +# You must rerun setup.php --setup-website after changing any of them. +# +# Enable logging of requests into the DB. +# The request will be logged into the new_query_log table. +# You should set up a cron job that regularly clears out this table. +NOMINATIM_LOG_DB=no + +# Enable logging of requests into a file. +# To enable logging set this setting to the file to log to. +NOMINATIM_LOG_FILE= diff --git a/test/bdd/environment.py b/test/bdd/environment.py index f0658c33..8847011a 100644 --- a/test/bdd/environment.py +++ b/test/bdd/environment.py @@ -48,6 +48,7 @@ class NominatimEnvironment(object): self.keep_scenario_db = config['KEEP_TEST_DB'] self.code_coverage_path = config['PHPCOV'] self.code_coverage_id = 1 + self.test_env = None os.environ['NOMINATIM_SETTINGS'] = self.local_settings_file self.template_db_done = False @@ -72,19 +73,28 @@ class NominatimEnvironment(object): return fn def write_nominatim_config(self, dbname): - f = open(self.local_settings_file, 'w') - # https://secure.php.net/manual/en/ref.pdo-pgsql.connection.php - f.write("oDbStub = $this->getMockBuilder(\DB::class) diff --git a/test/php/Nominatim/ClassTypesTest.php b/test/php/Nominatim/ClassTypesTest.php index 1ba79bdb..10256954 100644 --- a/test/php/Nominatim/ClassTypesTest.php +++ b/test/php/Nominatim/ClassTypesTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/ClassTypes.php'); +require_once(CONST_LibDir.'/ClassTypes.php'); class ClassTypesTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/DBTest.php b/test/php/Nominatim/DBTest.php index 1991f6f1..8a3157a8 100644 --- a/test/php/Nominatim/DBTest.php +++ b/test/php/Nominatim/DBTest.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/lib.php'); -require_once(CONST_BasePath.'/lib/DB.php'); +require_once(CONST_LibDir.'/lib.php'); +require_once(CONST_LibDir.'/DB.php'); // subclassing so we can set the protected connection variable class NominatimSubClassedDB extends \Nominatim\DB diff --git a/test/php/Nominatim/DatabaseErrorTest.php b/test/php/Nominatim/DatabaseErrorTest.php index 7b461894..da156493 100644 --- a/test/php/Nominatim/DatabaseErrorTest.php +++ b/test/php/Nominatim/DatabaseErrorTest.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/init-website.php'); -require_once(CONST_BasePath.'/lib/DatabaseError.php'); +require_once(CONST_LibDir.'/init-website.php'); +require_once(CONST_LibDir.'/DatabaseError.php'); class DatabaseErrorTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/DebugTest.php b/test/php/Nominatim/DebugTest.php index 5d9525ac..09860914 100644 --- a/test/php/Nominatim/DebugTest.php +++ b/test/php/Nominatim/DebugTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/DebugHtml.php'); +require_once(CONST_LibDir.'/DebugHtml.php'); class DebugTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/LibTest.php b/test/php/Nominatim/LibTest.php index 28cd9af0..6e9038ee 100644 --- a/test/php/Nominatim/LibTest.php +++ b/test/php/Nominatim/LibTest.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/lib.php'); -require_once(CONST_BasePath.'/lib/ClassTypes.php'); +require_once(CONST_LibDir.'/lib.php'); +require_once(CONST_LibDir.'/ClassTypes.php'); class LibTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/OutputTest.php b/test/php/Nominatim/OutputTest.php index b243ba47..cbfebb7d 100644 --- a/test/php/Nominatim/OutputTest.php +++ b/test/php/Nominatim/OutputTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/output.php'); +require_once(CONST_LibDir.'/output.php'); class OutputTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/ParameterParserTest.php b/test/php/Nominatim/ParameterParserTest.php index 361fefc1..3b06e274 100644 --- a/test/php/Nominatim/ParameterParserTest.php +++ b/test/php/Nominatim/ParameterParserTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/ParameterParser.php'); +require_once(CONST_LibDir.'/ParameterParser.php'); function userError($sError) diff --git a/test/php/Nominatim/PhraseTest.php b/test/php/Nominatim/PhraseTest.php index ab031bb0..42166e34 100644 --- a/test/php/Nominatim/PhraseTest.php +++ b/test/php/Nominatim/PhraseTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/Phrase.php'); +require_once(CONST_LibDir.'/Phrase.php'); class TokensFullSet { diff --git a/test/php/Nominatim/SearchContextTest.php b/test/php/Nominatim/SearchContextTest.php index 2b575a16..1b346297 100644 --- a/test/php/Nominatim/SearchContextTest.php +++ b/test/php/Nominatim/SearchContextTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/SearchContext.php'); +require_once(CONST_LibDir.'/SearchContext.php'); class SearchContextTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/ShellTest.php b/test/php/Nominatim/ShellTest.php index d0222ee1..2d81b71d 100644 --- a/test/php/Nominatim/ShellTest.php +++ b/test/php/Nominatim/ShellTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/Shell.php'); +require_once(CONST_LibDir.'/Shell.php'); class ShellTest extends \PHPUnit\Framework\TestCase { diff --git a/test/php/Nominatim/StatusTest.php b/test/php/Nominatim/StatusTest.php index f45e6633..8cb8a703 100644 --- a/test/php/Nominatim/StatusTest.php +++ b/test/php/Nominatim/StatusTest.php @@ -2,8 +2,8 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/DB.php'); -require_once(CONST_BasePath.'/lib/Status.php'); +require_once(CONST_LibDir.'/DB.php'); +require_once(CONST_LibDir.'/Status.php'); class StatusTest extends \PHPUnit\Framework\TestCase diff --git a/test/php/Nominatim/TokenListTest.php b/test/php/Nominatim/TokenListTest.php index ca43aabb..3ef4d84d 100644 --- a/test/php/Nominatim/TokenListTest.php +++ b/test/php/Nominatim/TokenListTest.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/TokenList.php'); +require_once(CONST_LibDir.'/TokenList.php'); class TokenTest extends \PHPUnit\Framework\TestCase diff --git a/test/php/bootstrap.php b/test/php/bootstrap.php index d6968717..3a36db38 100644 --- a/test/php/bootstrap.php +++ b/test/php/bootstrap.php @@ -1,4 +1,6 @@ "\033[92m", @@ -35,7 +37,7 @@ if ($oDB->checkConnection()) { echo <<< END Hints: * Is the database server started? - * Check the CONST_Database_DSN variable in build/settings/local.php + * Check the NOMINATIM_DATABASE_DSN variable in your local .env * Try connecting to the database with the same settings END; @@ -166,7 +168,7 @@ END; -if (CONST_Use_US_Tiger_Data) { +if (getSettingBool('USE_US_TIGER_DATA')) { echo 'Checking TIGER table exists ... '; if ($oDB->tableExists('location_property_tiger')) { $print_success(); diff --git a/utils/country_languages.php b/utils/country_languages.php index 63f6525c..1a7ea616 100644 --- a/utils/country_languages.php +++ b/utils/country_languages.php @@ -1,6 +1,6 @@ 1, 'country' => 4, diff --git a/utils/query.php b/utils/query.php index 6068c7c0..429b30ff 100644 --- a/utils/query.php +++ b/utils/query.php @@ -1,8 +1,8 @@ connect(); diff --git a/utils/setup.php b/utils/setup.php index 7f476d5c..713fe561 100644 --- a/utils/setup.php +++ b/utils/setup.php @@ -1,8 +1,8 @@ importTigerData(); + $sTigerPath = getSetting('TIGER_DATA_PATH'); + if (!$sTigerPath) { + $sTigerPath = CONST_DataDir.'/data/tiger'; + } + $oSetup->importTigerData($sTigerPath); } if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) { diff --git a/utils/specialphrases.php b/utils/specialphrases.php index 9e6c9d76..b1df6436 100644 --- a/utils/specialphrases.php +++ b/utils/specialphrases.php @@ -1,6 +1,6 @@ connect(); $fPostgresVersion = $oDB->getPostgresVersion(); -$aDSNInfo = Nominatim\DB::parseDSN(CONST_Database_DSN); +$aDSNInfo = Nominatim\DB::parseDSN(getSetting('DATABASE_DSN')); if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432; // cache memory to be used by osm2pgsql, should not be more than the available memory @@ -65,7 +70,7 @@ if ($iCacheMemory + 500 > getTotalMemoryMB()) { echo "WARNING: resetting cache memory to $iCacheMemory\n"; } -$oOsm2pgsqlCmd = (new \Nominatim\Shell(CONST_Osm2pgsql_Binary)) +$oOsm2pgsqlCmd = (new \Nominatim\Shell(getOsm2pgsqlBinary())) ->addParams('--hstore') ->addParams('--latlong') ->addParams('--append') @@ -75,7 +80,7 @@ $oOsm2pgsqlCmd = (new \Nominatim\Shell(CONST_Osm2pgsql_Binary)) ->addParams('--number-processes', 1) ->addParams('--cache', $iCacheMemory) ->addParams('--output', 'gazetteer') - ->addParams('--style', CONST_Import_Style) + ->addParams('--style', getImportStyle()) ->addParams('--database', $aDSNInfo['database']) ->addParams('--port', $aDSNInfo['port']); @@ -88,8 +93,8 @@ if (isset($aDSNInfo['username']) && $aDSNInfo['username']) { if (isset($aDSNInfo['password']) && $aDSNInfo['password']) { $oOsm2pgsqlCmd->addEnvPair('PGPASSWORD', $aDSNInfo['password']); } -if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) { - $oOsm2pgsqlCmd->addParams('--flat-nodes', CONST_Osm2pgsql_Flatnode_File); +if (getSetting('FLATNODE_FILE')) { + $oOsm2pgsqlCmd->addParams('--flat-nodes', getSetting('FLATNODE_FILE')); } if ($fPostgresVersion >= 11.0) { $oOsm2pgsqlCmd->addEnvPair( @@ -99,7 +104,7 @@ if ($fPostgresVersion >= 11.0) { } -$oIndexCmd = (new \Nominatim\Shell(CONST_BasePath.'/nominatim/nominatim.py')) +$oIndexCmd = (new \Nominatim\Shell(CONST_DataDir.'/nominatim/nominatim.py')) ->addParams('--database', $aDSNInfo['database']) ->addParams('--port', $aDSNInfo['port']) ->addParams('--threads', $aResult['index-instances']); @@ -119,31 +124,34 @@ if (isset($aDSNInfo['password']) && $aDSNInfo['password']) { $oIndexCmd->addEnvPair('PGPASSWORD', $aDSNInfo['password']); } +$sPyosmiumBin = getSetting('PYOSMIUM_BINARY'); +$sBaseURL = getSetting('REPLICATION_URL'); + if ($aResult['init-updates']) { // sanity check that the replication URL is correct - $sBaseState = file_get_contents(CONST_Replication_Url.'/state.txt'); + $sBaseState = file_get_contents($sBaseURL.'/state.txt'); if ($sBaseState === false) { echo "\nCannot find state.txt file at the configured replication URL.\n"; echo "Does the URL point to a directory containing OSM update data?\n\n"; fail('replication URL not reachable.'); } // sanity check for pyosmium-get-changes - if (!CONST_Pyosmium_Binary) { - echo "\nCONST_Pyosmium_Binary not configured.\n"; + if (!$sPyosmiumBin) { + echo "\nNOMINATIM_PYOSMIUM_BINARY not configured.\n"; echo "You need to install pyosmium and set up the path to pyosmium-get-changes\n"; - echo "in your local settings file.\n\n"; - fail('CONST_Pyosmium_Binary not configured'); + echo "in your local .env file.\n\n"; + fail('NOMINATIM_PYOSMIUM_BINARY not configured'); } $aOutput = 0; - $oCMD = new \Nominatim\Shell(CONST_Pyosmium_Binary, '--help'); + $oCMD = new \Nominatim\Shell($sPyosmiumBin, '--help'); exec($oCMD->escapedCmd(), $aOutput, $iRet); if ($iRet != 0) { echo "Cannot execute pyosmium-get-changes.\n"; echo "Make sure you have pyosmium installed correctly\n"; - echo "and have set up CONST_Pyosmium_Binary to point to pyosmium-get-changes.\n"; + echo "and have set up NOMINATIM_PYOSMIUM_BINARY to point to pyosmium-get-changes.\n"; fail('pyosmium-get-changes not found or not usable'); } @@ -164,9 +172,9 @@ if ($aResult['init-updates']) { // get the appropriate state id $aOutput = 0; - $oCMD = (new \Nominatim\Shell(CONST_Pyosmium_Binary)) + $oCMD = (new \Nominatim\Shell($sPyosmiumBin)) ->addParams('--start-date', $sWindBack) - ->addParams('--server', CONST_Replication_Url); + ->addParams('--server', $sBaseURL); exec($oCMD->escapedCmd(), $aOutput, $iRet); if ($iRet != 0 || $aOutput[0] == 'None') { @@ -193,8 +201,8 @@ if ($aResult['check-for-updates']) { fail('Updates not set up. Please run ./utils/update.php --init-updates.'); } - $oCmd = (new \Nominatim\Shell(CONST_BasePath.'/utils/check_server_for_updates.py')) - ->addParams(CONST_Replication_Url) + $oCmd = (new \Nominatim\Shell(CONST_BinDir.'/check_server_for_updates.py')) + ->addParams($sBaseURL) ->addParams($aLastState['sequence_id']); $iRet = $oCmd->run(); @@ -223,11 +231,11 @@ if (isset($aResult['import-diff']) || isset($aResult['import-file'])) { if ($aResult['calculate-postcodes']) { info('Update postcodes centroids'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/update-postcodes.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/update-postcodes.sql'); runSQLScript($sTemplate, true, true); } -$sTemporaryFile = CONST_BasePath.'/data/osmosischange.osc'; +$sTemporaryFile = CONST_InstallDir.'/osmosischange.osc'; $bHaveDiff = false; $bUseOSMApi = isset($aResult['import-from-main-api']) && $aResult['import-from-main-api']; $sContentURL = ''; @@ -274,7 +282,7 @@ if ($bHaveDiff) { if ($aResult['recompute-word-counts']) { info('Recompute frequency of full-word search terms'); - $sTemplate = file_get_contents(CONST_BasePath.'/sql/words_from_search_name.sql'); + $sTemplate = file_get_contents(CONST_DataDir.'/sql/words_from_search_name.sql'); runSQLScript($sTemplate, true, true); } @@ -291,8 +299,9 @@ if ($aResult['index']) { } if ($aResult['update-address-levels']) { - echo 'Updating address levels from '.CONST_Address_Level_Config.".\n"; - $oAlParser = new \Nominatim\Setup\AddressLevelParser(CONST_Address_Level_Config); + $sAddressLevelConfig = getSettingConfig('ADDRESS_LEVEL_CONFIG', 'address-levels.json'); + echo 'Updating address levels from '.$sAddressLevelConfig.".\n"; + $oAlParser = new \Nominatim\Setup\AddressLevelParser($sAddressLevelConfig); $oAlParser->createTable($oDB, 'address_levels'); } @@ -315,17 +324,17 @@ if ($aResult['recompute-importance']) { if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) { // - if (strpos(CONST_Replication_Url, 'download.geofabrik.de') !== false && CONST_Replication_Update_Interval < 86400) { + if (strpos($sBaseURL, 'download.geofabrik.de') !== false && getSetting('REPLICATION_UPDATE_INTERVAL') < 86400) { fail('Error: Update interval too low for download.geofabrik.de. ' . "Please check install documentation (https://nominatim.org/release-docs/latest/admin/Import-and-Update#setting-up-the-update-process)\n"); } - $sImportFile = CONST_InstallPath.'/osmosischange.osc'; + $sImportFile = CONST_InstallDir.'/osmosischange.osc'; - $oCMDDownload = (new \Nominatim\Shell(CONST_Pyosmium_Binary)) - ->addParams('--server', CONST_Replication_Url) + $oCMDDownload = (new \Nominatim\Shell($sPyosmiumBin)) + ->addParams('--server', $sBaseURL) ->addParams('--outfile', $sImportFile) - ->addParams('--size', CONST_Replication_Max_Diff_size); + ->addParams('--size', getSetting('REPLICATION_MAX_DIFF')); $oCMDImport = (clone $oOsm2pgsqlCmd)->addParams($sImportFile); @@ -345,7 +354,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) { if ($aLastState['indexed']) { // Sleep if the update interval has not yet been reached. - $fNextUpdate = $aLastState['unix_ts'] + CONST_Replication_Update_Interval; + $fNextUpdate = $aLastState['unix_ts'] + getSetting('REPLICATION_UPDATE_INTERVAL'); if ($fNextUpdate > $fStartTime) { $iSleepTime = $fNextUpdate - $fStartTime; echo "Waiting for next update for $iSleepTime sec."; @@ -366,8 +375,9 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) { exec($oCMD->escapedCmd(), $aOutput, $iResult); if ($iResult == 3) { - echo 'No new updates. Sleeping for '.CONST_Replication_Recheck_Interval." sec.\n"; - sleep(CONST_Replication_Recheck_Interval); + $sSleep = getSetting('REPLICATION_RECHECK_INTERVAL'); + echo 'No new updates. Sleeping for '.$sSleep." sec.\n"; + sleep($sSleep); } elseif ($iResult != 0) { echo 'ERROR: updates failed.'; exit($iResult); @@ -379,7 +389,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) { // get the newest object from the diff file $sBatchEnd = 0; $iRet = 0; - $oCMD = new \Nominatim\Shell(CONST_BasePath.'/utils/osm_file_date.py', $sImportFile); + $oCMD = new \Nominatim\Shell(CONST_BinDir.'/osm_file_date.py', $sImportFile); exec($oCMD->escapedCmd(), $sBatchEnd, $iRet); if ($iRet == 5) { echo "Diff file is empty. skipping import.\n"; diff --git a/utils/warm.php b/utils/warm.php index 5476eae0..0d8260f1 100644 --- a/utils/warm.php +++ b/utils/warm.php @@ -1,6 +1,11 @@ connect(); diff --git a/vagrant/Install-on-Centos-7.sh b/vagrant/Install-on-Centos-7.sh index c67aab7c..24b17663 100755 --- a/vagrant/Install-on-Centos-7.sh +++ b/vagrant/Install-on-Centos-7.sh @@ -6,6 +6,10 @@ # Installing the Required Software # ================================ # +# !!! caution +# These instructions are currently broken because they do not +# include installation of the required PHP library symfony-dotenv. +# # These instructions expect that you have a freshly installed CentOS version 7. # Make sure all packages are up-to-date by running: # @@ -189,10 +193,7 @@ fi #DOCS: # the name of your webserver user: #DOCS:```sh -tee settings/local.php << EOF -getSet('format', array('json'), 'json'); set_exception_handler_by_format($sOutputFormat); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $sSQL = 'select placex.place_id, country_code,'; diff --git a/website/details.php b/website/details.php index 77e74969..91440b54 100644 --- a/website/details.php +++ b/website/details.php @@ -1,9 +1,9 @@ getBool('hierarchy', false); $bGroupHierarchy = $oParams->getBool('group_hierarchy', false); $bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson', false); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $sLanguagePrefArraySQL = $oDB->getArraySQL($oDB->getDBQuotedList($aLangPrefOrder)); @@ -77,7 +77,7 @@ if ($sOsmType && $iOsmId > 0) { $aPointDetails['error_x'] = 0; $aPointDetails['error_y'] = 0; } - include(CONST_BasePath.'/lib/template/details-error-'.$sOutputFormat.'.php'); + include(CONST_LibDir.'/template/details-error-'.$sOutputFormat.'.php'); exit; } } @@ -247,4 +247,4 @@ if ($bIncludeKeywords) { logEnd($oDB, $hLog, 1); -include(CONST_BasePath.'/lib/template/details-'.$sOutputFormat.'.php'); +include(CONST_LibDir.'/template/details-'.$sOutputFormat.'.php'); diff --git a/website/lookup.php b/website/lookup.php index db2c01d6..737edc62 100644 --- a/website/lookup.php +++ b/website/lookup.php @@ -1,9 +1,9 @@ getPreferredLanguages(); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $hLog = logStart($oDB, 'place', $_SERVER['QUERY_STRING'], $aLangPrefOrder); @@ -84,4 +84,4 @@ $sMoreURL = ''; logEnd($oDB, $hLog, 1); $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat; -include(CONST_BasePath.'/lib/template/search-'.$sOutputTemplate.'.php'); +include(CONST_LibDir.'/template/search-'.$sOutputTemplate.'.php'); diff --git a/website/polygons.php b/website/polygons.php index 9c657a1d..88b48ae8 100644 --- a/website/polygons.php +++ b/website/polygons.php @@ -1,8 +1,8 @@ getInt('days', false); $bReduced = $oParams->getBool('reduced', false); $sClass = $oParams->getString('class', false); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $iTotalBroken = (int) $oDB->getOne('SELECT count(*) FROM import_polygon_error'); diff --git a/website/reverse.php b/website/reverse.php index 640ea2ab..553c2692 100644 --- a/website/reverse.php +++ b/website/reverse.php @@ -1,10 +1,10 @@ getPreferredLanguages(); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); $oDB->connect(); $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder); @@ -84,4 +84,4 @@ if ($sOutputFormat == 'geocodejson') { } $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat; -include(CONST_BasePath.'/lib/template/address-'.$sOutputTemplate.'.php'); +include(CONST_LibDir.'/template/address-'.$sOutputTemplate.'.php'); diff --git a/website/search.php b/website/search.php index 43c9fd01..619dec6d 100644 --- a/website/search.php +++ b/website/search.php @@ -1,12 +1,12 @@ connect(); $oParams = new Nominatim\ParameterParser(); @@ -15,15 +15,6 @@ $oGeocode = new Nominatim\Geocode($oDB); $aLangPrefOrder = $oParams->getPreferredLanguages(); $oGeocode->setLanguagePreference($aLangPrefOrder); -if (CONST_Search_ReversePlanForAll - || isset($aLangPrefOrder['name:de']) - || isset($aLangPrefOrder['name:ru']) - || isset($aLangPrefOrder['name:ja']) - || isset($aLangPrefOrder['name:pl']) -) { - $oGeocode->setReverseInPlan(true); -} - // Format for output $sOutputFormat = $oParams->getSet('format', array('xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'jsonv2'); set_exception_handler_by_format($sOutputFormat); @@ -41,7 +32,7 @@ if (CONST_Search_BatchMode && isset($_GET['batch'])) { $aSearchResults = $oBatchGeocode->lookup(); $aBatchResults[] = $aSearchResults; } - include(CONST_BasePath.'/lib/template/search-batch-json.php'); + include(CONST_LibDir.'/template/search-batch-json.php'); exit; } @@ -89,4 +80,4 @@ if (isset($_SERVER['REQUEST_SCHEME']) if (CONST_Debug) exit; $sOutputTemplate = ($sOutputFormat == 'jsonv2') ? 'json' : $sOutputFormat; -include(CONST_BasePath.'/lib/template/search-'.$sOutputTemplate.'.php'); +include(CONST_LibDir.'/template/search-'.$sOutputTemplate.'.php'); diff --git a/website/status.php b/website/status.php index 0d483544..9f030fb3 100644 --- a/website/status.php +++ b/website/status.php @@ -1,13 +1,13 @@ getSet('format', array('text', 'json'), 'text'); -$oDB = new Nominatim\DB(); +$oDB = new Nominatim\DB(CONST_Database_DSN); if ($sOutputFormat == 'json') { header('content-type: application/json; charset=UTF-8');