3 declare(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);
230 $this->error = (string)
$check;
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);
283 $ilDB = $DIC->database();
292 $ilCtrlStructureReader = null;
299 if ($a_break > $this->currentVersion
300 && $a_break < $this->fileVersion
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;
349 reset($this->filecontent);
351 if (!$hotfix && !$custom_update) {
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) {
424 if (!$hotfix && !$custom_update) {
428 } elseif ($custom_update) {
432 if (!$hotfix && !$custom_update) {
455 while ($row =
$res->fetchRow()) {
457 $a[] = array(
"name" => $status[
"Table"],
459 "status" => $status[
"Msg_text"],
471 $query =
"ANALYZE TABLE " . $table;
486 return $this->hotfix_current_version ?? null;
495 $this->hotfix_setting->set(
496 "db_hotfixes_" . $this->hotfix_version[0],
499 $this->hotfix_current_version = $a_version;
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]
553 $this->hotfix_info_read =
true;
570 $ilCtrlStructureReader = null;
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";
615 $this->custom_updates_setting->set(
'db_version_custom', (
string) $a_version);
616 $this->custom_updates_current_version = $a_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");
656 $this->custom_updates_info_read =
true;
667 $ilCtrlStructureReader = null;
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;
718 if ($a_break > $this->currentVersion
719 && $a_break < $this->fileVersion
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>";
getFileForStep(int $a_version)
Get db update file name for db step.
readCustomUpdatesFileVersion(array $a_file_content)
getCustomUpdatesFileVersion()
applyUpdate(int $a_break=0)
Apply update.
getTableStatus(string $table)
const ILIAS_VERSION_NUMERIC
getHotfixSteps()
Get hotfix steps.
readHotfixInfo(bool $a_force=false)
Get status of hotfix file.
__construct(ilDBInterface $a_db_handler, ilIniFile $client_ini=null)
Class ilCtrlStructureCidGenerator.
getHotfixFileVersion()
Get current hotfix version.
getUpdateStepNr(int $nr, bool $hotfix=false, bool $custom_update=false)
Get single update step for presentation.
setCurrentVersion(int $a_version)
int $hotfix_current_version
ilSetting $custom_updates_setting
applyHotfix()
Apply hotfix.
array $custom_updates_content
applyUpdateNr(int $nr, $hotfix=false, $custom_update=false)
apply an update
checkQuery(string $q)
check query
Class ilCtrlStructureReader is responsible for reading ilCtrl's control structure.
getUpdateSteps(int $a_break=0)
Get update steps as string (for presentation)
setRunningStatus(int $a_nr)
Set running status for a step.
readCustomUpdatesInfo(bool $a_force=false)
int $custom_updates_file_version
Iterator $ctrl_structure_iterator
int $custom_updates_current_version
execQuery(ilDBInterface $db, string $str)
execute a query
bool $custom_updates_info_read
getHotfixCurrentVersion()
Get current hotfix version.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
setHotfixCurrentVersion(int $a_version)
Set current hotfix version.
query(string $query)
Run a (read-only) Query on the database.
Class ilCtrlArrayIterator.
initGlobalsRequiredForUpdateSteps(?ilCtrlStructureReader &$ilCtrlStructureReader, ?ilDBInterface &$ilDB)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCustomUpdatesCurrentVersion(?int $a_version)
getFileVersion()
Get Version of file.
hotfixAvailable()
Get status of hotfix file.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
getRunningStatus()
Get running status.
getCustomUpdatesCurrentVersion()
clearRunningStatus()
Clear running status.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilSetting $hotfix_setting
readHotfixFileVersion(array $a_file_content)
Set current hotfix version.