- $sTemplate = file_get_contents(CONST_BasePath.'/sql/functions.sql');
- $sTemplate = str_replace('{modulepath}', CONST_InstallPath.'/module', $sTemplate);
- if ($aCMDResult['enable-diff-updates']) $sTemplate = str_replace('RETURN NEW; -- @DIFFUPDATES@', '--', $sTemplate);
- if ($aCMDResult['enable-debug-statements']) $sTemplate = str_replace('--DEBUG:', '', $sTemplate);
- if (CONST_Limit_Reindexing) $sTemplate = str_replace('--LIMIT INDEXING:', '', $sTemplate);
- pgsqlRunScript($sTemplate);
-
- if ($fPostgisVersion < 2.0) {
- echo "Helper functions for postgis < 2.0\n";
- $sTemplate = file_get_contents(CONST_BasePath.'/sql/postgis_15_aux.sql');
- } else {
- echo "Helper functions for postgis >= 2.0\n";
- $sTemplate = file_get_contents(CONST_BasePath.'/sql/postgis_20_aux.sql');
- }
- pgsqlRunScript($sTemplate);
- }
-
- if ($aCMDResult['create-minimal-tables'])
- {
- echo "Minimal Tables\n";
- $bDidSomething = true;
- pgsqlRunScriptFile(CONST_BasePath.'/sql/tables-minimal.sql');
-
- $sScript = '';
-
- // Backstop the import process - easliest possible import id
- $sScript .= "insert into import_npi_log values (18022);\n";
-
- $hFile = @fopen(CONST_BasePath.'/settings/partitionedtags.def', "r");
- if (!$hFile) fail('unable to open list of partitions: '.CONST_BasePath.'/settings/partitionedtags.def');
-
- while (($sLine = fgets($hFile, 4096)) !== false && $sLine && substr($sLine,0,1) !='#')
- {
- list($sClass, $sType) = explode(' ', trim($sLine));
- $sScript .= "create table place_classtype_".$sClass."_".$sType." as ";
- $sScript .= "select place_id as place_id,geometry as centroid from placex limit 0;\n";
-
- $sScript .= "CREATE INDEX idx_place_classtype_".$sClass."_".$sType."_centroid ";
- $sScript .= "ON place_classtype_".$sClass."_".$sType." USING GIST (centroid);\n";
-
- $sScript .= "CREATE INDEX idx_place_classtype_".$sClass."_".$sType."_place_id ";
- $sScript .= "ON place_classtype_".$sClass."_".$sType." USING btree(place_id);\n";
- }
- fclose($hFile);
- pgsqlRunScript($sScript);