$aDSNInfo = DB::parseDSN(CONST_Database_DSN);
if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
+ $fPostgisVersion = (float) CONST_Postgis_Version;
+
if ($aCMDResult['create-db'] || $aCMDResult['all'])
{
echo "Create DB\n";
$oDB =& getDB();
$sVersionString = $oDB->getOne('select version()');
- preg_match('#PostgreSQL ([0-9]+)[.]([0-9]+)[.]([0-9]+) #', $sVersionString, $aMatches);
+ preg_match('#PostgreSQL ([0-9]+)[.]([0-9]+)[^0-9]#', $sVersionString, $aMatches);
if (CONST_Postgresql_Version != $aMatches[1].'.'.$aMatches[2])
{
echo "ERROR: PostgreSQL version is not correct. Expected ".CONST_Postgresql_Version." found ".$aMatches[1].'.'.$aMatches[2]."\n";
pgsqlRunScript('CREATE EXTENSION hstore');
}
- $fPostgisVersion = (float) CONST_Postgis_Version;
if ($fPostgisVersion < 2.0) {
pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/postgis.sql');
pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/spatial_ref_sys.sql');
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'])
{
showUsage($aCMDOptions, true);
}
+ else
+ {
+ echo "Setup finished.\n";
+ }
function pgsqlRunScriptFile($sFilename)
{
fclose($ahPipes[1]);
$iReturn = proc_close($hProcess);
- if ($iReturn > 0)
- {
- fail("pgsql returned with error code ($iReturn)");
- }
}
function pgsqlRunDropAndRestore($sDumpFile)
fclose($ahPipes[1]);
$iReturn = proc_close($hProcess);
- if ($iReturn > 0)
- {
- fail("pgsql returned with error code ($iReturn)");
- }
}
function passthruCheckReturn($cmd)