39 $this->db =& $a_db_handler;
54 $this->db = $mySetup->db;
63 $this->current_file = $updatefile;
64 $this->DB_UPDATE_FILE = $this->PATH.
"setup/sql/".$updatefile;
69 $this->LAST_UPDATE_FILE = $this->PATH.
"setup/sql/dbupdate_03.php";
84 if ((
int)$a_version > 2948)
86 return "dbupdate_03.php";
88 else if ((
int)$a_version > 864)
90 return "dbupdate_02.php";
94 return "dbupdate.php";
113 $this->db->disconnect();
118 if (!file_exists($this->DB_UPDATE_FILE))
120 $this->error =
"no_db_update_file";
121 $this->filecontent = array();
125 $this->filecontent = @file($this->DB_UPDATE_FILE);
131 if (!file_exists($this->LAST_UPDATE_FILE))
133 $this->error =
"no_last_update_file";
134 $this->lastfilecontent = array();
138 $this->lastfilecontent = @file($this->LAST_UPDATE_FILE);
145 include_once
'./Services/Administration/classes/class.ilSetting.php';
147 $this->currentVersion = (integer) $set->get(
"db_version");
153 include_once
'./Services/Administration/classes/class.ilSetting.php';
155 $set->set(
"db_version", $a_version);
156 $this->currentVersion = $a_version;
168 include_once
'./Services/Administration/classes/class.ilSetting.php';
170 $set->set(
"db_update_running", $a_nr);
171 $this->db_update_running = $a_nr;
181 include_once
'./Services/Administration/classes/class.ilSetting.php';
183 $this->db_update_running = (integer) $set->get(
"db_update_running");
185 return $this->db_update_running;
193 include_once
'./Services/Administration/classes/class.ilSetting.php';
195 $set->set(
"db_update_running", 0);
196 $this->db_update_running = 0;
202 reset($this->lastfilecontent);
204 foreach ($this->lastfilecontent as
$row)
206 if (ereg(
"^<#([0-9]+)>", $row, $regs))
212 $this->fileVersion = (integer) $version;
232 $sql = explode(
"\n",trim($str));
233 for ($i=0; $i<count($sql); $i++)
235 $sql[$i] = trim($sql[$i]);
236 if ($sql[$i] !=
"" && substr($sql[$i],0,1)!=
"#")
239 if (substr($sql[$i],-1)==
";")
242 $q .=
" ".substr($sql[$i],0,-1);
249 $this->error = $r->getMessage();
255 $this->error = $check;
268 echo
"incomplete_statement: ".$q.
"<br>";
289 include_once
'./Services/Database/classes/class.ilMySQLAbstraction.php';
292 $GLOBALS[
'ilMySQLAbstraction'] = $ilMySQLAbstraction;
297 if ($a_break > $this->currentVersion &&
298 $a_break < $this->fileVersion)
306 for ($i=($c+1); $i<=$f; $i++)
311 $this->DB_UPDATE_FILE = $this->PATH.
"setup/sql/".$this->
getFileForStep($i);
320 "msg" =>
"update_error: ".$this->error,
323 $this->updateMsg = $msg;
329 "msg" =>
"update_applied",
335 $this->updateMsg = $msg;
339 $this->updateMsg =
"no_changes";
342 if ($f < $this->fileVersion)
357 require_once
"./setup/classes/class.ilModuleReader.php";
358 require_once
"./setup/classes/class.ilServiceReader.php";
359 require_once
"./setup/classes/class.ilCtrlStructureReader.php";
361 require_once
"./Services/Component/classes/class.ilModule.php";
362 require_once
"./Services/Component/classes/class.ilService.php";
368 foreach($modules as $module)
371 $module[
"subdir"],
"Modules");
378 foreach($services as $service)
381 $service[
"subdir"],
"Services");
386 $ilCtrlStructureReader->readStructure();
402 reset($this->filecontent);
413 while (!ereg(
"^<#".$nr.
">", $this->filecontent[$i]) && $i<count($this->filecontent))
419 if ($i == count($this->filecontent))
421 $this->error =
"update_not_found";
429 while ($i<count($this->filecontent) && !ereg(
"^<#".($nr+1).
">", $this->filecontent[$i]))
431 $update[] = trim($this->filecontent[$i]);
440 foreach ($update as
$row)
442 if (ereg(
"<\?php", $row))
446 if ($this->
execQuery($this->db, implode(
"\n", $sql)) ==
false)
448 $this->error = $this->error;
455 elseif (ereg(
"\?>", $row))
459 $code = implode(
"\n", $php);
460 if (eval($code) ===
false)
462 $this->error =
"Parse error: ".$code;
484 if ($mode ==
"sql" && count($sql) > 0)
486 if ($this->
execQuery($this->db, implode(
"\n", $sql)) ==
false)
488 $this->error =
"dump_error: ".$this->error;
494 if (!$hotfix && !$custom_update)
502 elseif($custom_update)
507 if (!$hotfix && !$custom_update)
519 if ($this->fileVersion > $this->currentVersion)
535 "name" => $status[
"Table"],
537 "status" => $status[
"Msg_text"]
547 $query =
"ANALYZE TABLE ".$table;
556 foreach (
$_POST[
"tables"] as $key => $value)
558 $query =
"OPTIMIZE TABLE ".$key;
560 $msg[] =
"table $key: ok";
576 return $this->hotfix_current_version;
585 $this->hotfix_setting->set(
"db_hotfixes_".
586 $this->hotfix_version[0].
"_".$this->hotfix_version[1], $a_version);
587 $this->hotfix_current_version = $a_version;
597 return $this->hotfix_file_version;
606 reset($a_file_content);
608 foreach ($a_file_content as
$row)
610 if (ereg(
"^<#([0-9]+)>", $row, $regs))
616 return (integer) $version;
624 if ($this->hotfix_info_read && !$a_force)
628 include_once
'./Services/Administration/classes/class.ilSetting.php';
630 $this->hotfix_setting =
new ilSetting(
"common",
true);
632 $version_array = explode(
".", $ilias_version);
633 $this->hotfix_version[0] = $version_array[0];
634 $this->hotfix_version[1] = $version_array[1];
635 $hotfix_file = $this->PATH.
"setup/sql/".$this->hotfix_version[0].
"_".$this->hotfix_version[1].
"_hotfixes.php";
636 if (is_file($hotfix_file))
638 $this->hotfix_content = @file($hotfix_file);
639 $this->hotfix_current_version = (int) $this->hotfix_setting->get(
"db_hotfixes_".
640 $this->hotfix_version[0].
"_".$this->hotfix_version[1]);
643 $this->hotfix_info_read =
true;
652 if ($this->hotfix_file_version > $this->hotfix_current_version)
666 include_once
'./Services/Database/classes/class.ilMySQLAbstraction.php';
669 $GLOBALS[
'ilMySQLAbstraction'] = $ilMySQLAbstraction;
679 for ($i=($c+1); $i<=$f; $i++)
683 $this->filecontent = $this->hotfix_content;
688 "msg" =>
"update_error: ".$this->error,
691 $this->updateMsg = $msg;
697 "msg" =>
"hotfix_applied",
703 $this->updateMsg = $msg;
707 $this->updateMsg =
"no_changes";
716 return $this->custom_updates_current_version;
722 $this->custom_updates_setting->set(
'db_version_custom', $a_version);
723 $this->custom_updates_current_version = $a_version;
730 return $this->custom_updates_file_version;
736 reset($a_file_content);
738 foreach ($a_file_content as
$row)
740 if (ereg(
"^<#([0-9]+)>", $row, $regs))
746 return (integer) $version;
751 if ($this->custom_updates_info_read && !$a_force)
755 include_once
'./Services/Administration/classes/class.ilSetting.php';
757 $this->custom_updates_setting =
new ilSetting();
758 $custom_updates_file = $this->PATH.
"setup/sql/dbupdate_custom.php";
759 if (is_file($custom_updates_file))
761 $this->custom_updates_content = @file($custom_updates_file);
762 $this->custom_updates_current_version = (int) $this->custom_updates_setting->get(
'db_version_custom', 0);
765 $this->custom_updates_info_read =
true;
774 if ($this->custom_updates_file_version > $this->custom_updates_current_version)
785 include_once
'./Services/Database/classes/class.ilMySQLAbstraction.php';
788 $GLOBALS[
'ilMySQLAbstraction'] = $ilMySQLAbstraction;
798 for ($i=($c+1); $i<=$f; $i++)
802 $this->filecontent = $this->custom_updates_content;
807 "msg" =>
"update_error: ".$this->error,
810 $this->updateMsg = $msg;
816 "msg" =>
"custom_update_applied",
822 $this->updateMsg = $msg;
826 $this->updateMsg =
"no_changes";
846 if ($a_break > $this->currentVersion &&
847 $a_break < $this->fileVersion)
855 for ($i=($c+1); $i<=$f; $i++)
860 $this->DB_UPDATE_FILE = $this->PATH.
"setup/sql/".$this->
getFileForStep($i);
888 for ($i=($c+1); $i<=$f; $i++)
890 $this->filecontent = $this->hotfix_content;
910 reset($this->filecontent);
916 while (!ereg(
"^<#".$nr.
">", $this->filecontent[$i]) && $i<count($this->filecontent))
922 if ($i == count($this->filecontent))
931 while ($i<count($this->filecontent) && !ereg(
"^<#".($nr+1).
">", $this->filecontent[$i]))
933 $str.= $this->filecontent[$i];
937 return "<pre><b><#".$nr.
"></b>\n".htmlentities($str).
"</pre>";