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_04.php";
84 if ((
int)$a_version > 4182)
86 return "dbupdate_04.php";
88 else if ((
int)$a_version > 2948)
90 return "dbupdate_03.php";
92 else if ((
int)$a_version > 864)
94 return "dbupdate_02.php";
98 return "dbupdate.php";
117 $this->db->disconnect();
122 if (!file_exists($this->DB_UPDATE_FILE))
124 $this->error =
"no_db_update_file";
125 $this->filecontent = array();
129 $this->filecontent = @file($this->DB_UPDATE_FILE);
135 if (!file_exists($this->LAST_UPDATE_FILE))
137 $this->error =
"no_last_update_file";
138 $this->lastfilecontent = array();
142 $this->lastfilecontent = @file($this->LAST_UPDATE_FILE);
149 include_once
'./Services/Administration/classes/class.ilSetting.php';
151 $this->currentVersion = (integer) $set->get(
"db_version");
157 include_once
'./Services/Administration/classes/class.ilSetting.php';
159 $set->set(
"db_version", $a_version);
160 $this->currentVersion = $a_version;
172 include_once
'./Services/Administration/classes/class.ilSetting.php';
174 $set->set(
"db_update_running", $a_nr);
175 $this->db_update_running = $a_nr;
185 include_once
'./Services/Administration/classes/class.ilSetting.php';
187 $this->db_update_running = (integer) $set->get(
"db_update_running");
189 return $this->db_update_running;
197 include_once
'./Services/Administration/classes/class.ilSetting.php';
199 $set->set(
"db_update_running", 0);
200 $this->db_update_running = 0;
206 reset($this->lastfilecontent);
208 foreach ($this->lastfilecontent as
$row)
210 if (ereg(
"^<#([0-9]+)>", $row, $regs))
216 $this->fileVersion = (integer) $version;
236 $sql = explode(
"\n",trim($str));
237 for ($i=0; $i<count($sql); $i++)
239 $sql[$i] = trim($sql[$i]);
240 if ($sql[$i] !=
"" && substr($sql[$i],0,1)!=
"#")
243 if (substr($sql[$i],-1)==
";")
246 $q .=
" ".substr($sql[$i],0,-1);
253 $this->error = $r->getMessage();
259 $this->error = $check;
272 echo
"incomplete_statement: ".$q.
"<br>";
293 include_once
'./Services/Database/classes/class.ilMySQLAbstraction.php';
296 $GLOBALS[
'ilMySQLAbstraction'] = $ilMySQLAbstraction;
301 if ($a_break > $this->currentVersion &&
302 $a_break < $this->fileVersion)
310 for ($i=($c+1); $i<=$f; $i++)
315 $this->DB_UPDATE_FILE = $this->PATH.
"setup/sql/".$this->
getFileForStep($i);
324 "msg" =>
"update_error: ".$this->error,
327 $this->updateMsg = $msg;
333 "msg" =>
"update_applied",
339 $this->updateMsg = $msg;
343 $this->updateMsg =
"no_changes";
346 if ($f < $this->fileVersion)
361 require_once
"./setup/classes/class.ilModuleReader.php";
362 require_once
"./setup/classes/class.ilServiceReader.php";
363 require_once
"./setup/classes/class.ilCtrlStructureReader.php";
365 require_once
"./Services/Component/classes/class.ilModule.php";
366 require_once
"./Services/Component/classes/class.ilService.php";
372 foreach($modules as $module)
375 $module[
"subdir"],
"Modules");
382 foreach($services as $service)
385 $service[
"subdir"],
"Services");
390 $ilCtrlStructureReader->readStructure();
406 reset($this->filecontent);
417 while (!ereg(
"^<#".$nr.
">", $this->filecontent[$i]) && $i<count($this->filecontent))
423 if ($i == count($this->filecontent))
425 $this->error =
"update_not_found";
433 while ($i<count($this->filecontent) && !ereg(
"^<#".($nr+1).
">", $this->filecontent[$i]))
435 $update[] = trim($this->filecontent[$i]);
444 foreach ($update as
$row)
446 if (ereg(
"<\?php", $row))
450 if ($this->
execQuery($this->db, implode(
"\n", $sql)) ==
false)
452 $this->error = $this->error;
459 elseif (ereg(
"\?>", $row))
463 $code = implode(
"\n", $php);
464 if (eval($code) ===
false)
466 $this->error =
"Parse error: ".$code;
488 if ($mode ==
"sql" && count($sql) > 0)
490 if ($this->
execQuery($this->db, implode(
"\n", $sql)) ==
false)
492 $this->error =
"dump_error: ".$this->error;
498 if (!$hotfix && !$custom_update)
506 elseif($custom_update)
511 if (!$hotfix && !$custom_update)
523 if ($this->fileVersion > $this->currentVersion)
539 "name" => $status[
"Table"],
541 "status" => $status[
"Msg_text"]
551 $query =
"ANALYZE TABLE ".$table;
560 foreach (
$_POST[
"tables"] as $key => $value)
562 $query =
"OPTIMIZE TABLE ".$key;
564 $msg[] =
"table $key: ok";
580 return $this->hotfix_current_version;
589 $this->hotfix_setting->set(
"db_hotfixes_".
590 $this->hotfix_version[0].
"_".$this->hotfix_version[1], $a_version);
591 $this->hotfix_current_version = $a_version;
601 return $this->hotfix_file_version;
610 reset($a_file_content);
612 foreach ($a_file_content as
$row)
614 if (ereg(
"^<#([0-9]+)>", $row, $regs))
620 return (integer) $version;
628 if ($this->hotfix_info_read && !$a_force)
632 include_once
'./Services/Administration/classes/class.ilSetting.php';
634 $this->hotfix_setting =
new ilSetting(
"common",
true);
636 $version_array = explode(
".", $ilias_version);
637 $this->hotfix_version[0] = $version_array[0];
638 $this->hotfix_version[1] = $version_array[1];
639 $hotfix_file = $this->PATH.
"setup/sql/".$this->hotfix_version[0].
"_".$this->hotfix_version[1].
"_hotfixes.php";
640 if (is_file($hotfix_file))
642 $this->hotfix_content = @file($hotfix_file);
643 $this->hotfix_current_version = (int) $this->hotfix_setting->get(
"db_hotfixes_".
644 $this->hotfix_version[0].
"_".$this->hotfix_version[1]);
647 $this->hotfix_info_read =
true;
656 if ($this->hotfix_file_version > $this->hotfix_current_version)
670 include_once
'./Services/Database/classes/class.ilMySQLAbstraction.php';
673 $GLOBALS[
'ilMySQLAbstraction'] = $ilMySQLAbstraction;
683 for ($i=($c+1); $i<=$f; $i++)
687 $this->filecontent = $this->hotfix_content;
692 "msg" =>
"update_error: ".$this->error,
695 $this->updateMsg = $msg;
701 "msg" =>
"hotfix_applied",
707 $this->updateMsg = $msg;
711 $this->updateMsg =
"no_changes";
720 return $this->custom_updates_current_version;
726 $this->custom_updates_setting->set(
'db_version_custom', $a_version);
727 $this->custom_updates_current_version = $a_version;
734 return $this->custom_updates_file_version;
740 reset($a_file_content);
742 foreach ($a_file_content as
$row)
744 if (ereg(
"^<#([0-9]+)>", $row, $regs))
750 return (integer) $version;
755 if ($this->custom_updates_info_read && !$a_force)
759 include_once
'./Services/Administration/classes/class.ilSetting.php';
761 $this->custom_updates_setting =
new ilSetting();
762 $custom_updates_file = $this->PATH.
"setup/sql/dbupdate_custom.php";
763 if (is_file($custom_updates_file))
765 $this->custom_updates_content = @file($custom_updates_file);
766 $this->custom_updates_current_version = (int) $this->custom_updates_setting->get(
'db_version_custom', 0);
769 $this->custom_updates_info_read =
true;
778 if ($this->custom_updates_file_version > $this->custom_updates_current_version)
789 include_once
'./Services/Database/classes/class.ilMySQLAbstraction.php';
792 $GLOBALS[
'ilMySQLAbstraction'] = $ilMySQLAbstraction;
802 for ($i=($c+1); $i<=$f; $i++)
806 $this->filecontent = $this->custom_updates_content;
811 "msg" =>
"update_error: ".$this->error,
814 $this->updateMsg = $msg;
820 "msg" =>
"custom_update_applied",
826 $this->updateMsg = $msg;
830 $this->updateMsg =
"no_changes";
850 if ($a_break > $this->currentVersion &&
851 $a_break < $this->fileVersion)
859 for ($i=($c+1); $i<=$f; $i++)
864 $this->DB_UPDATE_FILE = $this->PATH.
"setup/sql/".$this->
getFileForStep($i);
892 for ($i=($c+1); $i<=$f; $i++)
894 $this->filecontent = $this->hotfix_content;
914 reset($this->filecontent);
920 while (!ereg(
"^<#".$nr.
">", $this->filecontent[$i]) && $i<count($this->filecontent))
926 if ($i == count($this->filecontent))
935 while ($i<count($this->filecontent) && !ereg(
"^<#".($nr+1).
">", $this->filecontent[$i]))
937 $str.= $this->filecontent[$i];
941 return "<pre><b><#".$nr.
"></b>\n".htmlentities($str).
"</pre>";