ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilDBUpdate Class Reference

Database Update class. More...

+ Inheritance diagram for ilDBUpdate:
+ Collaboration diagram for ilDBUpdate:

Public Member Functions

 ilDBUpdate ($a_db_handler=0, $tmp_flag=false)
 constructor
 getFileForStep ($a_version)
 Get db update file name for db step.
 _DBUpdate ()
 destructor
 readDBUpdateFile ()
 readLastUpdateFile ()
 getCurrentVersion ()
 setCurrentVersion ($a_version)
 readFileVersion ()
 getFileVersion ()
 Get Version of file.
 execQuery ($db, $str)
 execute a query
 checkQuery ($q)
 check query
 applyUpdate ()
 Apply update.
 loadXMLInfo ()
 applyUpdateNr ($nr)
 apply an update
 getDBVersionStatus ()
 getTables ()
 getTableStatus ($table)
 optimizeTables ($tables)

Data Fields

 $DB_UPDATE_FILE
 db update file
 $currentVersion
 $fileVersion

Detailed Description

Database Update class.

Author
Peter Gabriel pgabr.nosp@m.iel@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
Id:
class.ilDBUpdate.php 16057 2008-02-23 19:19:41Z akill

Definition at line 34 of file class.ilDBUpdate.php.

Member Function Documentation

ilDBUpdate::_DBUpdate ( )

destructor

Returns
boolean

Reimplemented in ilPluginDBUpdate.

Definition at line 120 of file class.ilDBUpdate.php.

{
$this->db->disconnect();
}
ilDBUpdate::applyUpdate ( )

Apply update.

Definition at line 264 of file class.ilDBUpdate.php.

References $currentVersion, $fileVersion, $ilCtrlStructureReader, applyUpdateNr(), getFileForStep(), loadXMLInfo(), and readDBUpdateFile().

{
if ($c < $f)
{
$msg = array();
for ($i=($c+1); $i<=$f; $i++)
{
// check wether next update file must be loaded
if ($this->current_file != $this->getFileForStep($i))
{
$this->DB_UPDATE_FILE = $this->PATH."setup/sql/".$this->getFileForStep($i);
$this->readDBUpdateFile();
}
if ($this->applyUpdateNr($i) == false)
{
$msg[] = array(
"msg" => "update_error: ".$this->error,
"nr" => $i
);
$this->updateMsg = $msg;
return false;
}
else
{
$msg[] = array(
"msg" => "update_applied",
"nr" => $i
);
}
}
$this->updateMsg = $msg;
}
else
{
$this->updateMsg = "no_changes";
}
//global $ilDB; $ilDB->query("UPDATE settings SET value='1146' WHERE keyword='db_version'");
return $this->loadXMLInfo();
}

+ Here is the call graph for this function:

ilDBUpdate::applyUpdateNr (   $nr)

apply an update

Parameters
intnr number what patch to apply
Returns
bool private

Definition at line 357 of file class.ilDBUpdate.php.

References $ilCtrlStructureReader, $ilErr, execQuery(), and setCurrentVersion().

Referenced by applyUpdate().

{
global $ilDB,$ilErr,$ilUser,$ilCtrlStructureReader,$ilModuleReader;
//search for desired $nr
reset($this->filecontent);
//init
$i = 0;
//go through filecontent
while (!ereg("^<#".$nr.">", $this->filecontent[$i]) && $i<count($this->filecontent))
{
$i++;
}
//update not found
if ($i == count($this->filecontent))
{
$this->error = "update_not_found";
return false;
}
$i++;
//update found, now extract this update to a new array
$update = array();
while ($i<count($this->filecontent) && !ereg("^<#".($nr+1).">", $this->filecontent[$i]))
{
$update[] = trim($this->filecontent[$i]);
$i++;
}
//now you have the update, now process it
$sql = array();
$php = array();
$mode = "sql";
foreach ($update as $row)
{
if (ereg("<\?php", $row))
{
if (count($sql)>0)
{
if ($this->execQuery($this->db, implode("\n", $sql)) == false)
{
$this->error = $this->error;
return false;
}
$sql = array();
}
$mode = "php";
}
elseif (ereg("\?>", $row))
{
if (count($php)>0)
{
eval(implode("\n", $php));
$php = array();
}
$mode = "sql";
}
else
{
if ($mode == "sql")
{
$sql[] = $row;
}
if ($mode == "php")
{
$php[] = $row;
}
} //else
} //foreach
if ($mode == "sql" && count($sql) > 0)
{
if ($this->execQuery($this->db, implode("\n", $sql)) == false)
{
$this->error = "dump_error: ".$this->error;
return false;
}
}
//increase db_Version number
$this->setCurrentVersion($nr);
//$this->currentVersion = $ilias->getSetting("db_version");
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDBUpdate::checkQuery (   $q)

check query

Reimplemented in ilPluginDBUpdate.

Definition at line 256 of file class.ilDBUpdate.php.

Referenced by execQuery().

{
return true;
}

+ Here is the caller graph for this function:

ilDBUpdate::execQuery (   $db,
  $str 
)

execute a query

Parameters
objectDB
stringquery
Returns
boolean

Definition at line 209 of file class.ilDBUpdate.php.

References checkQuery().

Referenced by applyUpdateNr().

{
$sql = explode("\n",trim($str));
for ($i=0; $i<count($sql); $i++)
{
$sql[$i] = trim($sql[$i]);
if ($sql[$i] != "" && substr($sql[$i],0,1)!="#")
{
//take line per line, until last char is ";"
if (substr($sql[$i],-1)==";")
{
//query is complete
$q .= " ".substr($sql[$i],0,-1);
$check = $this->checkQuery($q);
if ($check === true)
{
$r = $db->query($q);
if (MDB2::isError($r))
{
$this->error = $r->getMessage();
return false;
}
}
else
{
$this->error = $check;
return false;
}
unset($q);
} //if
else
{
$q .= " ".$sql[$i];
} //else
} //if
} //for
if ($q != "")
{
echo "incomplete_statement: ".$q."<br>";
return false;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDBUpdate::getCurrentVersion ( )

Reimplemented in ilPluginDBUpdate.

Definition at line 151 of file class.ilDBUpdate.php.

References DB_FETCHMODE_OBJECT.

Referenced by ilDBUpdate().

{
$q = "SELECT value FROM settings ".
"WHERE keyword = 'db_version'";
$r = $this->db->query($q);
$row = $r->fetchRow(DB_FETCHMODE_OBJECT);
$this->currentVersion = (integer) $row->value;
return $this->currentVersion;
}

+ Here is the caller graph for this function:

ilDBUpdate::getDBVersionStatus ( )

Definition at line 451 of file class.ilDBUpdate.php.

{
if ($this->fileVersion > $this->currentVersion)
return false;
else
return true;
}
ilDBUpdate::getFileForStep (   $a_version)

Get db update file name for db step.

Reimplemented in ilPluginDBUpdate.

Definition at line 100 of file class.ilDBUpdate.php.

Referenced by applyUpdate(), and ilDBUpdate().

{
//
// NOTE: IF YOU ADD A NEW FILE HERE, CHANGE ALSO THE CONSTRUCTOR
//
if ((int)$a_version > 864) // last number in previous file
{
return "dbupdate_02.php";
}
else
{
return "dbupdate.php";
}
}

+ Here is the caller graph for this function:

ilDBUpdate::getFileVersion ( )

Get Version of file.

Definition at line 198 of file class.ilDBUpdate.php.

References $fileVersion.

{
}
ilDBUpdate::getTables ( )

Definition at line 459 of file class.ilDBUpdate.php.

References $res, and getTableStatus().

{
$a = array();
$query = "SHOW TABLES";
$res = $this->db->query($query);
while ($row = $res->fetchRow())
{
$status = $this->getTableStatus($row[0]);
$a[] = array(
"name" => $status["Table"],
"table" => $row[0],
"status" => $status["Msg_text"]
);
}
return $a;
}

+ Here is the call graph for this function:

ilDBUpdate::getTableStatus (   $table)

Definition at line 477 of file class.ilDBUpdate.php.

References $res, and DB_FETCHMODE_ASSOC.

Referenced by getTables().

{
$a = array();
$query = "ANALYZE TABLE ".$table;
$res = $this->db->query($query);
$row = $res->fetchRow(DB_FETCHMODE_ASSOC);
return $row;
}

+ Here is the caller graph for this function:

ilDBUpdate::ilDBUpdate (   $a_db_handler = 0,
  $tmp_flag = false 
)

constructor

Definition at line 56 of file class.ilDBUpdate.php.

References getCurrentVersion(), getFileForStep(), readDBUpdateFile(), readFileVersion(), and readLastUpdateFile().

{
// workaround to allow setup migration
if ($a_db_handler)
{
$this->db =& $a_db_handler;
if ($tmp_flag)
{
$this->PATH = "./";
}
else
{
$this->PATH = "../";
}
}
else
{
global $mySetup;
$this->db = $mySetup->db;
$this->PATH = "./";
}
// get update file for current version
$updatefile = $this->getFileForStep($this->currentVersion + 1);
$this->current_file = $updatefile;
$this->DB_UPDATE_FILE = $this->PATH."setup/sql/".$updatefile;
//
// NOTE: IF YOU SET THIS TO THE NEWEST FILE, CHANGE ALSO getFileForStep()
//
$this->LAST_UPDATE_FILE = $this->PATH."setup/sql/dbupdate_02.php";
$this->readDBUpdateFile();
$this->readFileVersion();
}

+ Here is the call graph for this function:

ilDBUpdate::loadXMLInfo ( )

Reimplemented in ilPluginDBUpdate.

Definition at line 312 of file class.ilDBUpdate.php.

References $ilCtrlStructureReader, ilModuleReader\clearTables(), ilServiceReader\clearTables(), ilModule\getAvailableCoreModules(), ilService\getAvailableCoreServices(), and ILIAS_ABSOLUTE_PATH.

Referenced by applyUpdate().

{
// read module and service information into db
require_once "./classes/class.ilModuleReader.php";
require_once "./classes/class.ilServiceReader.php";
require_once "./classes/class.ilCtrlStructureReader.php";
chdir("..");
require_once "./Services/Component/classes/class.ilModule.php";
require_once "./Services/Component/classes/class.ilService.php";
chdir("./setup");
foreach($modules as $module)
{
$mr = new ilModuleReader(ILIAS_ABSOLUTE_PATH."/Modules/".$module["subdir"]."/module.xml",
$module["subdir"], "Modules");
$mr->getModules();
unset($mr);
}
foreach($services as $service)
{
$sr = new ilServiceReader(ILIAS_ABSOLUTE_PATH."/Services/".$service["subdir"]."/service.xml",
$service["subdir"], "Services");
$sr->getServices();
unset($sr);
}
$ilCtrlStructureReader->readStructure();
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDBUpdate::optimizeTables (   $tables)

Definition at line 487 of file class.ilDBUpdate.php.

References $res.

{
$msg = array();
foreach ($_POST["tables"] as $key => $value)
{
$query = "OPTIMIZE TABLE ".$key;
$res = $this->db->query($query);
$msg[] = "table $key: ok";
}
return $msg;
}
ilDBUpdate::readDBUpdateFile ( )

Definition at line 125 of file class.ilDBUpdate.php.

Referenced by applyUpdate(), ilDBUpdate(), and ilPluginDBUpdate\ilPluginDBUpdate().

{
if (!file_exists($this->DB_UPDATE_FILE))
{
$this->error = "no_db_update_file";
$this->filecontent = array();
return false;
}
$this->filecontent = @file($this->DB_UPDATE_FILE);
return true;
}

+ Here is the caller graph for this function:

ilDBUpdate::readFileVersion ( )

Definition at line 178 of file class.ilDBUpdate.php.

References $fileVersion.

Referenced by ilDBUpdate(), and ilPluginDBUpdate\ilPluginDBUpdate().

{
//go through filecontent and search for last occurence of <#x>
reset($this->lastfilecontent);
$regs = array();
foreach ($this->lastfilecontent as $row)
{
if (ereg("^<#([0-9]+)>", $row, $regs))
{
$version = $regs[1];
}
}
$this->fileVersion = (integer) $version;
}

+ Here is the caller graph for this function:

ilDBUpdate::readLastUpdateFile ( )

Definition at line 138 of file class.ilDBUpdate.php.

Referenced by ilDBUpdate(), and ilPluginDBUpdate\ilPluginDBUpdate().

{
if (!file_exists($this->LAST_UPDATE_FILE))
{
$this->error = "no_last_update_file";
$this->lastfilecontent = array();
return false;
}
$this->lastfilecontent = @file($this->LAST_UPDATE_FILE);
return true;
}

+ Here is the caller graph for this function:

ilDBUpdate::setCurrentVersion (   $a_version)

Reimplemented in ilPluginDBUpdate.

Definition at line 164 of file class.ilDBUpdate.php.

Referenced by applyUpdateNr().

{
{
$q = "UPDATE settings SET ".
"value = ".$this->db->quote($a_version)." ".
"WHERE keyword = 'db_version'";
}
$this->db->query($q);
$this->currentVersion = $a_version;
return true;
}

+ Here is the caller graph for this function:

Field Documentation

ilDBUpdate::$currentVersion

Definition at line 45 of file class.ilDBUpdate.php.

Referenced by applyUpdate(), and ilPluginDBUpdate\getCurrentVersion().

ilDBUpdate::$DB_UPDATE_FILE

db update file

Definition at line 39 of file class.ilDBUpdate.php.

ilDBUpdate::$fileVersion

Definition at line 51 of file class.ilDBUpdate.php.

Referenced by applyUpdate(), getFileVersion(), and readFileVersion().


The documentation for this class was generated from the following file: