X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/7c4b68d2ea30a0615b7159c80b18132b09efd97b..f17c5345ec0ec0b85347b6ccb1b50900d645b4b2:/utils/setup.php diff --git a/utils/setup.php b/utils/setup.php index 4b60815c..8254b6cc 100755 --- a/utils/setup.php +++ b/utils/setup.php @@ -219,7 +219,7 @@ if (file_exists($sWikiArticlesFile)) { echo "Importing wikipedia articles..."; - pgsqlRunRestoreData($sWikiArticlesFile); + pgsqlRunDropAndRestore($sWikiArticlesFile); echo "...done\n"; } else @@ -229,7 +229,7 @@ if (file_exists($sWikiRedirectsFile)) { echo "Importing wikipedia redirects..."; - pgsqlRunRestoreData($sWikiRedirectsFile); + pgsqlRunDropAndRestore($sWikiRedirectsFile); echo "...done\n"; } else @@ -562,3 +562,31 @@ proc_close($hProcess); } + + function pgsqlRunDropAndRestore($sDumpFile) + { + // Convert database DSN to psql paramaters + $aDSNInfo = DB::parseDSN(CONST_Database_DSN); + if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432; + $sCMD = 'pg_restore -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'].' -Fc --clean '.$sDumpFile; + + $aDescriptors = array( + 0 => array('pipe', 'r'), + 1 => array('pipe', 'w'), + 2 => array('file', '/dev/null', 'a') + ); + $ahPipes = null; + $hProcess = proc_open($sCMD, $aDescriptors, $ahPipes); + if (!is_resource($hProcess)) fail('unable to start pg_restore'); + + fclose($ahPipes[0]); + + // TODO: error checking + while(!feof($ahPipes[1])) + { + echo fread($ahPipes[1], 4096); + } + fclose($ahPipes[1]); + + proc_close($hProcess); + }