4 require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
5 ini_set('memory_limit', '800M');
8 "Create and setup nominatim search system",
9 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
10 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
11 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
13 array('osm-file', '', 0, 1, 1, 1, 'realpath', 'File to import'),
14 array('threads', '', 0, 1, 1, 1, 'int', 'Number of threads (where possible)'),
16 array('all', '', 0, 1, 0, 0, 'bool', 'Do the complete process'),
18 array('create-db', '', 0, 1, 0, 0, 'bool', 'Create nominatim db'),
19 array('setup-db', '', 0, 1, 0, 0, 'bool', 'Build a blank nominatim db'),
20 array('import-data', '', 0, 1, 0, 0, 'bool', 'Import a osm file'),
21 array('osm2pgsql-cache', '', 0, 1, 1, 1, 'int', 'Cache size used by osm2pgsql'),
22 array('create-functions', '', 0, 1, 0, 0, 'bool', 'Create functions'),
23 array('enable-diff-updates', '', 0, 1, 0, 0, 'bool', 'Turn on the code required to make diff updates work'),
24 array('enable-debug-statements', '', 0, 1, 0, 0, 'bool', 'Include debug warning statements in pgsql commands'),
25 array('create-minimal-tables', '', 0, 1, 0, 0, 'bool', 'Create minimal main tables'),
26 array('create-tables', '', 0, 1, 0, 0, 'bool', 'Create main tables'),
27 array('create-partitions', '', 0, 1, 0, 0, 'bool', 'Create required partition tables and triggers'),
28 array('import-wikipedia-articles', '', 0, 1, 0, 0, 'bool', 'Import wikipedia article dump'),
29 array('load-data', '', 0, 1, 0, 0, 'bool', 'Copy data to live tables from import table'),
30 array('disable-token-precalc', '', 0, 1, 0, 0, 'bool', 'Disable name precalculation (EXPERT)'),
31 array('import-tiger-data', '', 0, 1, 0, 0, 'bool', 'Import tiger data (not included in \'all\')'),
32 array('calculate-postcodes', '', 0, 1, 0, 0, 'bool', 'Calculate postcode centroids'),
33 array('create-roads', '', 0, 1, 0, 0, 'bool', 'Calculate postcode centroids'),
34 array('osmosis-init', '', 0, 1, 0, 0, 'bool', 'Generate default osmosis configuration'),
35 array('osmosis-init-date', '', 0, 1, 1, 1, 'string', 'Generate default osmosis configuration'),
36 array('index', '', 0, 1, 0, 0, 'bool', 'Index the data'),
37 array('index-noanalyse', '', 0, 1, 0, 0, 'bool', 'Do not perform analyse opertions during index (EXPERT)'),
38 array('index-output', '', 0, 1, 1, 1, 'string', 'File to dump index information to'),
39 array('create-search-indices', '', 0, 1, 0, 0, 'bool', 'Create additional indices required for search and update'),
40 array('create-website', '', 0, 1, 1, 1, 'realpath', 'Create symlinks to setup web directory'),
42 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
44 $bDidSomething = false;
46 // This is a pretty hard core defult - the number of processors in the box - 1
47 $iInstances = isset($aCMDResult['threads'])?$aCMDResult['threads']:(getProcessorCount()-1);
51 echo "WARNING: resetting threads to $iInstances\n";
53 if ($iInstances > getProcessorCount())
55 $iInstances = getProcessorCount();
56 echo "WARNING: resetting threads to $iInstances\n";
59 // Assume we can steal all the cache memory in the box (unless told otherwise)
60 $iCacheMemory = (isset($aCMDResult['osm2pgsql-cache'])?$aCMDResult['osm2pgsql-cache']:getCacheMemoryMB());
61 if ($iCacheMemory > getTotalMemoryMB())
63 $iCacheMemory = getCacheMemoryMB();
64 echo "WARNING: resetting cache memory to $iCacheMemory\n";
67 if (isset($aCMDResult['osm-file']) && !isset($aCMDResult['osmosis-init-date']))
69 $sBaseFile = basename($aCMDResult['osm-file']);
70 if (preg_match('#^planet-([0-9]{2})([0-9]{2})([0-9]{2})[.]#', $sBaseFile, $aMatch))
72 $iTime = mktime(0, 0, 0, $aMatch[2], $aMatch[3], '20'.$aMatch[1]);
74 $aCMDResult['osmosis-init-date'] = date('Y-m-d', $iTime).'T22:00:00Z';
77 $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
78 if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
80 if ($aCMDResult['create-db'] || $aCMDResult['all'])
83 $bDidSomething = true;
84 $oDB =& DB::connect(CONST_Database_DSN, false);
85 if (!PEAR::isError($oDB))
87 fail('database already exists ('.CONST_Database_DSN.')');
89 passthru('createdb -E UTF-8 '.$aDSNInfo['database']);
92 if ($aCMDResult['create-db'] || $aCMDResult['all'])
94 echo "Create DB (2)\n";
95 $bDidSomething = true;
96 // TODO: path detection, detection memory, etc.
99 passthru('createlang plpgsql '.$aDSNInfo['database']);
100 $pgver = (float) CONST_Postgresql_Version;
102 pgsqlRunScriptFile(CONST_Path_Postgresql_Contrib.'/hstore.sql');
104 pgsqlRunScript('CREATE EXTENSION hstore');
106 pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/postgis.sql');
107 pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/spatial_ref_sys.sql');
108 pgsqlRunScriptFile(CONST_BasePath.'/data/country_name.sql');
109 pgsqlRunScriptFile(CONST_BasePath.'/data/country_naturalearthdata.sql');
110 pgsqlRunScriptFile(CONST_BasePath.'/data/country_osm_grid.sql');
111 pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode.sql');
112 pgsqlRunScriptFile(CONST_BasePath.'/data/us_statecounty.sql');
113 pgsqlRunScriptFile(CONST_BasePath.'/data/us_state.sql');
114 pgsqlRunScriptFile(CONST_BasePath.'/data/us_postcode.sql');
115 pgsqlRunScriptFile(CONST_BasePath.'/data/worldboundaries.sql');
118 if ($aCMDResult['import-data'] || $aCMDResult['all'])
121 $bDidSomething = true;
123 $osm2pgsql = CONST_Osm2pgsql_Binary;
124 if (!file_exists($osm2pgsql)) fail("please download and build osm2pgsql");
125 $osm2pgsql .= ' -lsc -O gazetteer --hstore';
126 $osm2pgsql .= ' -C '.$iCacheMemory;
127 $osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file'];
128 passthru($osm2pgsql);
131 $x = $oDB->getRow('select * from place limit 1');
132 if (PEAR::isError($x)) {
133 fail($x->getMessage());
135 if (!$x) fail('No Data');
138 if ($aCMDResult['create-functions'] || $aCMDResult['all'])
141 $bDidSomething = true;
142 if (!file_exists(CONST_BasePath.'/module/nominatim.so')) fail("nominatim module not built");
143 $sTemplate = file_get_contents(CONST_BasePath.'/sql/functions.sql');
144 $sTemplate = str_replace('{modulepath}', CONST_BasePath.'/module', $sTemplate);
145 if ($aCMDResult['enable-diff-updates']) $sTemplate = str_replace('RETURN NEW; -- @DIFFUPDATES@', '--', $sTemplate);
146 if ($aCMDResult['enable-debug-statements']) $sTemplate = str_replace('--DEBUG:', '', $sTemplate);
147 pgsqlRunScript($sTemplate);
150 if ($aCMDResult['create-minimal-tables'])
152 echo "Minimal Tables\n";
153 $bDidSomething = true;
154 pgsqlRunScriptFile(CONST_BasePath.'/sql/tables-minimal.sql');
158 // Backstop the import process - easliest possible import id
159 $sScript .= "insert into import_npi_log values (18022);\n";
161 $hFile = @fopen(CONST_BasePath.'/settings/partitionedtags.def', "r");
162 if (!$hFile) fail('unable to open list of partitions: '.CONST_BasePath.'/settings/partitionedtags.def');
164 while (($sLine = fgets($hFile, 4096)) !== false && $sLine && substr($sLine,0,1) !='#')
166 list($sClass, $sType) = explode(' ', trim($sLine));
167 $sScript .= "create table place_classtype_".$sClass."_".$sType." as ";
168 $sScript .= "select place_id as place_id,geometry as centroid from placex limit 0;\n";
170 $sScript .= "CREATE INDEX idx_place_classtype_".$sClass."_".$sType."_centroid ";
171 $sScript .= "ON place_classtype_".$sClass."_".$sType." USING GIST (centroid);\n";
173 $sScript .= "CREATE INDEX idx_place_classtype_".$sClass."_".$sType."_place_id ";
174 $sScript .= "ON place_classtype_".$sClass."_".$sType." USING btree(place_id);\n";
177 pgsqlRunScript($sScript);
180 if ($aCMDResult['create-tables'] || $aCMDResult['all'])
183 $bDidSomething = true;
184 pgsqlRunScriptFile(CONST_BasePath.'/sql/tables.sql');
186 // re-run the functions
187 $sTemplate = file_get_contents(CONST_BasePath.'/sql/functions.sql');
188 $sTemplate = str_replace('{modulepath}',CONST_BasePath.'/module', $sTemplate);
189 pgsqlRunScript($sTemplate);
192 if ($aCMDResult['create-partitions'] || $aCMDResult['all'])
195 $bDidSomething = true;
197 $sSQL = 'select partition from country_name order by country_code';
198 $aPartitions = $oDB->getCol($sSQL);
199 if (PEAR::isError($aPartitions))
201 fail($aPartitions->getMessage());
205 $sTemplate = file_get_contents(CONST_BasePath.'/sql/partitions.src.sql');
206 preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER);
207 foreach($aMatches as $aMatch)
210 foreach($aPartitions as $sPartitionName)
212 $sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]);
214 $sTemplate = str_replace($aMatch[0], $sResult, $sTemplate);
217 pgsqlRunScript($sTemplate);
220 if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all'])
222 $bDidSomething = true;
223 $sWikiArticlesFile = CONST_BasePath.'/data/wikipedia_article.sql.bin';
224 $sWikiRedirectsFile = CONST_BasePath.'/data/wikipedia_redirect.sql.bin';
225 if (file_exists($sWikiArticlesFile))
227 echo "Importing wikipedia articles...";
228 pgsqlRunDropAndRestore($sWikiArticlesFile);
233 echo "WARNING: wikipedia article dump file not found - places will have default importance\n";
235 if (file_exists($sWikiRedirectsFile))
237 echo "Importing wikipedia redirects...";
238 pgsqlRunDropAndRestore($sWikiRedirectsFile);
243 echo "WARNING: wikipedia redirect dump file not found - some place importance values may be missing\n";
248 if ($aCMDResult['load-data'] || $aCMDResult['all'])
251 $bDidSomething = true;
254 if (!pg_query($oDB->connection, 'TRUNCATE word')) fail(pg_last_error($oDB->connection));
256 if (!pg_query($oDB->connection, 'TRUNCATE placex')) fail(pg_last_error($oDB->connection));
258 if (!pg_query($oDB->connection, 'TRUNCATE place_addressline')) fail(pg_last_error($oDB->connection));
260 if (!pg_query($oDB->connection, 'TRUNCATE place_boundingbox')) fail(pg_last_error($oDB->connection));
262 if (!pg_query($oDB->connection, 'TRUNCATE location_area')) fail(pg_last_error($oDB->connection));
264 if (!pg_query($oDB->connection, 'TRUNCATE search_name')) fail(pg_last_error($oDB->connection));
266 if (!pg_query($oDB->connection, 'TRUNCATE search_name_blank')) fail(pg_last_error($oDB->connection));
268 if (!pg_query($oDB->connection, 'DROP SEQUENCE seq_place')) fail(pg_last_error($oDB->connection));
270 if (!pg_query($oDB->connection, 'CREATE SEQUENCE seq_place start 100000')) fail(pg_last_error($oDB->connection));
273 $sSQL = 'select partition from country_name order by country_code';
274 $aPartitions = $oDB->getCol($sSQL);
275 if (PEAR::isError($aPartitions))
277 fail($aPartitions->getMessage());
280 foreach($aPartitions as $sPartition)
282 if (!pg_query($oDB->connection, 'TRUNCATE location_road_'.$sPartition)) fail(pg_last_error($oDB->connection));
286 // pre-create the word list
287 if (!$aCMDResult['disable-token-precalc'])
289 if (!pg_query($oDB->connection, 'select count(make_keywords(v)) from (select distinct svals(name) as v from place) as w where v is not null;')) fail(pg_last_error($oDB->connection));
291 if (!pg_query($oDB->connection, 'select count(make_keywords(v)) from (select distinct postcode as v from place) as w where v is not null;')) fail(pg_last_error($oDB->connection));
293 if (!pg_query($oDB->connection, 'select count(getorcreate_housenumber_id(v)) from (select distinct housenumber as v from place where housenumber is not null) as w;')) fail(pg_last_error($oDB->connection));
297 $aDBInstances = array();
298 for($i = 0; $i < $iInstances; $i++)
300 $aDBInstances[$i] =& getDB(true);
301 $sSQL = 'insert into placex (osm_type, osm_id, class, type, name, admin_level, ';
302 $sSQL .= 'housenumber, street, isin, postcode, country_code, extratags, ';
303 $sSQL .= 'geometry) select * from place where osm_id % '.$iInstances.' = '.$i;
304 if ($aCMDResult['verbose']) echo "$sSQL\n";
305 if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection));
311 for($i = 0; $i < $iInstances; $i++)
313 if (pg_connection_busy($aDBInstances[$i]->connection)) $bAnyBusy = true;
319 echo "Reanalysing database...\n";
320 pgsqlRunScript('ANALYSE');
323 if ($aCMDResult['create-roads'])
325 $bDidSomething = true;
328 $aDBInstances = array();
329 for($i = 0; $i < $iInstances; $i++)
331 $aDBInstances[$i] =& getDB(true);
332 if (!pg_query($aDBInstances[$i]->connection, 'set enable_bitmapscan = off')) fail(pg_last_error($oDB->connection));
333 $sSQL = 'select count(*) from (select insertLocationRoad(partition, place_id, country_code, geometry) from ';
334 $sSQL .= 'placex where osm_id % '.$iInstances.' = '.$i.' and rank_search between 26 and 27 and class = \'highway\') as x ';
335 if ($aCMDResult['verbose']) echo "$sSQL\n";
336 if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection));
342 for($i = 0; $i < $iInstances; $i++)
344 if (pg_connection_busy($aDBInstances[$i]->connection)) $bAnyBusy = true;
352 if ($aCMDResult['import-tiger-data'])
354 $bDidSomething = true;
356 $aDBInstances = array();
357 for($i = 0; $i < $iInstances; $i++)
359 $aDBInstances[$i] =& getDB(true);
362 foreach(glob(CONST_BasePath.'/data/tiger2011/*.sql') as $sFile)
365 $hFile = fopen($sFile, "r");
366 $sSQL = fgets($hFile, 100000);
371 for($i = 0; $i < $iInstances; $i++)
373 if (!pg_connection_busy($aDBInstances[$i]->connection))
375 while(pg_get_result($aDBInstances[$i]->connection));
376 $sSQL = fgets($hFile, 100000);
378 if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection));
396 for($i = 0; $i < $iInstances; $i++)
398 if (pg_connection_busy($aDBInstances[$i]->connection)) $bAnyBusy = true;
406 if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all'])
408 $bDidSomething = true;
410 if (!pg_query($oDB->connection, 'DELETE from placex where osm_type=\'P\'')) fail(pg_last_error($oDB->connection));
411 $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,country_code,geometry) ";
412 $sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,country_code,";
413 $sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from (select country_code,postcode,";
414 $sSQL .= "avg(st_x(st_centroid(geometry))) as x,avg(st_y(st_centroid(geometry))) as y ";
415 $sSQL .= "from placex where postcode is not null group by country_code,postcode) as x";
416 if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection));
418 $sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,country_code,geometry) ";
419 $sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,'us',";
420 $sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from us_postcode";
421 if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection));
424 if (($aCMDResult['osmosis-init'] || $aCMDResult['all']) && isset($aCMDResult['osmosis-init-date']))
426 $bDidSomething = true;
429 if (!file_exists(CONST_Osmosis_Binary)) fail("please download osmosis");
430 if (file_exists(CONST_BasePath.'/settings/configuration.txt')) echo "settings/configuration.txt already exists\n";
431 else passthru(CONST_Osmosis_Binary.' --read-replication-interval-init '.CONST_BasePath.'/settings');
433 $sDate = $aCMDResult['osmosis-init-date'];
434 $aDate = date_parse_from_format("Y-m-d\TH-i", $sDate);
435 $sURL = 'http://toolserver.org/~mazder/replicate-sequences/?';
436 $sURL .= 'Y='.$aDate['year'].'&m='.$aDate['month'].'&d='.$aDate['day'];
437 $sURL .= '&H='.$aDate['hour'].'&i='.$aDate['minute'].'&s=0';
438 $sURL .= '&stream=minute';
439 echo "Getting state file: $sURL\n";
440 $sStateFile = file_get_contents($sURL);
441 if (!$sStateFile || strlen($sStateFile) > 1000) fail("unable to obtain state file");
442 file_put_contents(CONST_BasePath.'/settings/state.txt', $sStateFile);
443 echo "Updating DB status\n";
444 pg_query($oDB->connection, 'TRUNCATE import_status');
445 $sSQL = "INSERT INTO import_status VALUES('".$sDate."')";
446 pg_query($oDB->connection, $sSQL);
450 if ($aCMDResult['index'] || $aCMDResult['all'])
452 $bDidSomething = true;
454 if (isset($aCMDResult['index-output'])) $sOutputFile = ' -F '.$aCMDResult['index-output'];
455 $sBaseCmd = CONST_BasePath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -t '.$iInstances.$sOutputFile;
456 passthru($sBaseCmd.' -R 4');
457 if (!$aCMDResult['index-noanalyse']) pgsqlRunScript('ANALYSE');
458 passthru($sBaseCmd.' -r 5 -R 25');
459 if (!$aCMDResult['index-noanalyse']) pgsqlRunScript('ANALYSE');
460 passthru($sBaseCmd.' -r 26');
463 if ($aCMDResult['create-search-indices'] || $aCMDResult['all'])
465 echo "Search indices\n";
466 $bDidSomething = true;
468 $sSQL = 'select partition from country_name order by country_code';
469 $aPartitions = $oDB->getCol($sSQL);
470 if (PEAR::isError($aPartitions))
472 fail($aPartitions->getMessage());
476 $sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql');
477 preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER);
478 foreach($aMatches as $aMatch)
481 foreach($aPartitions as $sPartitionName)
483 $sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]);
485 $sTemplate = str_replace($aMatch[0], $sResult, $sTemplate);
488 pgsqlRunScript($sTemplate);
491 if (isset($aCMDResult['create-website']))
493 $bDidSomething = true;
494 $sTargetDir = $aCMDResult['create-website'];
495 if (!is_dir($sTargetDir)) fail('please specify a directory to setup');
496 @symlink(CONST_BasePath.'/website/details.php', $sTargetDir.'/details.php');
497 @symlink(CONST_BasePath.'/website/reverse.php', $sTargetDir.'/reverse.php');
498 @symlink(CONST_BasePath.'/website/search.php', $sTargetDir.'/search.php');
499 @symlink(CONST_BasePath.'/website/search.php', $sTargetDir.'/index.php');
500 @symlink(CONST_BasePath.'/website/images', $sTargetDir.'/images');
501 @symlink(CONST_BasePath.'/website/js', $sTargetDir.'/js');
502 echo "Symlinks created\n";
507 showUsage($aCMDOptions, true);
510 function pgsqlRunScriptFile($sFilename)
512 if (!file_exists($sFilename)) fail('unable to find '.$sFilename);
514 // Convert database DSN to psql paramaters
515 $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
516 if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
517 $sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'].' -f '.$sFilename;
519 $aDescriptors = array(
520 0 => array('pipe', 'r'),
521 1 => array('pipe', 'w'),
522 2 => array('file', '/dev/null', 'a')
525 $hProcess = proc_open($sCMD, $aDescriptors, $ahPipes);
526 if (!is_resource($hProcess)) fail('unable to start pgsql');
530 // TODO: error checking
531 while(!feof($ahPipes[1]))
533 echo fread($ahPipes[1], 4096);
537 proc_close($hProcess);
540 function pgsqlRunScript($sScript)
542 // Convert database DSN to psql paramaters
543 $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
544 if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
545 $sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'];
546 $aDescriptors = array(
547 0 => array('pipe', 'r'),
552 $hProcess = @proc_open($sCMD, $aDescriptors, $ahPipes);
553 if (!is_resource($hProcess)) fail('unable to start pgsql');
555 while(strlen($sScript))
557 $written = fwrite($ahPipes[0], $sScript);
558 $sScript = substr($sScript, $written);
561 proc_close($hProcess);
564 function pgsqlRunRestoreData($sDumpFile)
566 // Convert database DSN to psql paramaters
567 $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
568 if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
569 $sCMD = 'pg_restore -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'].' -Fc -a '.$sDumpFile;
571 $aDescriptors = array(
572 0 => array('pipe', 'r'),
573 1 => array('pipe', 'w'),
574 2 => array('file', '/dev/null', 'a')
577 $hProcess = proc_open($sCMD, $aDescriptors, $ahPipes);
578 if (!is_resource($hProcess)) fail('unable to start pg_restore');
582 // TODO: error checking
583 while(!feof($ahPipes[1]))
585 echo fread($ahPipes[1], 4096);
589 proc_close($hProcess);
592 function pgsqlRunDropAndRestore($sDumpFile)
594 // Convert database DSN to psql paramaters
595 $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
596 if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
597 $sCMD = 'pg_restore -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'].' -Fc --clean '.$sDumpFile;
599 $aDescriptors = array(
600 0 => array('pipe', 'r'),
601 1 => array('pipe', 'w'),
602 2 => array('file', '/dev/null', 'a')
605 $hProcess = proc_open($sCMD, $aDescriptors, $ahPipes);
606 if (!is_resource($hProcess)) fail('unable to start pg_restore');
610 // TODO: error checking
611 while(!feof($ahPipes[1]))
613 echo fread($ahPipes[1], 4096);
617 proc_close($hProcess);