ILIAS  eassessment Revision 61809
 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.
 initStep ($i)
 Init Step.
 _DBUpdate ()
 destructor
 readDBUpdateFile ()
 readLastUpdateFile ()
 getCurrentVersion ()
 setCurrentVersion ($a_version)
 setRunningStatus ($a_nr)
 Set running status for a step.
 getRunningStatus ()
 Get running status.
 clearRunningStatus ()
 Clear running status.
 readFileVersion ()
 getFileVersion ()
 Get Version of file.
 execQuery ($db, $str)
 execute a query
 checkQuery ($q)
 check query
 applyUpdate ($a_break=0)
 Apply update.
 loadXMLInfo ()
 applyUpdateNr ($nr, $hotfix=false)
 apply an update
 getDBVersionStatus ()
 getTables ()
 getTableStatus ($table)
 optimizeTables ($tables)
 getHotfixCurrentVersion ()
 Get current hotfix version.
 setHotfixCurrentVersion ($a_version)
 Set current hotfix version.
 getHotfixFileVersion ()
 Get current hotfix version.
 readHotfixFileVersion ($a_file_content)
 Set current hotfix version.
 readHotfixInfo ($a_force=false)
 Get status of hotfix file.
 hotfixAvailable ()
 Get status of hotfix file.
 applyHotfix ()
 Apply hotfix.

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
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id:
class.ilDBUpdate.php 25692 2010-09-15 09:44:16Z mwarkus

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

Member Function Documentation

ilDBUpdate::_DBUpdate ( )

destructor

Returns
boolean

Reimplemented in ilPluginDBUpdate.

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

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

Apply hotfix.

Reimplemented in ilDBUpdateEA.

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

References $f, $GLOBALS, $ilCtrlStructureReader, applyUpdateNr(), getHotfixCurrentVersion(), getHotfixFileVersion(), loadXMLInfo(), and readHotfixInfo().

{
global $ilCtrlStructureReader, $ilMySQLAbstraction;
include_once './Services/Database/classes/class.ilMySQLAbstraction.php';
$ilMySQLAbstraction = new ilMySQLAbstraction();
$GLOBALS['ilMySQLAbstraction'] = $ilMySQLAbstraction;
$this->readHotfixInfo(true);
$c = $this->getHotfixCurrentVersion();
if ($c < $f)
{
$msg = array();
for ($i=($c+1); $i<=$f; $i++)
{
// $this->initStep($i); // nothings happens here
$this->filecontent = $this->hotfix_content;
if ($this->applyUpdateNr($i, true) == false)
{
$msg[] = array(
"msg" => "update_error: ".$this->error,
"nr" => $i
);
$this->updateMsg = $msg;
return false;
}
else
{
$msg[] = array(
"msg" => "hotfix_applied",
"nr" => $i
);
}
}
$this->updateMsg = $msg;
}
else
{
$this->updateMsg = "no_changes";
}
return $this->loadXMLInfo();
}

+ Here is the call graph for this function:

ilDBUpdate::applyUpdate (   $a_break = 0)

Apply update.

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

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

{
global $ilCtrlStructureReader, $ilMySQLAbstraction;
include_once './Services/Database/classes/class.ilMySQLAbstraction.php';
$ilMySQLAbstraction = new ilMySQLAbstraction();
$GLOBALS['ilMySQLAbstraction'] = $ilMySQLAbstraction;
if ($a_break > $this->currentVersion &&
$a_break < $this->fileVersion)
{
$f = $a_break;
}
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();
}
$this->initStep($i);
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";
}
if ($f < $this->fileVersion)
{
return true;
}
else
{
return $this->loadXMLInfo();
}
}

+ Here is the call graph for this function:

ilDBUpdate::applyUpdateNr (   $nr,
  $hotfix = false 
)

apply an update

Parameters
intnr number what patch to apply
Returns
bool private

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

References $error, $ilCtrlStructureReader, $ilDB, $ilErr, $row, clearRunningStatus(), execQuery(), setCurrentVersion(), setHotfixCurrentVersion(), and setRunningStatus().

Referenced by applyHotfix(), and applyUpdate().

{
global $ilDB,$ilErr,$ilUser,$ilCtrlStructureReader,$ilModuleReader,$ilMySQLAbstraction;
//search for desired $nr
reset($this->filecontent);
if (!$hotfix)
{
$this->setRunningStatus($nr);
}
//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)
{
$code = implode("\n", $php);
if (eval($code) === false)
{
$this->error = "Parse error: ".$code;
return false;
}
$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
if (!$hotfix)
{
$this->setCurrentVersion($nr);
}
else
{
}
if (!$hotfix)
{
}
//$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 278 of file class.ilDBUpdate.php.

Referenced by execQuery().

{
return true;
}

+ Here is the caller graph for this function:

ilDBUpdate::clearRunningStatus ( )

Clear running status.

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

Referenced by applyUpdateNr().

{
include_once './Services/Administration/classes/class.ilSetting.php';
$set = new ilSetting();
$set->set("db_update_running", 0);
$this->db_update_running = 0;
}

+ Here is the caller graph for this function:

ilDBUpdate::execQuery (   $db,
  $str 
)

execute a query

Parameters
objectDB
stringquery
Returns
boolean

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

References checkQuery(), and MDB2\isError().

Referenced by ilDBUpdateEA\applyUpdateEANr(), and 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 142 of file class.ilDBUpdate.php.

References $currentVersion, and $GLOBALS.

Referenced by ilDBUpdate().

{
$GLOBALS["ilDB"] = $this->db;
include_once './Services/Administration/classes/class.ilSetting.php';
$set = new ilSetting();
$this->currentVersion = (integer) $set->get("db_version");
}

+ Here is the caller graph for this function:

ilDBUpdate::getDBVersionStatus ( )

Definition at line 512 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 79 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 > 2948) // last number in previous file
{
return "dbupdate_03.php";
}
else 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 220 of file class.ilDBUpdate.php.

References $fileVersion.

{
}
ilDBUpdate::getHotfixCurrentVersion ( )

Get current hotfix version.

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

References readHotfixInfo().

Referenced by applyHotfix(), and ilDBUpdateEA\getHotfixCurrentVersionAsString().

{
$this->readHotfixInfo();
return $this->hotfix_current_version;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDBUpdate::getHotfixFileVersion ( )

Get current hotfix version.

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

References readHotfixInfo().

Referenced by applyHotfix(), and ilDBUpdateEA\getHotfixFileVersionAsString().

{
$this->readHotfixInfo();
return $this->hotfix_file_version;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDBUpdate::getRunningStatus ( )

Get running status.

Returns
int current runnning db step

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

{
include_once './Services/Administration/classes/class.ilSetting.php';
$set = new ilSetting();
$this->db_update_running = (integer) $set->get("db_update_running");
return $this->db_update_running;
}
ilDBUpdate::getTables ( )

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

References $query, $res, $row, 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 538 of file class.ilDBUpdate.php.

References $query, $res, $row, and DB_FETCHMODE_ASSOC.

Referenced by getTables().

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

+ Here is the caller graph for this function:

ilDBUpdate::hotfixAvailable ( )

Get status of hotfix file.

Reimplemented in ilDBUpdateEA.

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

References readHotfixInfo().

{
$this->readHotfixInfo();
if ($this->hotfix_file_version > $this->hotfix_current_version)
{
return true;
}
return false;
}

+ Here is the call graph for this function:

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

constructor

Definition at line 34 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 = "./";
//$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_03.php";
$this->readDBUpdateFile();
$this->readFileVersion();
}

+ Here is the call graph for this function:

ilDBUpdate::initStep (   $i)

Init Step.

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

Referenced by applyUpdate().

{
//
}

+ Here is the caller graph for this function:

ilDBUpdate::loadXMLInfo ( )

Reimplemented in ilPluginDBUpdate.

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

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

Referenced by ilDBUpdateEA\applyHotfix(), applyHotfix(), and applyUpdate().

{
// read module and service information into db
require_once "./setup/classes/class.ilModuleReader.php";
require_once "./setup/classes/class.ilServiceReader.php";
require_once "./setup/classes/class.ilCtrlStructureReader.php";
require_once "./Services/Component/classes/class.ilModule.php";
require_once "./Services/Component/classes/class.ilService.php";
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 548 of file class.ilDBUpdate.php.

References $_POST, $query, and $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 116 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 200 of file class.ilDBUpdate.php.

References $fileVersion, and $row.

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::readHotfixFileVersion (   $a_file_content)

Set current hotfix version.

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

References $row.

Referenced by readHotfixInfo(), and ilDBUpdateEA\readHotfixInfoEA().

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

+ Here is the caller graph for this function:

ilDBUpdate::readHotfixInfo (   $a_force = false)

Get status of hotfix file.

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

References $GLOBALS, ILIAS_VERSION_NUMERIC, and readHotfixFileVersion().

Referenced by applyHotfix(), getHotfixCurrentVersion(), getHotfixFileVersion(), hotfixAvailable(), and setHotfixCurrentVersion().

{
if ($this->hotfix_info_read && !$a_force)
{
return;
}
include_once './Services/Administration/classes/class.ilSetting.php';
$GLOBALS["ilDB"] = $this->db;
$this->hotfix_setting = new ilSetting();
$ilias_version = ILIAS_VERSION_NUMERIC;
$version_array = explode(".", $ilias_version);
$this->hotfix_version[0] = $version_array[0];
$this->hotfix_version[1] = $version_array[1];
$hotfix_file = $this->PATH."setup/sql/".$this->hotfix_version[0]."_".$this->hotfix_version[1]."_hotfixes.php";
if (is_file($hotfix_file))
{
$this->hotfix_content = @file($hotfix_file);
$this->hotfix_current_version = (int) $this->hotfix_setting->get("db_hotfixes_".
$this->hotfix_version[0]."_".$this->hotfix_version[1]);
$this->hotfix_file_version = $this->readHotfixFileVersion($this->hotfix_content);
}
$this->hotfix_info_read = true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDBUpdate::readLastUpdateFile ( )

Definition at line 129 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 152 of file class.ilDBUpdate.php.

Referenced by applyUpdateNr().

{
include_once './Services/Administration/classes/class.ilSetting.php';
$set = new ilSetting();
$set->set("db_version", $a_version);
$this->currentVersion = $a_version;
return true;
}

+ Here is the caller graph for this function:

ilDBUpdate::setHotfixCurrentVersion (   $a_version)

Set current hotfix version.

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

References readHotfixInfo().

Referenced by applyUpdateNr().

{
$this->readHotfixInfo();
$this->hotfix_setting->set("db_hotfixes_".
$this->hotfix_version[0]."_".$this->hotfix_version[1], $a_version);
$this->hotfix_current_version = $a_version;
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDBUpdate::setRunningStatus (   $a_nr)

Set running status for a step.

Parameters
intstep number

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

Referenced by applyUpdateNr().

{
include_once './Services/Administration/classes/class.ilSetting.php';
$set = new ilSetting();
$set->set("db_update_running", $a_nr);
$this->db_update_running = $a_nr;
}

+ Here is the caller graph for this function:

Field Documentation

ilDBUpdate::$currentVersion
ilDBUpdate::$DB_UPDATE_FILE

db update file

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

ilDBUpdate::$fileVersion

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

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


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