fixed jengos problems

This commit is contained in:
seek3r 2001-01-02 08:11:00 +00:00
parent f2710edd85
commit b463fe28e4
5 changed files with 443 additions and 18 deletions

View File

@ -33,6 +33,8 @@
$phpgw_info["server"]["app_images"] = "templates/default/images";
if(!file_exists("../header.inc.php")) { include("../header.inc.php"); }
include("./inc/phpgw_setup.inc.php");
include("./inc/phpgw_schema_proc.inc.php");
$phpgw_setup = new phpgw_setup;

View File

@ -1,31 +1,58 @@
<?php
/**************************************************************************\
* phpGroupWare - Setup *
* http://www.phpgroupware.org *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
class phpgw_schema_proc
{
var $m_oTranslator;
var $m_odb;
var $m_aTables;
function phpgw_schema_proc($dbms)
{
include("./inc/phpgw_schema_proc_" . $dbms . ".inc.php");
eval("\$this->m_oTranslator = new phpgw_schema_proc_$dbms;");
global $phpgw_setup;
$this->m_odb = &$phpgw_setup->db;
$this->m_aTables = array();
}
function GenerateScripts($aTables, $bOutputHTML = false)
function GenerateScripts(&$aTables, $bOutputHTML = false)
{
if (!is_array($aTables))
return false;
reset($aTables);
$this->m_aTables = &$aTables;
reset($this->m_aTables);
$sAllTableSQL = "";
while (list($sTableName, $aTableDef) = each($aTables))
while (list($sTableName, $aTableDef) = each($this->m_aTables))
{
if ($this->_GetTableSQL($aTableDef, $sTableSQL))
$sSequenceSQL = "";
if ($this->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL))
{
$sTableSQL = "CREATE TABLE $sTableName (\n$sTableSQL\n)"
. $this->m_oTranslator->m_sStatementTerminator;
if ($sSequenceSQL != "")
$sAllTableSQL .= $sSequenceSQL . "\n";
$sAllTableSQL .= $sTableSQL . "\n\n";
}
else
{
if ($bOutputHTML)
print("<br>Failed generating script for <b>$sTableName</b><br>");
return false;
}
}
if ($bOutputHTML)
@ -34,14 +61,93 @@ class phpgw_schema_proc
return true;
}
function _GetTableSQL($aTableDef, &$sTableSQL)
function ExecuteScripts(&$aTables, $bOutputHTML = false)
{
if (!is_array($aTables) || !IsSet($this->m_odb))
return false;
$this->m_aTables = &$aTables;
reset($this->m_aTables);
while (list($sTableName, $aTableDef) = each($this->m_aTables))
{
if ($this->CreateTable($sTableName, $aTableDef))
{
if ($bOutputHTML)
echo "<br>Create Table <b>$sTableSQL</b>";
}
else
return false;
}
return true;
}
function DropAllTables(&$aTables, $bOutputHTML = false)
{
if (!is_array($aTables) || !IsSet($this->m_odb))
return false;
$this->m_aTables = &$aTables;
reset($this->m_aTables);
while (list($sTableName, $aTableDef) = each($this->m_aTables))
{
if ($this->DropTable($sTableName))
{
if ($bOutputHTML)
echo "<br>Drop Table <b>$sTableSQL</b>";
}
else
return false;
}
return true;
}
function DropTable($sTableName)
{
return $this->m_oTranslator->DropTable($this, $sTableName);
}
function DropColumn($sTableName, $aTableDef, $sColumnName, $bCopyData = true)
{
return $this->m_oTranslator->DropColumn($this, $sTableName, $aTableDef, $sColumnName, $bCopyData);
}
function RenameTable($sOldTableName, $sNewTableName)
{
return $this->m_oTranslator->RenameTable($this, $sOldTableName, $sNewTableName);
}
function RenameColumn($sTableName, $sOldColumnName, $sNewColumnName, $bCopyData = true)
{
return $this->m_oTranslator->RenameColumn($this, $sTableName, $sOldColumnName, $sNewColumnName, $bCopyData);
}
function AlterColumn($sTableName, $sColumnName, $aColumnDef, $bCopyData = true)
{
return $this->m_oTranslator->AlterColumn($this, $sTableName, $sColumnName, $aColumnDef, $bCopyData);
}
function AddColumn($sTableName, $sColumnName, $aColumnDef)
{
return $this->m_oTranslator->AddColumn($this, $sTableName, $sColumnName, $aColumnDef);
}
function CreateTable($sTableName, $aTableDef)
{
return $this->m_oTranslator->CreateTable($this, $sTableName, $aTableDef);
}
function _GetTableSQL($sTableName, $aTableDef, &$sTableSQL, &$sSequenceSQL)
{
if (!is_array($aTableDef))
return false;
$sTableSQL = "";
reset($aTableDef);
while (list($sFieldName, $aFieldAttr) = each($aTableDef))
reset($aTableDef["fd"]);
while (list($sFieldName, $aFieldAttr) = each($aTableDef["fd"]))
{
$sFieldSQL = "";
if ($this->_GetFieldSQL($aFieldAttr, $sFieldSQL))
@ -50,11 +156,49 @@ class phpgw_schema_proc
$sTableSQL .= ",\n";
$sTableSQL .= "$sFieldName $sFieldSQL";
if ($aFieldAttr["type"] == "auto")
{
$this->m_oTranslator->GetSequenceSQL($sTableName, $sFieldName, $sSequenceSQL);
if ($sSequenceSQL != "")
{
$sTableSQL .= sprintf(" DEFAULT nextval('%s_%s_seq')", $sTableName, $sFieldName);
}
}
}
else
return false;
}
$sUCSQL = "";
$sPKSQL = "";
if (count($aTableDef["pk"]) > 0)
{
if (!$this->_GetPK($aTableDef["pk"], $sPKSQL))
{
if ($bOutputHTML)
print("<br>Failed getting primary key<br>");
return false;
}
}
if (count($aTableDef["uc"]) > 0)
{
if (!$this->_GetUC($aTableDef["uc"], $sUCSQL))
{
if ($bOutputHTML)
print("<br>Failed getting unique constraint<br>");
return false;
}
}
if ($sPKSQL != "")
$sTableSQL .= ",\n" . $sPKSQL;
if ($sUCSQL != "")
$sTableSQL .= ",\n" . $sUCSQL;
return true;
}
@ -68,7 +212,7 @@ class phpgw_schema_proc
$iPrecision = 0;
$iScale = 0;
$sDefault = "";
$bNullable = false;
$bNullable = true;
reset($aField);
while (list($sAttr, $vAttrVal) = each($aField))
@ -109,7 +253,49 @@ class phpgw_schema_proc
return true;
}
print("<br>Failed to translate field: type[$sType] precision[$iPrecision] scale[$iScale]<br>");
return false;
}
}
function _GetPK($aFields, &$sPKSQL)
{
$sPKSQL = "";
if (count($aFields) < 1)
return true;
$sFields = "";
reset($aFields);
while (list($key, $sField) = each($aFields))
{
if ($sFields != "")
$sFields .= ",";
$sFields .= $sField;
}
$sPKSQL = $this->m_oTranslator->GetPKSQL($sFields);
return true;
}
function _GetUC($aFields, &$sUCSQL)
{
$sUCSQL = "";
if (count($aFields) < 1)
return true;
$sFields = "";
reset($aFields);
while (list($key, $sField) = each($aFields))
{
if ($sFields != "")
$sFields .= ",";
$sFields .= $sField;
}
$sUCSQL = $this->m_oTranslator->GetUCSQL($sFields);
return true;
}
}
?>

View File

@ -14,8 +14,11 @@ class phpgw_schema_proc_mysql
$sTranslated = "";
switch($sType)
{
case "autoincrement":
$sTranslated = "auto_increment";
case "auto":
$sTranslated = "int(11) auto_increment";
break;
case "blob":
$sTranslated = "blob";
break;
case "char":
if ($iPrecision > 0 && $iPrecision < 256)
@ -56,14 +59,20 @@ class phpgw_schema_proc_mysql
break;
}
break;
case "text":
$sTranslated = "text";
break;
case "timestamp":
$sTranslated = "datetime";
$sTranslated = "datetime";
break;
case "varchar":
if ($iPrecision > 0 && $iPrecision < 256)
$sTranslated = sprintf("varchar(%d)", $iPrecision);
if ($iPrecision > 255)
$sTranslated = "text";
break;
}
return (strlen($sTranslated) > 0);
@ -80,5 +89,93 @@ class phpgw_schema_proc_mysql
return $sDefault;
}
function GetPKSQL($sFields)
{
return "PRIMARY KEY($sFields)";
}
function GetUCSQL($sFields)
{
return "UNIQUE($sFields)";
}
function _GetColumns(&$oProc, $sTableName, &$sColumns, $sDropColumn = "")
{
$sColumns = "";
$oProc->m_odb->query("describe $sTableName");
while ($oProc->m_odb->next_record())
{
if ($sColumns != "")
$sColumns .= ",";
$sColumns .= $oProc->m_odb->f(0);
}
return false;
}
function DropTable(&$oProc, $sTableName)
{
return !!($oProc->m_odb->query("DROP TABLE " . $sTableName));
}
function DropColumn(&$oProc, $sTableName, $aNewTableDef, $sColumnName, $bCopyData = true)
{
return !!($oProc->m_odb->query("ALTER TABLE $sTableName DROP COLUMN $sColumnName"));
}
function RenameTable(&$oProc, $sOldTableName, $sNewTableName)
{
return !!($oProc->m_odb->query("ALTER TABLE $sOldTableName RENAME TO $sNewTableName"));
}
function RenameColumn(&$oProc, $sTableName, $sOldColumnName, $sNewColumnName, $bCopyData = true)
{
// This really needs testing - it can affect primary keys, and other table-related objects
// like sequences and such
if ($oProc->_GetFieldSQL($oProc->m_aTables[$sTableName]["fd"][$sNewColumnName], $sNewColumnSQL))
return !!($oProc->m_odb->query("ALTER TABLE $sTableName CHANGE $sOldColumnName $sNewColumnName " . $sNewColumnSQL));
return false;
}
function AlterColumn(&$oProc, $sTableName, $sColumnName, &$aColumnDef, $bCopyData = true)
{
if ($oProc->_GetFieldSQL($oProc->m_aTables[$sTableName]["fd"][$sColumnName], $sNewColumnSQL))
return !!($oProc->m_odb->query("ALTER TABLE $sTableName MODIFY $sColumnName " . $sNewColumnSQL));
return false;
}
function AddColumn(&$oProc, $sTableName, $sColumnName, &$aColumnDef)
{
$oProc->_GetFieldSQL($aColumnDef, $sFieldSQL);
$query = "ALTER TABLE $sTableName ADD COLUMN $sColumnName $sFieldSQL";
return !!($oProc->m_odb->query($query));
}
function GetSequenceSQL($sTableName, $sFieldName, &$sSequenceSQL)
{
$sSequenceSQL = "";
return true;
}
function CreateTable(&$oProc, $sTableName, $aTableDef)
{
if ($oProc->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL))
{
// create sequence first since it will be needed for default
if ($sSequenceSQL != "")
$oProc->m_odb->query($sSequenceSQL);
$query = "CREATE TABLE $sTableName ($sTableSQL)";
return !!($oProc->m_odb->query($query));
}
return false;
}
}
?>

View File

@ -1,4 +1,16 @@
<?php
/**************************************************************************\
* phpGroupWare - Setup *
* http://www.phpgroupware.org *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
class phpgw_schema_proc_pgsql
{
var $m_sStatementTerminator;
@ -13,8 +25,11 @@ class phpgw_schema_proc_pgsql
{
switch($sType)
{
case "autoincrement":
$sTranslated = "serial";
case "auto":
$sTranslated = "int4";
break;
case "blob":
$sTranslated = "text";
break;
case "char":
if ($iPrecision > 0 && $iPrecision < 256)
@ -39,6 +54,9 @@ class phpgw_schema_proc_pgsql
if ($iPrecision == 2 || $iPrecision == 4 || $iPrecision == 8)
$sTranslated = sprintf("int%d", $iPrecision);
break;
case "text":
$sTranslated = "text";
break;
case "timestamp":
$sTranslated = "timestamp";
@ -67,5 +85,128 @@ class phpgw_schema_proc_pgsql
return $sDefault;
}
function GetPKSQL($sFields)
{
return "PRIMARY KEY($sFields)";
}
function GetUCSQL($sFields)
{
return "UNIQUE($sFields)";
}
function _GetColumns(&$oProc, $sTableName, &$sColumns, $sDropColumn = "")
{
$sColumns = "";
$query = "SELECT a.attname FROM pg_attribute a,pg_class b WHERE ";
$query .= "a.oid=b.attrelid AND a.attnum>0 and b.relname='$sTableName'";
if ($sDropColumn != "")
$query .= " AND a.attname != '$sDropColumn'";
$query .= " ORDER BY a.attnum";
$oProc->m_odb->query($query);
while ($oProc->m_odb->next_record())
{
if ($sColumns != "")
$sColumns .= ",";
$sColumns .= $oProc->m_odb->f(0);
}
return false;
}
function DropTable(&$oProc, $sTableName)
{
return !!($oProc->m_odb->query("DROP TABLE " . $sTableName));
}
function DropColumn(&$oProc, $sTableName, $aNewTableDef, $sColumnName, $bCopyData = true)
{
if ($bCopyData)
$oProc->m_odb->query("ALTER TABLE $sTableName RENAME TO $sTableName" . "_tmp");
else
$this->DropTable($oProc, $sTableName);
$oProc->_GetTableSQL($sTableName, $aNewTableDef, $sTableSQL);
$query = "CREATE TABLE $sTableName ($sTableSQL)";
if (!$bCopyData)
return !!($oProc->m_odb->query($query));
$oProc->m_odb->query($query);
$this->_GetColumns($oProc, $sTableName . "_tmp", $sColumns, $sColumnName);
$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp";
return !!($oProc->m_odb->query($query));
}
function RenameTable(&$oProc, $sOldTableName, $sNewTableName)
{
return !!($oProc->m_odb->query("ALTER TABLE $sOldTableName RENAME TO $sNewTableName"));
}
function RenameColumn(&$oProc, $sTableName, $sOldColumnName, $sNewColumnName, $bCopyData = true)
{
// This really needs testing - it can affect primary keys, and other table-related objects
// like sequences and such
if ($bCopyData)
$oProc->m_odb->query("ALTER TABLE $sTableName RENAME TO $sTableName" . "_tmp");
else
$this->DropTable($oProc, $sTableName);
if (!$bCopyData)
return $this->CreateTable($oProc, $sTableName, $oProc->m_aTables[$sTableName]);
$this->CreateTable($oProc, $sTableName, $oProc->m_aTables[$sTableName]);
$this->_GetColumns($oProc, $sTableName . "_tmp", $sColumns);
$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp";
return !!($oProc->m_odb->query($query));
}
function AlterColumn(&$oProc, $sTableName, $sColumnName, &$aColumnDef, $bCopyData = true)
{
if ($bCopyData)
$oProc->m_odb->query("ALTER TABLE $sTableName RENAME TO $sTableName" . "_tmp");
else
$this->DropTable($oProc, $sTableName);
if (!$bCopyData)
return $this->CreateTable($oProc, $sTableName, $oProc->m_aTables[$sTableName]);
$this->CreateTable($oProc, $sTableName, $oProc->m_aTables[$sTableName]);
$this->_GetColumns($oProc, $sTableName . "_tmp", $sColumns);
$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp";
return !!($oProc->m_odb->query($query));
}
function AddColumn(&$oProc, $sTableName, $sColumnName, &$aColumnDef)
{
$oProc->_GetFieldSQL($aColumnDef, $sFieldSQL);
$query = "ALTER TABLE $sTableName ADD COLUMN $sColumnName $sFieldSQL";
return !!($oProc->m_odb->query($query));
}
function GetSequenceSQL($sTableName, $sFieldName, &$sSequenceSQL)
{
$sSequenceSQL = sprintf("CREATE SEQUENCE %s_%s_seq", $sTableName, $sFieldName);
return true;
}
function CreateTable(&$oProc, $sTableName, $aTableDef)
{
if ($oProc->_GetTableSQL($sTableName, $aTableDef, $sTableSQL, $sSequenceSQL))
{
// create sequence first since it will be needed for default
if ($sSequenceSQL != "")
$oProc->m_odb->query($sSequenceSQL);
$query = "CREATE TABLE $sTableName ($sTableSQL)";
return !!($oProc->m_odb->query($query));
}
return false;
}
}
?>

View File

@ -83,7 +83,6 @@
$phpgw_info["setup"]["header_msg"] = "Stage One";
return "1";
}else{
include("../header.inc.php");
if (!isset($phpgw_info["server"]["header_admin_password"])){
$phpgw_info["setup"]["header_msg"] = "Stage One (No header admin password set)";
return "2";
@ -93,11 +92,11 @@
}elseif ($phpgw_info["server"]["versions"]["header"] != $phpgw_info["server"]["versions"]["current_header"]) {
$phpgw_info["setup"]["header_msg"] = "Stage One (Upgrade your header.inc.php)";
return "3";
}else{ /* header.inc.php part settled. Moving to authentication */
$phpgw_info["setup"]["header_msg"] = "Stage One (Completed)";
return "10";
}
}
/* header.inc.php part settled. Moving to authentication */
$phpgw_info["setup"]["header_msg"] = "Stage One (Completed)";
return "10";
}
function generate_header()