<?php\r
\r
-\r
-\r
class SetupFunctions\r
-\r
{\r
protected $iCacheMemory; // set in constructor\r
protected $iInstances; // set in constructor\r
protected $oDB = null; // set in setupDB (earliest) or later in loadData, importData, drop, createSqlFunctions, importTigerData\r
// pgsqlRunPartitionScript, calculatePostcodes, ..if no already set \r
\r
-\r
public function __construct($aCMDResult) {\r
// by default, use all but one processor, but never more than 15.\r
$this->iInstances = isset($aCMDResult['threads'])\r
$this->bEnableDiffUpdates = $aCMDResult['enable-diff-updates'];\r
$this->bEnableDebugStatements = $aCMDResult['enable-debug-statements'];\r
$this->bNoPartitions = $aCMDResult['no-partitions'];\r
- \r
}\r
\r
- public function createDB(){\r
+ public function createDB()\r
+ {\r
info('Create DB');\r
$sDB = DB::connect(CONST_Database_DSN, false);\r
if (!PEAR::isError($sDB)) {\r
if ($result != 0) fail('Error executing external command: '.$sCreateDBCmd);\r
}\r
\r
- public function setupDB() {\r
+ public function setupDB()\r
+ {\r
info('Setup DB');\r
$this->oDB =& getDB();\r
\r
$this->pgsqlRunScript('CREATE TYPE wikipedia_article_match AS ()', false);\r
}\r
\r
- public function importData($sOSMFile) {\r
+ public function importData($sOSMFile)\r
+ {\r
info('Import data');\r
\r
$osm2pgsql = CONST_Osm2pgsql_Binary;\r
}\r
}\r
\r
- public function createFunctions() {\r
+ public function createFunctions()\r
+ {\r
info('Create Functions');\r
\r
$this->createSqlFunctions();\r
}\r
\r
- public function createTables() {\r
+ public function createTables()\r
+ {\r
info('Create Tables');\r
\r
$sTemplate = file_get_contents(CONST_BasePath.'/sql/tables.sql');\r
);\r
\r
$this->pgsqlRunScript($sTemplate, false);\r
+ }\r
\r
+ public function recreateFunction()\r
+ {\r
// re-run the functions\r
info('Recreate Functions');\r
$this->createSqlFunctions();\r
}\r
\r
- public function createPartitionTables() {\r
+ public function createPartitionTables()\r
+ {\r
info('Create Partition Tables');\r
\r
$sTemplate = file_get_contents(CONST_BasePath.'/sql/partition-tables.src.sql');\r
$this->pgsqlRunPartitionScript($sTemplate);\r
}\r
\r
- public function createPartitionFunctions() {\r
+ public function createPartitionFunctions()\r
+ {\r
info('Create Partition Functions');\r
\r
$sTemplate = file_get_contents(CONST_BasePath.'/sql/partition-functions.src.sql');\r
$this->pgsqlRunPartitionScript($sTemplate);\r
}\r
\r
- public function importWikipediaArticles() {\r
+ public function importWikipediaArticles()\r
+ {\r
$sWikiArticlesFile = CONST_Wikipedia_Data_Path.'/wikipedia_article.sql.bin';\r
$sWikiRedirectsFile = CONST_Wikipedia_Data_Path.'/wikipedia_redirect.sql.bin';\r
if (file_exists($sWikiArticlesFile)) {\r
warn('wikipedia redirect dump file not found - some place importance values may be missing');\r
}\r
echo ' finish wikipedia';\r
- } \r
+ }\r
\r
- public function loadData($bDisableTokenPrecalc) {\r
+ public function loadData($bDisableTokenPrecalc)\r
+ {\r
info('Drop old Data');\r
\r
if ($this->oDB == null) $this->oDB =& getDB();\r
}\r
\r
// last thread for interpolation lines\r
-\r
$aDBInstances[$iLoadThreads] =& getDB(true);\r
$sSQL = 'insert into location_property_osmline';\r
$sSQL .= ' (osm_id, address, linegeo)';\r
}\r
}\r
\r
- public function importTigerData() {\r
+ public function importTigerData()\r
+ {\r
info('Import Tiger data');\r
\r
$sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_start.sql');\r
$this->pgsqlRunScript($sTemplate, false);\r
}\r
\r
- public function calculatePostcodes($bCMDResultAll) {\r
+ public function calculatePostcodes($bCMDResultAll)\r
+ {\r
info('Calculate Postcodes');\r
if ($this->oDB == null) $this->oDB =& getDB();\r
if (!pg_query($this->oDB->connection, 'TRUNCATE location_postcode')) {\r
}\r
}\r
\r
- public function index($bIndexNoanalyse) {\r
+ public function index($bIndexNoanalyse)\r
+ {\r
$sOutputFile = '';\r
- $sBaseCmd = CONST_InstallPath.'/nominatim/nominatim -i -d '.$this->aDSNInfo['database'].' -P '.$this->aDSNInfo['port'].' -t '.$this->iInstances.$sOutputFile;\r
+ $sBaseCmd = CONST_InstallPath.'/nominatim/nominatim -i -d '.$this->aDSNInfo['database'].' -P '\r
+ .$this->aDSNInfo['port'].' -t '.$this->iInstances.$sOutputFile;\r
if (isset($this->aDSNInfo['hostspec']) && $this->aDSNInfo['hostspec']) {\r
$sBaseCmd .= ' -H ' . $this->aDSNInfo['hostspec'];\r
}\r
if ($this->oDB == null) $this->oDB =& getDB();\r
$sSQL = 'UPDATE location_postcode SET indexed_status = 0';\r
if (!pg_query($this->oDB->connection, $sSQL)) fail(pg_last_error($this->oDB->connection));\r
- } \r
+ }\r
\r
- public function createSearchIndices() {\r
+ public function createSearchIndices()\r
+ {\r
info('Create Search indices');\r
\r
$sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql');\r
$this->pgsqlRunScript($sTemplate);\r
}\r
\r
- public function createCountryNames() {\r
+ public function createCountryNames()\r
+ {\r
info('Create search index for default country names');\r
\r
$this->pgsqlRunScript("select getorcreate_country(make_standard_name('uk'), 'gb')");\r
$this->pgsqlRunScript("select getorcreate_country(make_standard_name('united states'), 'us')");\r
$this->pgsqlRunScript('select count(*) from (select getorcreate_country(make_standard_name(country_code), country_code) from country_name where country_code is not null) as x');\r
$this->pgsqlRunScript("select count(*) from (select getorcreate_country(make_standard_name(name->'name'), country_code) from country_name where name ? 'name') as x");\r
- $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 ';\r
+ $sSQL = 'select count(*) from (select getorcreate_country(make_standard_name(v),'\r
+ .'country_code) from (select country_code, skeys(name) as k, svals(name) as v from country_name) x where k ';\r
if (CONST_Languages) {\r
$sSQL .= 'in ';\r
$sDelim = '(';\r
$this->pgsqlRunScript($sSQL);\r
}\r
\r
- public function drop() {\r
+ public function drop()\r
+ {\r
info('Drop tables only required for updates');\r
\r
// The implementation is potentially a bit dangerous because it uses\r
}\r
}\r
\r
- private function pgsqlRunDropAndRestore($sDumpFile) {\r
+ private function pgsqlRunDropAndRestore($sDumpFile)\r
+ {\r
if (!isset($this->aDSNInfo['port']) || !$this->aDSNInfo['port']) $this->aDSNInfo['port'] = 5432;\r
$sCMD = 'pg_restore -p '.$this->aDSNInfo['port'].' -d '.$this->aDSNInfo['database'].' -Fc --clean '.$sDumpFile;\r
if (isset($this->aDSNInfo['hostspec']) && $this->aDSNInfo['hostspec']) {\r
$iReturn = runWithEnv($sCMD, $aProcEnv); // /lib/cmd.php "function runWithEnv($sCmd, $aEnv)"\r
}\r
\r
- private function pgsqlRunScript($sScript, $bfatal = true) {\r
+ private function pgsqlRunScript($sScript, $bfatal = true)\r
+ {\r
runSQLScript(\r
$sScript,\r
$bfatal,\r
);\r
}\r
\r
- private function createSqlFunctions() { \r
+ private function createSqlFunctions()\r
+ {\r
$sTemplate = file_get_contents(CONST_BasePath.'/sql/functions.sql');\r
$sTemplate = str_replace('{modulepath}', $this->sModulePath, $sTemplate);\r
if ($this->bEnableDiffUpdates) {\r
$this->pgsqlRunScript($sTemplate);\r
}\r
\r
- private function pgsqlRunPartitionScript($sTemplate) {\r
+ private function pgsqlRunPartitionScript($sTemplate)\r
+ {\r
if ($this->oDB == null) $this->oDB =& getDB();\r
\r
$sSQL = 'select distinct partition from country_name';\r
}\r
\r
$this->pgsqlRunScript($sTemplate);\r
- } \r
+ }\r
\r
- private function pgsqlRunScriptFile($sFilename) {\r
+ private function pgsqlRunScriptFile($sFilename)\r
+ {\r
if (!file_exists($sFilename)) fail('unable to find '.$sFilename);\r
\r
$sCMD = 'psql -p '.$this->aDSNInfo['port'].' -d '.$this->aDSNInfo['database'];\r
proc_close($hGzipProcess);\r
}\r
}\r
- private function replaceTablespace($sTemplate, $sTablespace, $sSql) {\r
+\r
+ private function replaceTablespace($sTemplate, $sTablespace, $sSql)\r
+ {\r
if ($sTablespace) {\r
$sSql = str_replace($sTemplate, 'TABLESPACE "'.$sTablespace.'"', $sSql);\r
} else {\r