3declare(strict_types=1);
58 $this->db = $a_db_handler;
66 $this->current_file = $updatefile;
67 $this->DB_UPDATE_FILE = $this->
PATH .
"setup/sql/" . $updatefile;
72 $this->LAST_UPDATE_FILE = $this->
PATH .
"setup/sql/dbupdate_05.php";
78 $class_map = require ILIAS_ABSOLUTE_PATH .
'/libs/composer/vendor/composer/autoload_classmap.php';
91 case ($a_version > 5431):
92 return "dbupdate_05.php";
93 case ($a_version > 4182):
94 return "dbupdate_04.php";
95 case ($a_version > 2948):
96 return "dbupdate_03.php";
97 case ($a_version > 864):
98 return "dbupdate_02.php";
100 return "dbupdate.php";
111 if (!file_exists($this->DB_UPDATE_FILE)) {
112 $this->
error =
"no_db_update_file";
113 $this->filecontent = array();
118 $this->filecontent = @file($this->DB_UPDATE_FILE);
125 if (!file_exists($this->LAST_UPDATE_FILE)) {
126 $this->
error =
"no_last_update_file";
127 $this->lastfilecontent = array();
132 $this->lastfilecontent = @file($this->LAST_UPDATE_FILE);
140 $this->currentVersion = (
int) $set->get(
"db_version");
148 $set->set(
"db_version", (
string) $a_version);
149 $this->currentVersion = $a_version;
159 $set->set(
"db_update_running", (
string) $a_nr);
160 $this->db_update_running = $a_nr;
170 $this->db_update_running = (
int) $set->get(
"db_update_running");
181 $set->set(
"db_update_running",
"0");
182 $this->db_update_running = 0;
188 reset($this->lastfilecontent);
191 foreach ($this->lastfilecontent as $row) {
192 if (preg_match(
'/^<\#([0-9]+)>/', $row, $regs)) {
217 $sql = explode(
"\n", trim($str));
218 foreach ($sql as
$i => $statement) {
219 $sql[
$i] = trim($statement);
220 if ($statement !==
"" && $statement[0] !==
"#") {
222 if (substr($statement, -1) ===
";") {
225 $q .=
" " . substr($statement, 0, -1);
237 $q .=
" " . $statement;
241 if (isset($q) && $q !==
"") {
242 echo
"incomplete_statement: " . $q .
"<br>";
266 if (isset(
$GLOBALS[
'ilCtrlStructureReader'])) {
267 $ilCtrlStructureReader =
$GLOBALS[
'ilCtrlStructureReader'];
268 } elseif (
$DIC->offsetExists(
'ilCtrlStructureReader')) {
269 $ilCtrlStructureReader =
$DIC[
'ilCtrlStructureReader'];
272 $this->ctrl_structure_iterator,
275 $DIC->offsetSet(
'ilCtrlStructureReader', $ilCtrlStructureReader);
278 $GLOBALS[
'ilCtrlStructureReader'] = $ilCtrlStructureReader;
280 if ($this->client_ini) {
281 $ilCtrlStructureReader->setIniFile($this->client_ini);
292 $ilCtrlStructureReader =
null;
294 $this->initGlobalsRequiredForUpdateSteps($ilCtrlStructureReader,
$ilDB);
296 $f = $this->fileVersion;
297 $c = $this->currentVersion;
299 if ($a_break > $this->currentVersion
300 && $a_break < $this->fileVersion
309 if ($this->current_file != $this->getFileForStep(
$i)) {
310 $this->DB_UPDATE_FILE = $this->
PATH .
"setup/sql/" . $this->getFileForStep(
$i);
311 $this->readDBUpdateFile();
316 if ($this->applyUpdateNr(
$i) ===
false) {
317 $msg[] =
"msg: update_error - " . $this->
error .
"; nr: " .
$i .
";";
318 $this->updateMsg = implode(
"\n", $msg);
323 $msg[] =
"msg: update_applied; nr: " .
$i .
";";
326 $this->updateMsg = implode(
"\n", $msg);
328 $this->updateMsg =
"no_changes";
331 if ($f < $this->fileVersion) {
341 public function applyUpdateNr(
int $nr, $hotfix =
false, $custom_update =
false): bool
343 $ilCtrlStructureReader =
null;
344 $ilMySQLAbstraction =
null;
346 $this->initGlobalsRequiredForUpdateSteps($ilCtrlStructureReader,
$ilDB);
349 reset($this->filecontent);
351 if (!$hotfix && !$custom_update) {
352 $this->setRunningStatus($nr);
359 while (!preg_match(
"/^<\#" . $nr .
">/", $this->filecontent[
$i]) &&
$i < count($this->filecontent)) {
364 if (
$i === count($this->filecontent)) {
365 $this->
error =
"update_not_found";
374 while (
$i < count($this->filecontent) && !preg_match(
"/^<#" . ($nr + 1) .
">/", $this->filecontent[
$i])) {
375 $update[] = trim($this->filecontent[
$i]);
385 if (preg_match(
"/<\?php/", $row)) {
386 if (count($sql) > 0) {
387 if ($this->execQuery($this->db, implode(
"\n", $sql)) ===
false) {
393 } elseif (preg_match(
"/\?>/", $row)) {
394 if (count($php) > 0) {
395 $code = implode(
"\n", $php);
396 if (eval($code) ===
false) {
397 $this->
error =
"Parse error: " . $code;
405 if ($mode ===
"sql") {
409 if ($mode ===
"php") {
415 if ($mode ===
"sql" && count($sql) > 0) {
416 if ($this->execQuery($this->db, implode(
"\n", $sql)) ===
false) {
417 $this->
error =
"dump_error: " . $this->error;
424 if (!$hotfix && !$custom_update) {
425 $this->setCurrentVersion($nr);
427 $this->setHotfixCurrentVersion($nr);
428 } elseif ($custom_update) {
429 $this->setCustomUpdatesCurrentVersion($nr);
432 if (!$hotfix && !$custom_update) {
433 $this->clearRunningStatus();
443 return !($this->fileVersion > $this->currentVersion);
455 while ($row =
$res->fetchRow()) {
456 $status = $this->getTableStatus($row[0]);
457 $a[] = array(
"name" => $status[
"Table"],
459 "status" => $status[
"Msg_text"],
471 $query =
"ANALYZE TABLE " . $table;
484 $this->readHotfixInfo();
486 return $this->hotfix_current_version ??
null;
494 $this->readHotfixInfo();
495 $this->hotfix_setting->set(
496 "db_hotfixes_" . $this->hotfix_version[0],
499 $this->hotfix_current_version = $a_version;
509 $this->readHotfixInfo();
511 return $this->hotfix_file_version ??
null;
520 reset($a_file_content);
523 foreach ($a_file_content as $row) {
524 if (preg_match(
"/^<#([0-9]+)>/", $row, $regs)) {
537 if (isset($this->hotfix_info_read) && $this->hotfix_info_read && !$a_force) {
540 $this->hotfix_setting =
new ilSetting(
"common",
true);
542 $version_array = explode(
".", $ilias_version);
543 $this->hotfix_version[0] = $version_array[0];
544 $this->hotfix_version[1] = $version_array[1];
545 $hotfix_file = $this->
PATH .
"setup/sql/" . $this->hotfix_version[0] .
"_hotfixes.php";
546 if (is_file($hotfix_file)) {
547 $this->hotfix_content = @file($hotfix_file);
548 $this->hotfix_current_version = (
int) $this->hotfix_setting->get(
549 "db_hotfixes_" . $this->hotfix_version[0]
551 $this->hotfix_file_version = $this->readHotfixFileVersion($this->hotfix_content);
553 $this->hotfix_info_read =
true;
561 $this->readHotfixInfo();
562 return isset($this->hotfix_file_version) && $this->hotfix_file_version > $this->hotfix_current_version;
570 $ilCtrlStructureReader =
null;
572 $this->initGlobalsRequiredForUpdateSteps($ilCtrlStructureReader,
$ilDB);
573 $this->readHotfixInfo(
true);
575 $f = $this->getHotfixFileVersion();
576 $c = $this->getHotfixCurrentVersion();
581 $this->filecontent = $this->hotfix_content;
583 if ($this->applyUpdateNr(
$i,
true) ===
false) {
584 $msg[] = array(
"msg" =>
"update_error: " . $this->
error,
587 $this->updateMsg = implode(
"\n", $msg);
592 $msg[] = array(
"msg" =>
"hotfix_applied",
597 $this->updateMsg = implode(
"\n", $msg);
599 $this->updateMsg =
"no_changes";
607 $this->readCustomUpdatesInfo();
609 return $this->custom_updates_current_version;
614 $this->readCustomUpdatesInfo();
615 $this->custom_updates_setting->set(
'db_version_custom', (
string) $a_version);
616 $this->custom_updates_current_version = $a_version;
623 $this->readCustomUpdatesInfo();
625 return $this->custom_updates_file_version;
631 reset($a_file_content);
634 foreach ($a_file_content as $row) {
635 if (preg_match(
"/^<#([0-9]+)>/", $row, $regs)) {
645 if ($this->custom_updates_info_read && !$a_force) {
649 $this->custom_updates_setting =
new ilSetting();
650 $custom_updates_file = $this->
PATH .
"setup/sql/dbupdate_custom.php";
651 if (is_file($custom_updates_file)) {
652 $this->custom_updates_content = @file($custom_updates_file);
653 $this->custom_updates_current_version = (
int) $this->custom_updates_setting->get(
'db_version_custom',
"0");
654 $this->custom_updates_file_version = $this->readCustomUpdatesFileVersion($this->custom_updates_content);
656 $this->custom_updates_info_read =
true;
661 $this->readCustomUpdatesInfo();
662 return $this->custom_updates_file_version > $this->custom_updates_current_version;
667 $ilCtrlStructureReader =
null;
669 $this->initGlobalsRequiredForUpdateSteps($ilCtrlStructureReader,
$ilDB);
670 $this->readCustomUpdatesInfo(
true);
672 $f = $this->getCustomUpdatesFileVersion();
673 $c = $this->getCustomUpdatesCurrentVersion();
678 $this->filecontent = $this->custom_updates_content;
680 if ($this->applyUpdateNr(
$i,
false,
true) ===
false) {
681 $msg[] = array(
"msg" =>
"update_error: " . $this->
error,
684 $this->updateMsg = implode(
"\n", $msg);
689 $msg[] = array(
"msg" =>
"custom_update_applied",
694 $this->updateMsg = implode(
"\n", $msg);
696 $this->updateMsg =
"no_changes";
708 $ilCtrlStructureReader =
null;
709 $ilMySQLAbstraction =
null;
711 $this->initGlobalsRequiredForUpdateSteps($ilCtrlStructureReader,
$ilDB);
715 $f = $this->fileVersion;
716 $c = $this->currentVersion;
718 if ($a_break > $this->currentVersion
719 && $a_break < $this->fileVersion
727 if ($this->current_file != $this->getFileForStep(
$i)) {
728 $this->DB_UPDATE_FILE = $this->
PATH .
"setup/sql/" . $this->getFileForStep(
$i);
729 $this->readDBUpdateFile();
732 $str .= $this->getUpdateStepNr(
$i);
745 $this->readHotfixInfo(
true);
749 $f = $this->getHotfixFileVersion();
750 $c = $this->getHotfixCurrentVersion();
754 $this->filecontent = $this->hotfix_content;
756 $str .= $this->getUpdateStepNr(
$i,
true);
766 public function getUpdateStepNr(
int $nr,
bool $hotfix =
false,
bool $custom_update =
false): string
771 reset($this->filecontent);
777 while (!preg_match(
"/^<#" . $nr .
">/", $this->filecontent[
$i]) &&
$i < count($this->filecontent)) {
782 if (
$i === count($this->filecontent)) {
787 while (
$i < count($this->filecontent) && !preg_match(
"/^<#" . ($nr + 1) .
">/", $this->filecontent[
$i])) {
788 $str .= $this->filecontent[
$i];
792 return "<pre><b><#" . $nr .
"></b>\n" . htmlentities($str) .
"</pre>";
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Class ilCtrlArrayIterator.
Class ilCtrlStructureCidGenerator.
Class ilCtrlStructureReader is responsible for reading ilCtrl's control structure.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTableStatus(string $table)
getFileVersion()
Get Version of file.
getHotfixSteps()
Get hotfix steps.
getCustomUpdatesFileVersion()
readCustomUpdatesInfo(bool $a_force=false)
__construct(ilDBInterface $a_db_handler, ilIniFile $client_ini=null)
getCustomUpdatesCurrentVersion()
applyUpdate(int $a_break=0)
Apply update.
readCustomUpdatesFileVersion(array $a_file_content)
getUpdateStepNr(int $nr, bool $hotfix=false, bool $custom_update=false)
Get single update step for presentation.
getHotfixCurrentVersion()
Get current hotfix version.
int $custom_updates_file_version
getUpdateSteps(int $a_break=0)
Get update steps as string (for presentation)
readHotfixInfo(bool $a_force=false)
Get status of hotfix file.
setHotfixCurrentVersion(int $a_version)
Set current hotfix version.
initGlobalsRequiredForUpdateSteps(?ilCtrlStructureReader &$ilCtrlStructureReader, ?ilDBInterface &$ilDB)
getHotfixFileVersion()
Get current hotfix version.
int $hotfix_current_version
int $custom_updates_current_version
ilSetting $custom_updates_setting
hotfixAvailable()
Get status of hotfix file.
ilSetting $hotfix_setting
readHotfixFileVersion(array $a_file_content)
Set current hotfix version.
setCurrentVersion(int $a_version)
checkQuery(string $q)
check query
execQuery(ilDBInterface $db, string $str)
execute a query
clearRunningStatus()
Clear running status.
array $custom_updates_content
getFileForStep(int $a_version)
Get db update file name for db step.
setCustomUpdatesCurrentVersion(?int $a_version)
Iterator $ctrl_structure_iterator
applyUpdateNr(int $nr, $hotfix=false, $custom_update=false)
apply an update
applyHotfix()
Apply hotfix.
bool $custom_updates_info_read
setRunningStatus(int $a_nr)
Set running status for a step.
getRunningStatus()
Get running status.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ILIAS_VERSION_NUMERIC
query(string $query)
Run a (read-only) Query on the database.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples