X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/9cfd891fb981a2a4241e24c4f3c4b5519eceda48..0c483063dd7f5b62c28e10279e22250ec861fb8f:/lib/setup/SetupClass.php diff --git a/lib/setup/SetupClass.php b/lib/setup/SetupClass.php index b8070e4a..2fdb3926 100755 --- a/lib/setup/SetupClass.php +++ b/lib/setup/SetupClass.php @@ -139,7 +139,7 @@ class SetupFunctions exit(1); } $this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_name.sql'); - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_osm_grid.sql.gz'); + $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'); @@ -160,13 +160,6 @@ class SetupFunctions if ($this->bNoPartitions) { $this->pgsqlRunScript('update country_name set partition = 0'); } - - // the following will be needed by createFunctions later but - // is only defined in the subsequently called createTables - // Create dummies here that will be overwritten by the proper - // versions in create-tables. - $this->pgsqlRunScript('CREATE TABLE IF NOT EXISTS place_boundingbox ()'); - $this->pgsqlRunScript('CREATE TYPE wikipedia_article_match AS ()', false); } public function importData($sOSMFile) @@ -323,19 +316,14 @@ class SetupFunctions public function importWikipediaArticles() { - $sWikiArticlesFile = CONST_Wikipedia_Data_Path.'/wikipedia_article.sql.bin'; - $sWikiRedirectsFile = CONST_Wikipedia_Data_Path.'/wikipedia_redirect.sql.bin'; + $sWikiArticlesFile = CONST_Wikipedia_Data_Path.'/wikimedia-importance.sql.gz'; if (file_exists($sWikiArticlesFile)) { - info('Importing wikipedia articles'); - $this->pgsqlRunDropAndRestore($sWikiArticlesFile); - } else { - warn('wikipedia article dump file not found - places will have default importance'); - } - if (file_exists($sWikiRedirectsFile)) { - info('Importing wikipedia redirects'); - $this->pgsqlRunDropAndRestore($sWikiRedirectsFile); + info('Importing wikipedia articles and redirects'); + $this->pgExec('DROP TABLE IF EXISTS wikipedia_article'); + $this->pgExec('DROP TABLE IF EXISTS wikipedia_redirect'); + $this->pgsqlRunScriptFile($sWikiArticlesFile); } else { - warn('wikipedia redirect dump file not found - some place importance values may be missing'); + warn('wikipedia importance dump file not found - places will have default importance'); } } @@ -351,8 +339,6 @@ class SetupFunctions echo '.'; $this->pgExec('TRUNCATE place_addressline'); echo '.'; - $this->pgExec('TRUNCATE place_boundingbox'); - echo '.'; $this->pgExec('TRUNCATE location_area'); echo '.'; if (!$this->dbReverseOnly()) { @@ -470,6 +456,10 @@ class SetupFunctions { info('Import Tiger data'); + $aFilenames = glob(CONST_Tiger_Data_Path.'/*.sql'); + info('Found '.count($aFilenames).' SQL files in path '.CONST_Tiger_Data_Path); + if (empty($aFilenames)) return; + $sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_start.sql'); $sTemplate = str_replace('{www-user}', CONST_Database_Web_User, $sTemplate); $sTemplate = $this->replaceTablespace( @@ -494,7 +484,7 @@ class SetupFunctions pg_ping($aDBInstances[$i]); } - foreach (glob(CONST_Tiger_Data_Path.'/*.sql') as $sFile) { + foreach ($aFilenames as $sFile) { echo $sFile.': '; $hFile = fopen($sFile, 'r'); $sSQL = fgets($hFile, 100000); @@ -729,9 +719,7 @@ class SetupFunctions } foreach ($aDropTables as $sDrop) { if ($this->bVerbose) echo "Dropping table $sDrop\n"; - $this->oDB->exec("DROP TABLE $sDrop CASCADE"); - // ignore warnings/errors as they might be caused by a table having - // been deleted already by CASCADE + $this->oDB->exec("DROP TABLE IF EXISTS $sDrop CASCADE"); } if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) { @@ -742,25 +730,6 @@ class SetupFunctions } } - private function pgsqlRunDropAndRestore($sDumpFile) - { - $sCMD = 'pg_restore' - .' -p '.escapeshellarg($this->aDSNInfo['port']) - .' -d '.escapeshellarg($this->aDSNInfo['database']) - .' --no-owner -Fc --clean '.escapeshellarg($sDumpFile); - if ($this->oDB->getPostgresVersion() >= 9.04) { - $sCMD .= ' --if-exists'; - } - if (isset($this->aDSNInfo['hostspec'])) { - $sCMD .= ' -h '.escapeshellarg($this->aDSNInfo['hostspec']); - } - if (isset($this->aDSNInfo['username'])) { - $sCMD .= ' -U '.escapeshellarg($this->aDSNInfo['username']); - } - - $this->runWithPgEnv($sCMD); - } - private function pgsqlRunScript($sScript, $bfatal = true) { runSQLScript(