56 $this->db = &$a_db_handler;
60 if (
$DIC->offsetExists(
'mySetup')) {
61 $mySetup =
$DIC[
'mySetup'];
63 $this->db = $mySetup->db;
72 $this->current_file = $updatefile;
73 $this->DB_UPDATE_FILE = $this->
PATH .
"setup/sql/" . $updatefile;
78 $this->LAST_UPDATE_FILE = $this->
PATH .
"setup/sql/dbupdate_05.php";
99 case ((
int) $a_version > 5431):
100 return "dbupdate_05.php";
101 case ((
int) $a_version > 4182):
102 return "dbupdate_04.php";
103 case ((
int) $a_version > 2948):
104 return "dbupdate_03.php";
105 case ((
int) $a_version > 864):
106 return "dbupdate_02.php";
108 return "dbupdate.php";
124 if (!file_exists($this->DB_UPDATE_FILE)) {
125 $this->
error =
"no_db_update_file";
126 $this->filecontent = array();
131 $this->filecontent = @file($this->DB_UPDATE_FILE);
139 if (!file_exists($this->LAST_UPDATE_FILE)) {
140 $this->
error =
"no_last_update_file";
141 $this->lastfilecontent = array();
146 $this->lastfilecontent = @file($this->LAST_UPDATE_FILE);
158 $this->currentVersion = (integer) $set->get(
"db_version");
172 $set->set(
"db_version", $a_version);
173 $this->currentVersion = $a_version;
187 $set->set(
"db_update_running", $a_nr);
188 $this->db_update_running = $a_nr;
200 $this->db_update_running = (integer) $set->get(
"db_update_running");
202 return $this->db_update_running;
212 $set->set(
"db_update_running", 0);
213 $this->db_update_running = 0;
220 reset($this->lastfilecontent);
223 foreach ($this->lastfilecontent as $row) {
224 if (preg_match(
'/^<\#([0-9]+)>/', $row, $regs)) {
229 $this->fileVersion = (integer) $version;
254 $sql = explode(
"\n", trim($str));
255 for (
$i = 0;
$i < count($sql);
$i++) {
256 $sql[
$i] = trim($sql[
$i]);
257 if ($sql[
$i] !=
"" && substr($sql[
$i], 0, 1) !=
"#") {
259 if (substr($sql[
$i], -1) ==
";") {
261 $q .=
" " . substr($sql[
$i], 0, -1);
263 if ($check ===
true) {
269 $this->
error = $e->getMessage();
274 $this->
error = $check;
281 $q .=
" " . $sql[
$i];
285 if (isset($q) && $q !=
"") {
286 echo
"incomplete_statement: " . $q .
"<br>";
315 if (isset(
$GLOBALS[
'ilCtrlStructureReader'])) {
316 $ilCtrlStructureReader =
$GLOBALS[
'ilCtrlStructureReader'];
317 } elseif (
$DIC->offsetExists(
'ilCtrlStructureReader')) {
318 $ilCtrlStructureReader =
$DIC[
'ilCtrlStructureReader'];
321 $DIC->offsetSet(
'ilCtrlStructureReader', $ilCtrlStructureReader);
324 $GLOBALS[
'ilCtrlStructureReader'] = $ilCtrlStructureReader;
326 if (
$DIC->offsetExists(
'ilMySQLAbstraction')) {
327 $ilMySQLAbstraction =
$DIC[
'ilMySQLAbstraction'];
330 $DIC->offsetSet(
'ilMySQLAbstraction', $ilMySQLAbstraction);
333 $GLOBALS[
'ilMySQLAbstraction'] = $ilMySQLAbstraction;
334 if ($this->client_ini) {
335 $ilCtrlStructureReader->setIniFile($this->client_ini);
346 $ilCtrlStructureReader =
null;
347 $ilMySQLAbstraction =
null;
354 if ($a_break > $this->currentVersion
355 && $a_break < $this->fileVersion
372 $msg[] = array(
"msg" =>
"update_error: " . $this->
error,
374 $this->updateMsg = $msg;
378 $msg[] = array(
"msg" =>
"update_applied",
383 $this->updateMsg = $msg;
385 $this->updateMsg =
"no_changes";
388 if ($f < $this->fileVersion) {
398 $ilCtrlStructureReader =
null;
399 $ilMySQLAbstraction =
null;
407 $ilCtrlStructureReader->readStructure();
411 foreach ($modules as $module) {
413 ILIAS_ABSOLUTE_PATH .
"/Modules/" . $module[
"subdir"] .
"/module.xml",
425 ILIAS_ABSOLUTE_PATH .
"/Services/" .
$service[
"subdir"] .
"/service.xml",
447 public function applyUpdateNr(&$nr, $hotfix =
false, $custom_update =
false)
449 $ilCtrlStructureReader =
null;
450 $ilMySQLAbstraction =
null;
455 reset($this->filecontent);
457 if (!$hotfix && !$custom_update) {
465 while (!preg_match(
"/^<\#" . $nr .
">/", $this->filecontent[
$i]) &&
$i < count($this->filecontent)) {
470 if (
$i == count($this->filecontent)) {
471 $this->
error =
"update_not_found";
480 while (
$i < count($this->filecontent) && !preg_match(
"/^<#" . ($nr + 1) .
">/", $this->filecontent[
$i])) {
481 $update[] = trim($this->filecontent[
$i]);
490 foreach ($update as $row) {
491 if (preg_match(
"/<\?php/", $row)) {
492 if (count($sql) > 0) {
493 if ($this->
execQuery($this->db, implode(
"\n", $sql)) ==
false) {
494 $this->
error = $this->error;
501 } elseif (preg_match(
"/\?>/", $row)) {
502 if (count($php) > 0) {
503 $code = implode(
"\n", $php);
504 if (eval($code) ===
false) {
505 $this->
error =
"Parse error: " . $code;
513 if ($mode ==
"sql") {
517 if ($mode ==
"php") {
523 if ($mode ==
"sql" && count($sql) > 0) {
524 if ($this->
execQuery($this->db, implode(
"\n", $sql)) ==
false) {
525 $this->
error =
"dump_error: " . $this->error;
532 if (!$hotfix && !$custom_update) {
536 } elseif ($custom_update) {
540 if (!$hotfix && !$custom_update) {
552 if ($this->fileVersion > $this->currentVersion) {
566 while ($row =
$res->fetchRow()) {
568 $a[] = array(
"name" => $status[
"Table"],
570 "status" => $status[
"Msg_text"],);
581 $query =
"ANALYZE TABLE " . $table;
600 return $this->hotfix_current_version ??
null;
610 $this->hotfix_setting->set(
611 "db_hotfixes_" . $this->hotfix_version[0],
614 $this->hotfix_current_version = $a_version;
627 return $this->hotfix_file_version ??
null;
637 reset($a_file_content);
639 foreach ($a_file_content as $row) {
640 if (preg_match(
"/^<#([0-9]+)>/", $row, $regs)) {
645 return (integer) $version;
654 if (isset($this->hotfix_info_read) && $this->hotfix_info_read && !$a_force) {
657 $this->hotfix_setting =
new ilSetting(
"common",
true);
659 $version_array = explode(
".", $ilias_version);
660 $this->hotfix_version[0] = $version_array[0];
661 $this->hotfix_version[1] = $version_array[1];
662 $hotfix_file = $this->
PATH .
"setup/sql/" . $this->hotfix_version[0] .
"_hotfixes.php";
663 if (is_file($hotfix_file)) {
664 $this->hotfix_content = @file($hotfix_file);
665 $this->hotfix_current_version = (int) $this->hotfix_setting->get(
666 "db_hotfixes_" . $this->hotfix_version[0]
670 $this->hotfix_info_read =
true;
680 if (isset($this->hotfix_file_version) && $this->hotfix_file_version > $this->hotfix_current_version) {
693 $ilCtrlStructureReader =
null;
694 $ilMySQLAbstraction =
null;
699 $GLOBALS[
'DIC'][
'ilMySQLAbstraction'] = $ilMySQLAbstraction;
711 $this->filecontent = $this->hotfix_content;
714 $msg[] = array(
"msg" =>
"update_error: " . $this->
error,
716 $this->updateMsg = $msg;
720 $msg[] = array(
"msg" =>
"hotfix_applied",
725 $this->updateMsg = $msg;
727 $this->updateMsg =
"no_changes";
745 $this->custom_updates_setting->set(
'db_version_custom', $a_version);
746 $this->custom_updates_current_version = $a_version;
763 reset($a_file_content);
765 foreach ($a_file_content as $row) {
766 if (preg_match(
"/^<#([0-9]+)>/", $row, $regs)) {
771 return (integer) $version;
777 if ($this->custom_updates_info_read && !$a_force) {
781 $this->custom_updates_setting =
new ilSetting();
782 $custom_updates_file = $this->
PATH .
"setup/sql/dbupdate_custom.php";
783 if (is_file($custom_updates_file)) {
784 $this->custom_updates_content = @file($custom_updates_file);
785 $this->custom_updates_current_version = (int) $this->custom_updates_setting->get(
'db_version_custom', 0);
788 $this->custom_updates_info_read =
true;
798 if ($this->custom_updates_file_version > $this->custom_updates_current_version) {
808 $ilCtrlStructureReader =
null;
809 $ilMySQLAbstraction =
null;
814 $GLOBALS[
'DIC'][
'ilMySQLAbstraction'] = $ilMySQLAbstraction;
824 $this->filecontent = $this->custom_updates_content;
827 $msg[] = array(
"msg" =>
"update_error: " . $this->
error,
829 $this->updateMsg = $msg;
833 $msg[] = array(
"msg" =>
"custom_update_applied",
838 $this->updateMsg = $msg;
840 $this->updateMsg =
"no_changes";
854 $ilCtrlStructureReader =
null;
855 $ilMySQLAbstraction =
null;
864 if ($a_break > $this->currentVersion
865 && $a_break < $this->fileVersion
904 $this->filecontent = $this->hotfix_content;
922 reset($this->filecontent);
928 while (!preg_match(
"/^<#" . $nr .
">/", $this->filecontent[
$i]) &&
$i < count($this->filecontent)) {
933 if (
$i == count($this->filecontent)) {
941 while (
$i < count($this->filecontent) && !preg_match(
"/^<#" . ($nr + 1) .
">/", $this->filecontent[
$i])) {
942 $str .= $this->filecontent[
$i];
946 return "<pre><b><#" . $nr .
"></b>\n" . htmlentities($str) .
"</pre>";
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
Class ilCtrlStructureReader.
getUpdateStepNr($nr, $hotfix=false, $custom_update=false)
Get single update step for presentation.
getFileVersion()
Get Version of file.
applyUpdate($a_break=0)
Apply update.
readCustomUpdatesInfo($a_force=false)
__construct($a_db_handler=0, $client_ini=null)
ilDBUpdate constructor.
$DB_UPDATE_FILE
db update file
getHotfixSteps()
Get hotfix steps.
setCurrentVersion($a_version)
getFileForStep($a_version)
Get db update file name for db step.
$custom_updates_file_version
getCustomUpdatesFileVersion()
getUpdateSteps($a_break=0)
Get update steps as string (for presentation)
setRunningStatus($a_nr)
Set running status for a step.
getCustomUpdatesCurrentVersion()
setHotfixCurrentVersion($a_version)
Set current hotfix version.
initGlobalsRequiredForUpdateSteps(&$ilCtrlStructureReader, &$ilMySQLAbstraction, &$ilDB)
execQuery($db, $str)
execute a query
checkQuery($q)
check query
$custom_updates_info_read
getHotfixCurrentVersion()
Get current hotfix version.
getHotfixFileVersion()
Get current hotfix version.
readHotfixInfo($a_force=false)
Get status of hotfix file.
readCustomUpdatesFileVersion($a_file_content)
hotfixAvailable()
Get status of hotfix file.
setCustomUpdatesCurrentVersion($a_version)
applyUpdateNr(&$nr, $hotfix=false, $custom_update=false)
apply an update
clearRunningStatus()
Clear running status.
$custom_updates_current_version
applyHotfix()
Apply hotfix.
getRunningStatus()
Get running status.
readHotfixFileVersion($a_file_content)
Set current hotfix version.
Class ilDatabaseException.
static getAvailableCoreModules()
Get all available core modules.
This class includes methods that help to abstract ILIAS 3.10.x MySQL tables for the use with MDB2 abs...
static getAvailableCoreServices()
Get all available core services.
const ILIAS_VERSION_NUMERIC
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
foreach($_POST as $key=> $value) $res