mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
move creation of website scripts to setup script
Instead of creating the website wrapper scripts with cmake, they are now created when --setup-website is called. The setup of the configuration constants is directly embedded into the scripts. This means we can get rid of the separate settings-frontend.php. More importantly however, it means that it is now possible to set up multiple website directories from the same build directory.
This commit is contained in:
@@ -114,26 +114,10 @@ if (BUILD_IMPORTER)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# webserver scripts (API only)
|
# Targets for running a development webserver from the build directory.
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
if (BUILD_API)
|
if (BUILD_API)
|
||||||
set(WEBSITESCRIPTS
|
|
||||||
deletable.php
|
|
||||||
details.php
|
|
||||||
lookup.php
|
|
||||||
polygons.php
|
|
||||||
reverse.php
|
|
||||||
search.php
|
|
||||||
status.php
|
|
||||||
)
|
|
||||||
|
|
||||||
foreach (script_source ${WEBSITESCRIPTS})
|
|
||||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/website.tmpl
|
|
||||||
${PROJECT_BINARY_DIR}/website/${script_source})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
|
|
||||||
add_custom_target(serve
|
add_custom_target(serve
|
||||||
php -S 127.0.0.1:8088
|
php -S 127.0.0.1:8088
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/website
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/website
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
@define('CONST_Debug', (isset($_GET['debug']) && $_GET['debug']));
|
|
||||||
@define('CONST_LibDir', '@CMAKE_SOURCE_DIR@/lib');
|
|
||||||
@define('CONST_DataDir', '@CMAKE_SOURCE_DIR@');
|
|
||||||
@define('CONST_InstallDir', '@CMAKE_BINARY_DIR@');
|
|
||||||
require_once(CONST_InstallDir.'/settings/settings-frontend.php');
|
|
||||||
|
|
||||||
require_once('@CMAKE_SOURCE_DIR@/website/@script_source@');
|
|
||||||
18
lib/lib.php
18
lib/lib.php
@@ -134,6 +134,24 @@ function addQuotes($s)
|
|||||||
return "'".$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)
|
function parseLatLon($sQuery)
|
||||||
{
|
{
|
||||||
$sFound = null;
|
$sFound = null;
|
||||||
|
|||||||
@@ -706,33 +706,60 @@ class SetupFunctions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup settings-frontend.php in the build/website directory
|
* Setup the directory for the API scripts.
|
||||||
*
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function setupWebsite()
|
public function setupWebsite()
|
||||||
{
|
{
|
||||||
$rOutputFile = fopen(CONST_InstallDir.'/settings/settings-frontend.php', 'w');
|
if (!is_dir(CONST_InstallDir.'/website')) {
|
||||||
|
info('Creating directory for website scripts at: '.CONST_InstallDir.'/website');
|
||||||
|
mkdir(CONST_InstallDir.'/website');
|
||||||
|
}
|
||||||
|
|
||||||
fwrite($rOutputFile, "<?php
|
$aScripts = array(
|
||||||
if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SETTINGS'));
|
'deletable.php',
|
||||||
|
'details.php',
|
||||||
|
'lookup.php',
|
||||||
|
'polygons.php',
|
||||||
|
'reverse.php',
|
||||||
|
'search.php',
|
||||||
|
'status.php'
|
||||||
|
);
|
||||||
|
|
||||||
@define('CONST_Database_DSN', '".getSetting('DATABASE_DSN')."');
|
foreach($aScripts as $sScript) {
|
||||||
@define('CONST_Default_Language', ".getSetting('DEFAULT_LANGUAGE', 'false').");
|
$rFile = fopen(CONST_InstallDir.'/website/'.$sScript, 'w');
|
||||||
@define('CONST_Log_DB', ".(getSettingBool('LOG_DB') ? 'true' : 'false').");
|
|
||||||
@define('CONST_Log_File', ".getSetting('LOG_FILE', 'false').");
|
fwrite($rFile, "<?php\n\n");
|
||||||
@define('CONST_Max_Word_Frequency', '".getSetting('MAX_WORD_FREQUENCY')."');
|
fwrite($rFile, '@define(\'CONST_Debug\', $_GET[\'debug\'] ?? false);'."\n\n");
|
||||||
@define('CONST_NoAccessControl', ".(getSettingBool('CORS_NOACCESSCONTROL') ? 'true' : 'false').");
|
|
||||||
@define('CONST_Places_Max_ID_count', ".getSetting('LOOKUP_MAX_COUNT').");
|
fwriteConstDef($rFile, 'LibDir', CONST_LibDir);
|
||||||
@define('CONST_PolygonOutput_MaximumTypes', ".getSetting('POLYGON_OUTPUT_MAX_TYPES').");
|
fwriteConstDef($rFile, 'DataDir', CONST_DataDir);
|
||||||
@define('CONST_Search_BatchMode', ".(getSettingBool('SEARCH_BATCH_MODE') ? 'true' : 'false').");
|
fwriteConstDef($rFile, 'InstallDir', CONST_InstallDir);
|
||||||
@define('CONST_Search_NameOnlySearchFrequencyThreshold', ".getSetting('SEARCH_NAME_ONLY_THRESHOLD').");
|
|
||||||
@define('CONST_Term_Normalization_Rules', \"".getSetting('TERM_NORMALIZATION')."\");
|
fwrite($rFile, "if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SETTINGS'));\n\n");
|
||||||
@define('CONST_Use_Aux_Location_data', ".(getSettingBool('USE_AUX_LOCATION_DATA') ? 'true' : 'false').");
|
|
||||||
@define('CONST_Use_US_Tiger_Data', ".(getSettingBool('USE_US_TIGER_DATA') ? 'true' : 'false').");
|
fwriteConstDef($rFile, 'Database_DSN', getSetting('DATABASE_DSN'));
|
||||||
@define('CONST_MapIcon_URL', ".getSetting('MAPICON_URL', 'false').');
|
fwriteConstDef($rFile, 'Default_Language', getSetting('DEFAULT_LANGUAGE'));
|
||||||
');
|
fwriteConstDef($rFile, 'Log_DB', getSettingBool('LOG_DB'));
|
||||||
info(CONST_InstallDir.'/settings/settings-frontend.php has been set up successfully');
|
fwriteConstDef($rFile, 'Log_File', getSetting('LOG_FILE'));
|
||||||
|
fwriteConstDef($rFile, 'Max_Word_Frequency', (int)getSetting('MAX_WORD_FREQUENCY'));
|
||||||
|
fwriteConstDef($rFile, 'NoAccessControl', getSettingBool('CORS_NOACCESSCONTROL'));
|
||||||
|
fwriteConstDef($rFile, 'Places_Max_ID_count', (int)getSetting('LOOKUP_MAX_COUNT'));
|
||||||
|
fwriteConstDef($rFile, 'PolygonOutput_MaximumTypes', getSetting('POLYGON_OUTPUT_MAX_TYPES'));
|
||||||
|
fwriteConstDef($rFile, 'Search_BatchMode', getSettingBool('SEARCH_BATCH_MODE'));
|
||||||
|
fwriteConstDef($rFile, 'Search_NameOnlySearchFrequencyThreshold', getSetting('SEARCH_NAME_ONLY_THRESHOLD'));
|
||||||
|
fwriteConstDef($rFile, 'Term_Normalization_Rules', getSetting('TERM_NORMALIZATION'));
|
||||||
|
fwriteConstDef($rFile, 'Use_Aux_Location_data', getSettingBool('USE_AUX_LOCATION_DATA'));
|
||||||
|
fwriteConstDef($rFile, 'Use_US_Tiger_Data', getSettingBool('USE_US_TIGER_DATA'));
|
||||||
|
fwriteConstDef($rFile, 'MapIcon_URL', getSetting('MAPICON_URL'));
|
||||||
|
|
||||||
|
// XXX scripts should go into the library.
|
||||||
|
fwrite($rFile, 'require_once(\''.CONST_DataDir.'/website/'.$sScript."');\n");
|
||||||
|
fclose($rFile);
|
||||||
|
|
||||||
|
chmod(CONST_InstallDir.'/website/'.$sScript, 0755);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ $aCMDOptions
|
|||||||
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
|
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
|
||||||
|
|
||||||
loadSettings($aCMDResult['project-dir'] ?? getcwd());
|
loadSettings($aCMDResult['project-dir'] ?? getcwd());
|
||||||
|
|
||||||
@define('CONST_Database_DSN', getSetting('DATABASE_DSN'));
|
@define('CONST_Database_DSN', getSetting('DATABASE_DSN'));
|
||||||
@define('CONST_Default_Language', getSetting('DEFAULT_LANGUAGE', false));
|
@define('CONST_Default_Language', getSetting('DEFAULT_LANGUAGE', false));
|
||||||
@define('CONST_Log_DB', getSettingBool('LOG_DB'));
|
@define('CONST_Log_DB', getSettingBool('LOG_DB'));
|
||||||
|
|||||||
Reference in New Issue
Block a user