protected $sIgnoreErrors;
protected $bEnableDiffUpdates;
protected $bEnableDebugStatements;
- protected $bNoPartitions;
protected $bDrop;
protected $oDB = null;
protected $oNominatimCmd;
} else {
$this->bEnableDebugStatements = false;
}
- if (isset($aCMDResult['no-partitions'])) {
- $this->bNoPartitions = $aCMDResult['no-partitions'];
- } else {
- $this->bNoPartitions = false;
- }
if (isset($aCMDResult['enable-diff-updates'])) {
$this->bEnableDiffUpdates = $aCMDResult['enable-diff-updates'];
} else {
$this->createSqlFunctions();
}
- public function createTables($bReverseOnly = false)
- {
- info('Create Tables');
-
- $sTemplate = file_get_contents(CONST_SqlDir.'/tables.sql');
- $sTemplate = $this->replaceSqlPatterns($sTemplate);
-
- $this->pgsqlRunScript($sTemplate, false);
-
- if ($bReverseOnly) {
- $this->dropTable('search_name');
- }
-
- (clone($this->oNominatimCmd))->addParams('refresh', '--address-levels')->run();
- }
-
- public function createTableTriggers()
- {
- info('Create Tables');
-
- $sTemplate = file_get_contents(CONST_SqlDir.'/table-triggers.sql');
- $sTemplate = $this->replaceSqlPatterns($sTemplate);
-
- $this->pgsqlRunScript($sTemplate, false);
- }
-
- public function createPartitionTables()
- {
- info('Create Partition Tables');
-
- $sTemplate = file_get_contents(CONST_SqlDir.'/partition-tables.src.sql');
- $sTemplate = $this->replaceSqlPatterns($sTemplate);
-
- $this->pgsqlRunPartitionScript($sTemplate);
- }
-
public function importTigerData($sTigerPath)
{
info('Import Tiger data');
$oCmd->run(!$this->sIgnoreErrors);
}
- private function pgsqlRunPartitionScript($sTemplate)
- {
- $sSQL = 'select distinct partition from country_name';
- $aPartitions = $this->db()->getCol($sSQL);
- if (!$this->bNoPartitions) $aPartitions[] = 0;
-
- preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER);
- foreach ($aMatches as $aMatch) {
- $sResult = '';
- foreach ($aPartitions as $sPartitionName) {
- $sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]);
- }
- $sTemplate = str_replace($aMatch[0], $sResult, $sTemplate);
- }
-
- $this->pgsqlRunScript($sTemplate);
- }
-
private function pgsqlRunScriptFile($sFilename)
{
if (!file_exists($sFilename)) fail('unable to find '.$sFilename);