ILIAS  release_4-4 Revision
ilDBUpdate Class Reference

Database Update class. More...

+ Inheritance diagram for ilDBUpdate:
+ Collaboration diagram for ilDBUpdate:

Public Member Functions

 ilDBUpdate ($a_db_handler=0, $tmp_flag=false)
 constructor More...
 
 getFileForStep ($a_version)
 Get db update file name for db step. More...
 
 initStep ($i)
 Init Step. More...
 
 _DBUpdate ()
 destructor More...
 
 readDBUpdateFile ()
 
 readLastUpdateFile ()
 
 getCurrentVersion ()
 
 setCurrentVersion ($a_version)
 
 setRunningStatus ($a_nr)
 Set running status for a step. More...
 
 getRunningStatus ()
 Get running status. More...
 
 clearRunningStatus ()
 Clear running status. More...
 
 readFileVersion ()
 
 getFileVersion ()
 Get Version of file. More...
 
 execQuery ($db, $str)
 execute a query More...
 
 checkQuery ($q)
 check query More...
 
 applyUpdate ($a_break=0)
 Apply update. More...
 
 loadXMLInfo ()
 
 applyUpdateNr ($nr, $hotfix=false, $custom_update=false)
 apply an update More...
 
 getDBVersionStatus ()
 
 getTables ()
 
 getTableStatus ($table)
 
 optimizeTables ($tables)
 
 getHotfixCurrentVersion ()
 Get current hotfix version. More...
 
 setHotfixCurrentVersion ($a_version)
 Set current hotfix version. More...
 
 getHotfixFileVersion ()
 Get current hotfix version. More...
 
 readHotfixFileVersion ($a_file_content)
 Set current hotfix version. More...
 
 readHotfixInfo ($a_force=false)
 Get status of hotfix file. More...
 
 hotfixAvailable ()
 Get status of hotfix file. More...
 
 applyHotfix ()
 Apply hotfix. More...
 
 getCustomUpdatesCurrentVersion ()
 
 setCustomUpdatesCurrentVersion ($a_version)
 
 getCustomUpdatesFileVersion ()
 
 readCustomUpdatesFileVersion ($a_file_content)
 
 readCustomUpdatesInfo ($a_force=false)
 
 customUpdatesAvailable ()
 
 applyCustomUpdates ()
 
 getUpdateSteps ($a_break=0)
 Get update steps as string (for presentation) More...
 
 getHotfixSteps ()
 Get hotfix steps. More...
 
 getUpdateStepNr ($nr, $hotfix=false, $custom_update=false)
 Get single update step for presentation. More...
 

Data Fields

 $DB_UPDATE_FILE
 db update file More...
 
 $currentVersion
 
 $fileVersion
 

Detailed Description

Database Update class.

Author
Peter Gabriel pgabr.nosp@m.iel@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilDBUpdate.php.

Member Function Documentation

◆ _DBUpdate()

ilDBUpdate::_DBUpdate ( )

destructor

Returns
boolean

Definition at line 111 of file class.ilDBUpdate.php.

112  {
113  $this->db->disconnect();
114  }

◆ applyCustomUpdates()

ilDBUpdate::applyCustomUpdates ( )

Definition at line 781 of file class.ilDBUpdate.php.

References $GLOBALS, $ilCtrlStructureReader, applyUpdateNr(), getCustomUpdatesCurrentVersion(), getCustomUpdatesFileVersion(), loadXMLInfo(), and readCustomUpdatesInfo().

782  {
783  global $ilCtrlStructureReader, $ilMySQLAbstraction;
784 
785  include_once './Services/Database/classes/class.ilMySQLAbstraction.php';
786 
787  $ilMySQLAbstraction = new ilMySQLAbstraction();
788  $GLOBALS['ilMySQLAbstraction'] = $ilMySQLAbstraction;
789 
790  $this->readCustomUpdatesInfo(true);
791 
792  $f = $this->getCustomUpdatesFileVersion();
793  $c = $this->getCustomUpdatesCurrentVersion();
794 
795  if ($c < $f)
796  {
797  $msg = array();
798  for ($i=($c+1); $i<=$f; $i++)
799  {
800 // $this->initStep($i); // nothings happens here
801 
802  $this->filecontent = $this->custom_updates_content;
803 
804  if ($this->applyUpdateNr($i, false, true) == false)
805  {
806  $msg[] = array(
807  "msg" => "update_error: ".$this->error,
808  "nr" => $i
809  );
810  $this->updateMsg = $msg;
811  return false;
812  }
813  else
814  {
815  $msg[] = array(
816  "msg" => "custom_update_applied",
817  "nr" => $i
818  );
819  }
820  }
821 
822  $this->updateMsg = $msg;
823  }
824  else
825  {
826  $this->updateMsg = "no_changes";
827  }
828 
829  return $this->loadXMLInfo();
830  }
This class includes methods that help to abstract ILIAS 3.10.x MySQL tables for the use with MDB2 abs...
$ilCtrlStructureReader
applyUpdateNr($nr, $hotfix=false, $custom_update=false)
apply an update
$GLOBALS['ct_recipient']
readCustomUpdatesInfo($a_force=false)
getCustomUpdatesCurrentVersion()
+ Here is the call graph for this function:

◆ applyHotfix()

ilDBUpdate::applyHotfix ( )

Apply hotfix.

Definition at line 662 of file class.ilDBUpdate.php.

References $GLOBALS, $ilCtrlStructureReader, applyUpdateNr(), getHotfixCurrentVersion(), getHotfixFileVersion(), loadXMLInfo(), and readHotfixInfo().

663  {
664  global $ilCtrlStructureReader, $ilMySQLAbstraction;
665 
666  include_once './Services/Database/classes/class.ilMySQLAbstraction.php';
667 
668  $ilMySQLAbstraction = new ilMySQLAbstraction();
669  $GLOBALS['ilMySQLAbstraction'] = $ilMySQLAbstraction;
670 
671  $this->readHotfixInfo(true);
672 
673  $f = $this->getHotfixFileVersion();
674  $c = $this->getHotfixCurrentVersion();
675 
676  if ($c < $f)
677  {
678  $msg = array();
679  for ($i=($c+1); $i<=$f; $i++)
680  {
681 // $this->initStep($i); // nothings happens here
682 
683  $this->filecontent = $this->hotfix_content;
684 
685  if ($this->applyUpdateNr($i, true) == false)
686  {
687  $msg[] = array(
688  "msg" => "update_error: ".$this->error,
689  "nr" => $i
690  );
691  $this->updateMsg = $msg;
692  return false;
693  }
694  else
695  {
696  $msg[] = array(
697  "msg" => "hotfix_applied",
698  "nr" => $i
699  );
700  }
701  }
702 
703  $this->updateMsg = $msg;
704  }
705  else
706  {
707  $this->updateMsg = "no_changes";
708  }
709 
710  return $this->loadXMLInfo();
711  }
This class includes methods that help to abstract ILIAS 3.10.x MySQL tables for the use with MDB2 abs...
$ilCtrlStructureReader
getHotfixFileVersion()
Get current hotfix version.
applyUpdateNr($nr, $hotfix=false, $custom_update=false)
apply an update
readHotfixInfo($a_force=false)
Get status of hotfix file.
$GLOBALS['ct_recipient']
getHotfixCurrentVersion()
Get current hotfix version.
+ Here is the call graph for this function:

◆ applyUpdate()

ilDBUpdate::applyUpdate (   $a_break = 0)

Apply update.

Definition at line 285 of file class.ilDBUpdate.php.

References $currentVersion, $fileVersion, $GLOBALS, $ilCtrlStructureReader, applyUpdateNr(), getFileForStep(), initStep(), loadXMLInfo(), and readDBUpdateFile().

286  {
287  global $ilCtrlStructureReader, $ilMySQLAbstraction;
288 
289  include_once './Services/Database/classes/class.ilMySQLAbstraction.php';
290 
291  $ilMySQLAbstraction = new ilMySQLAbstraction();
292  $GLOBALS['ilMySQLAbstraction'] = $ilMySQLAbstraction;
293 
294  $f = $this->fileVersion;
296 
297  if ($a_break > $this->currentVersion &&
298  $a_break < $this->fileVersion)
299  {
300  $f = $a_break;
301  }
302 
303  if ($c < $f)
304  {
305  $msg = array();
306  for ($i=($c+1); $i<=$f; $i++)
307  {
308  // check wether next update file must be loaded
309  if ($this->current_file != $this->getFileForStep($i))
310  {
311  $this->DB_UPDATE_FILE = $this->PATH."setup/sql/".$this->getFileForStep($i);
312  $this->readDBUpdateFile();
313  }
314 
315  $this->initStep($i);
316 
317  if ($this->applyUpdateNr($i) == false)
318  {
319  $msg[] = array(
320  "msg" => "update_error: ".$this->error,
321  "nr" => $i
322  );
323  $this->updateMsg = $msg;
324  return false;
325  }
326  else
327  {
328  $msg[] = array(
329  "msg" => "update_applied",
330  "nr" => $i
331  );
332  }
333  }
334 
335  $this->updateMsg = $msg;
336  }
337  else
338  {
339  $this->updateMsg = "no_changes";
340  }
341 
342  if ($f < $this->fileVersion)
343  {
344  return true;
345  }
346  else
347  {
348  return $this->loadXMLInfo();
349  }
350  }
getFileForStep($a_version)
Get db update file name for db step.
This class includes methods that help to abstract ILIAS 3.10.x MySQL tables for the use with MDB2 abs...
$ilCtrlStructureReader
applyUpdateNr($nr, $hotfix=false, $custom_update=false)
apply an update
initStep($i)
Init Step.
$GLOBALS['ct_recipient']
+ Here is the call graph for this function:

◆ applyUpdateNr()

ilDBUpdate::applyUpdateNr (   $nr,
  $hotfix = false,
  $custom_update = false 
)

apply an update

Parameters
intnr number what patch to apply
Returns
bool private

Definition at line 397 of file class.ilDBUpdate.php.

References $ilCtrlStructureReader, $ilErr, $ilUser, $row, clearRunningStatus(), execQuery(), setCurrentVersion(), setCustomUpdatesCurrentVersion(), setHotfixCurrentVersion(), and setRunningStatus().

Referenced by applyCustomUpdates(), applyHotfix(), and applyUpdate().

398  {
399  global $ilDB,$ilErr,$ilUser,$ilCtrlStructureReader,$ilModuleReader,$ilMySQLAbstraction;
400 
401  //search for desired $nr
402  reset($this->filecontent);
403 
404  if (!$hotfix)
405  {
406  $this->setRunningStatus($nr);
407  }
408 
409  //init
410  $i = 0;
411 
412  //go through filecontent
413  while (!ereg("^<#".$nr.">", $this->filecontent[$i]) && $i<count($this->filecontent))
414  {
415  $i++;
416  }
417 
418  //update not found
419  if ($i == count($this->filecontent))
420  {
421  $this->error = "update_not_found";
422  return false;
423  }
424 
425  $i++;
426 
427  //update found, now extract this update to a new array
428  $update = array();
429  while ($i<count($this->filecontent) && !ereg("^<#".($nr+1).">", $this->filecontent[$i]))
430  {
431  $update[] = trim($this->filecontent[$i]);
432  $i++;
433  }
434 
435  //now you have the update, now process it
436  $sql = array();
437  $php = array();
438  $mode = "sql";
439 
440  foreach ($update as $row)
441  {
442  if (ereg("<\?php", $row))
443  {
444  if (count($sql)>0)
445  {
446  if ($this->execQuery($this->db, implode("\n", $sql)) == false)
447  {
448  $this->error = $this->error;
449  return false;
450  }
451  $sql = array();
452  }
453  $mode = "php";
454  }
455  elseif (ereg("\?>", $row))
456  {
457  if (count($php)>0)
458  {
459  $code = implode("\n", $php);
460  if (eval($code) === false)
461  {
462  $this->error = "Parse error: ".$code;
463  return false;
464  }
465  $php = array();
466  }
467  $mode = "sql";
468 
469  }
470  else
471  {
472  if ($mode == "sql")
473  {
474  $sql[] = $row;
475  }
476 
477  if ($mode == "php")
478  {
479  $php[] = $row;
480  }
481  } //else
482  } //foreach
483 
484  if ($mode == "sql" && count($sql) > 0)
485  {
486  if ($this->execQuery($this->db, implode("\n", $sql)) == false)
487  {
488  $this->error = "dump_error: ".$this->error;
489  return false;
490  }
491  }
492 
493  //increase db_Version number
494  if (!$hotfix && !$custom_update)
495  {
496  $this->setCurrentVersion($nr);
497  }
498  elseif($hotfix)
499  {
500  $this->setHotfixCurrentVersion($nr);
501  }
502  elseif($custom_update)
503  {
504  $this->setCustomUpdatesCurrentVersion($nr);
505  }
506 
507  if (!$hotfix && !$custom_update)
508  {
509  $this->clearRunningStatus();
510  }
511  //$this->currentVersion = $ilias->getSetting("db_version");
512 
513  return true;
514 
515  }
setRunningStatus($a_nr)
Set running status for a step.
$ilCtrlStructureReader
setCustomUpdatesCurrentVersion($a_version)
execQuery($db, $str)
execute a query
setHotfixCurrentVersion($a_version)
Set current hotfix version.
global $ilUser
Definition: imgupload.php:15
setCurrentVersion($a_version)
clearRunningStatus()
Clear running status.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkQuery()

ilDBUpdate::checkQuery (   $q)

check query

Definition at line 277 of file class.ilDBUpdate.php.

Referenced by execQuery().

278  {
279  return true;
280  }
+ Here is the caller graph for this function:

◆ clearRunningStatus()

ilDBUpdate::clearRunningStatus ( )

Clear running status.

Definition at line 191 of file class.ilDBUpdate.php.

Referenced by applyUpdateNr().

192  {
193  include_once './Services/Administration/classes/class.ilSetting.php';
194  $set = new ilSetting("common", true);
195  $set->set("db_update_running", 0);
196  $this->db_update_running = 0;
197  }
ILIAS Setting Class.
+ Here is the caller graph for this function:

◆ customUpdatesAvailable()

ilDBUpdate::customUpdatesAvailable ( )

Definition at line 768 of file class.ilDBUpdate.php.

References readCustomUpdatesInfo().

769  {
770  // trunk does not support custom updates
771  return false;
772 
773  $this->readCustomUpdatesInfo();
774  if ($this->custom_updates_file_version > $this->custom_updates_current_version)
775  {
776  return true;
777  }
778  return false;
779  }
readCustomUpdatesInfo($a_force=false)
+ Here is the call graph for this function:

◆ execQuery()

ilDBUpdate::execQuery (   $db,
  $str 
)

execute a query

Parameters
objectDB
stringquery
Returns
boolean

Definition at line 230 of file class.ilDBUpdate.php.

References $r, checkQuery(), and MDB2\isError().

Referenced by applyUpdateNr().

231  {
232  $sql = explode("\n",trim($str));
233  for ($i=0; $i<count($sql); $i++)
234  {
235  $sql[$i] = trim($sql[$i]);
236  if ($sql[$i] != "" && substr($sql[$i],0,1)!="#")
237  {
238  //take line per line, until last char is ";"
239  if (substr($sql[$i],-1)==";")
240  {
241  //query is complete
242  $q .= " ".substr($sql[$i],0,-1);
243  $check = $this->checkQuery($q);
244  if ($check === true)
245  {
246  $r = $db->query($q);
247  if (MDB2::isError($r))
248  {
249  $this->error = $r->getMessage();
250  return false;
251  }
252  }
253  else
254  {
255  $this->error = $check;
256  return false;
257  }
258  unset($q);
259  } //if
260  else
261  {
262  $q .= " ".$sql[$i];
263  } //else
264  } //if
265  } //for
266  if ($q != "")
267  {
268  echo "incomplete_statement: ".$q."<br>";
269  return false;
270  }
271  return true;
272  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
checkQuery($q)
check query
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCurrentVersion()

ilDBUpdate::getCurrentVersion ( )

Definition at line 142 of file class.ilDBUpdate.php.

References $currentVersion, and $GLOBALS.

Referenced by ilDBUpdate().

143  {
144  $GLOBALS["ilDB"] = $this->db;
145  include_once './Services/Administration/classes/class.ilSetting.php';
146  $set = new ilSetting("common", true);
147  $this->currentVersion = (integer) $set->get("db_version");
148  return $this->currentVersion;
149  }
ILIAS Setting Class.
$GLOBALS['ct_recipient']
+ Here is the caller graph for this function:

◆ getCustomUpdatesCurrentVersion()

ilDBUpdate::getCustomUpdatesCurrentVersion ( )

Definition at line 713 of file class.ilDBUpdate.php.

References readCustomUpdatesInfo().

Referenced by applyCustomUpdates().

714  {
715  $this->readCustomUpdatesInfo();
716  return $this->custom_updates_current_version;
717  }
readCustomUpdatesInfo($a_force=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCustomUpdatesFileVersion()

ilDBUpdate::getCustomUpdatesFileVersion ( )

Definition at line 727 of file class.ilDBUpdate.php.

References readCustomUpdatesInfo().

Referenced by applyCustomUpdates().

728  {
729  $this->readCustomUpdatesInfo();
730  return $this->custom_updates_file_version;
731  }
readCustomUpdatesInfo($a_force=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDBVersionStatus()

ilDBUpdate::getDBVersionStatus ( )

Definition at line 517 of file class.ilDBUpdate.php.

518  {
519  if ($this->fileVersion > $this->currentVersion)
520  return false;
521  else
522  return true;
523  }

◆ getFileForStep()

ilDBUpdate::getFileForStep (   $a_version)

Get db update file name for db step.

Definition at line 79 of file class.ilDBUpdate.php.

Referenced by applyUpdate(), getUpdateSteps(), and ilDBUpdate().

80  {
81  //
82  // NOTE: IF YOU ADD A NEW FILE HERE, CHANGE ALSO THE CONSTRUCTOR
83  //
84  if ((int)$a_version > 2948) // last number in previous file
85  {
86  return "dbupdate_03.php";
87  }
88  else if ((int)$a_version > 864) // last number in previous file
89  {
90  return "dbupdate_02.php";
91  }
92  else
93  {
94  return "dbupdate.php";
95  }
96  }
+ Here is the caller graph for this function:

◆ getFileVersion()

ilDBUpdate::getFileVersion ( )

Get Version of file.

Definition at line 219 of file class.ilDBUpdate.php.

References $fileVersion.

220  {
221  return $this->fileVersion;
222  }

◆ getHotfixCurrentVersion()

ilDBUpdate::getHotfixCurrentVersion ( )

Get current hotfix version.

Definition at line 573 of file class.ilDBUpdate.php.

References readHotfixInfo().

Referenced by applyHotfix(), and getHotfixSteps().

574  {
575  $this->readHotfixInfo();
576  return $this->hotfix_current_version;
577  }
readHotfixInfo($a_force=false)
Get status of hotfix file.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHotfixFileVersion()

ilDBUpdate::getHotfixFileVersion ( )

Get current hotfix version.

Definition at line 594 of file class.ilDBUpdate.php.

References readHotfixInfo().

Referenced by applyHotfix(), and getHotfixSteps().

595  {
596  $this->readHotfixInfo();
597  return $this->hotfix_file_version;
598  }
readHotfixInfo($a_force=false)
Get status of hotfix file.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHotfixSteps()

ilDBUpdate::getHotfixSteps ( )

Get hotfix steps.

Returns
string steps from the update file

Definition at line 876 of file class.ilDBUpdate.php.

References getHotfixCurrentVersion(), getHotfixFileVersion(), getUpdateStepNr(), and readHotfixInfo().

877  {
878  $this->readHotfixInfo(true);
879 
880  $str = "";
881 
882  $f = $this->getHotfixFileVersion();
883  $c = $this->getHotfixCurrentVersion();
884 
885  if ($c < $f)
886  {
887  $msg = array();
888  for ($i=($c+1); $i<=$f; $i++)
889  {
890  $this->filecontent = $this->hotfix_content;
891 
892  $str.= $this->getUpdateStepNr($i, true);
893  }
894  }
895 
896  return $str;
897  }
getHotfixFileVersion()
Get current hotfix version.
readHotfixInfo($a_force=false)
Get status of hotfix file.
getHotfixCurrentVersion()
Get current hotfix version.
getUpdateStepNr($nr, $hotfix=false, $custom_update=false)
Get single update step for presentation.
+ Here is the call graph for this function:

◆ getRunningStatus()

ilDBUpdate::getRunningStatus ( )

Get running status.

Returns
int current runnning db step

Definition at line 179 of file class.ilDBUpdate.php.

180  {
181  include_once './Services/Administration/classes/class.ilSetting.php';
182  $set = new ilSetting("common", true);
183  $this->db_update_running = (integer) $set->get("db_update_running");
184 
185  return $this->db_update_running;
186  }
ILIAS Setting Class.

◆ getTables()

ilDBUpdate::getTables ( )

Definition at line 525 of file class.ilDBUpdate.php.

References $query, $res, $row, and getTableStatus().

526  {
527  $a = array();
528 
529  $query = "SHOW TABLES";
530  $res = $this->db->query($query);
531  while ($row = $res->fetchRow())
532  {
533  $status = $this->getTableStatus($row[0]);
534  $a[] = array(
535  "name" => $status["Table"],
536  "table" => $row[0],
537  "status" => $status["Msg_text"]
538  );
539  }
540  return $a;
541  }
getTableStatus($table)
+ Here is the call graph for this function:

◆ getTableStatus()

ilDBUpdate::getTableStatus (   $table)

Definition at line 543 of file class.ilDBUpdate.php.

References $query, $res, $row, and DB_FETCHMODE_ASSOC.

Referenced by getTables().

544  {
545  $a = array();
546 
547  $query = "ANALYZE TABLE ".$table;
548  $res = $this->db->query($query);
549  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
550  return $row;
551  }
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
+ Here is the caller graph for this function:

◆ getUpdateStepNr()

ilDBUpdate::getUpdateStepNr (   $nr,
  $hotfix = false,
  $custom_update = false 
)

Get single update step for presentation.

Definition at line 903 of file class.ilDBUpdate.php.

References $ilCtrlStructureReader, $ilErr, and $ilUser.

Referenced by getHotfixSteps(), and getUpdateSteps().

904  {
905  global $ilDB,$ilErr,$ilUser,$ilCtrlStructureReader,$ilModuleReader,$ilMySQLAbstraction;
906 
907  $str = "";
908 
909  //search for desired $nr
910  reset($this->filecontent);
911 
912  //init
913  $i = 0;
914 
915  //go through filecontent
916  while (!ereg("^<#".$nr.">", $this->filecontent[$i]) && $i<count($this->filecontent))
917  {
918  $i++;
919  }
920 
921  //update not found
922  if ($i == count($this->filecontent))
923  {
924  return false;
925  }
926 
927  $i++;
928 
929  //update found, now extract this update to a new array
930  $update = array();
931  while ($i<count($this->filecontent) && !ereg("^<#".($nr+1).">", $this->filecontent[$i]))
932  {
933  $str.= $this->filecontent[$i];
934  $i++;
935  }
936 
937  return "<pre><b><#".$nr."></b>\n".htmlentities($str)."</pre>";
938  }
$ilCtrlStructureReader
global $ilUser
Definition: imgupload.php:15
+ Here is the caller graph for this function:

◆ getUpdateSteps()

ilDBUpdate::getUpdateSteps (   $a_break = 0)

Get update steps as string (for presentation)

Returns
string steps from the update file

Definition at line 837 of file class.ilDBUpdate.php.

References $currentVersion, $fileVersion, $ilCtrlStructureReader, getFileForStep(), getUpdateStepNr(), and readDBUpdateFile().

838  {
839  global $ilCtrlStructureReader, $ilMySQLAbstraction;
840 
841  $str = "";
842 
843  $f = $this->fileVersion;
845 
846  if ($a_break > $this->currentVersion &&
847  $a_break < $this->fileVersion)
848  {
849  $f = $a_break;
850  }
851 
852  if ($c < $f)
853  {
854  $msg = array();
855  for ($i=($c+1); $i<=$f; $i++)
856  {
857  // check wether next update file must be loaded
858  if ($this->current_file != $this->getFileForStep($i))
859  {
860  $this->DB_UPDATE_FILE = $this->PATH."setup/sql/".$this->getFileForStep($i);
861  $this->readDBUpdateFile();
862  }
863 
864  $str.= $this->getUpdateStepNr($i);
865  }
866 
867  }
868  return $str;
869  }
getFileForStep($a_version)
Get db update file name for db step.
$ilCtrlStructureReader
getUpdateStepNr($nr, $hotfix=false, $custom_update=false)
Get single update step for presentation.
+ Here is the call graph for this function:

◆ hotfixAvailable()

ilDBUpdate::hotfixAvailable ( )

Get status of hotfix file.

Definition at line 649 of file class.ilDBUpdate.php.

References readHotfixInfo().

650  {
651  $this->readHotfixInfo();
652  if ($this->hotfix_file_version > $this->hotfix_current_version)
653  {
654  return true;
655  }
656  return false;
657  }
readHotfixInfo($a_force=false)
Get status of hotfix file.
+ Here is the call graph for this function:

◆ ilDBUpdate()

ilDBUpdate::ilDBUpdate (   $a_db_handler = 0,
  $tmp_flag = false 
)

constructor

Definition at line 34 of file class.ilDBUpdate.php.

References getCurrentVersion(), getFileForStep(), readDBUpdateFile(), readFileVersion(), and readLastUpdateFile().

35  {
36  // workaround to allow setup migration
37  if ($a_db_handler)
38  {
39  $this->db =& $a_db_handler;
40 
41  if ($tmp_flag)
42  {
43  $this->PATH = "./";
44  }
45  else
46  {
47  $this->PATH = "./";
48  //$this->PATH = "../";
49  }
50  }
51  else
52  {
53  global $mySetup;
54  $this->db = $mySetup->db;
55  $this->PATH = "./";
56  }
57 
58  $this->getCurrentVersion();
59 
60  // get update file for current version
61  $updatefile = $this->getFileForStep($this->currentVersion + 1);
62 
63  $this->current_file = $updatefile;
64  $this->DB_UPDATE_FILE = $this->PATH."setup/sql/".$updatefile;
65 
66  //
67  // NOTE: IF YOU SET THIS TO THE NEWEST FILE, CHANGE ALSO getFileForStep()
68  //
69  $this->LAST_UPDATE_FILE = $this->PATH."setup/sql/dbupdate_03.php";
70 
71  $this->readDBUpdateFile();
72  $this->readLastUpdateFile();
73  $this->readFileVersion();
74  }
getFileForStep($a_version)
Get db update file name for db step.
+ Here is the call graph for this function:

◆ initStep()

ilDBUpdate::initStep (   $i)

Init Step.

Definition at line 101 of file class.ilDBUpdate.php.

Referenced by applyUpdate().

102  {
103  //
104  }
+ Here is the caller graph for this function:

◆ loadXMLInfo()

ilDBUpdate::loadXMLInfo ( )

Definition at line 352 of file class.ilDBUpdate.php.

References $ilCtrlStructureReader, ilModule\getAvailableCoreModules(), ilService\getAvailableCoreServices(), and ILIAS_ABSOLUTE_PATH.

Referenced by applyCustomUpdates(), applyHotfix(), and applyUpdate().

353  {
354  global $ilCtrlStructureReader;
355 
356  // read module and service information into db
357  require_once "./setup/classes/class.ilModuleReader.php";
358  require_once "./setup/classes/class.ilServiceReader.php";
359  require_once "./setup/classes/class.ilCtrlStructureReader.php";
360 
361  require_once "./Services/Component/classes/class.ilModule.php";
362  require_once "./Services/Component/classes/class.ilService.php";
365 
366  $mr = new ilModuleReader("", "", "");
367  $mr->clearTables();
368  foreach($modules as $module)
369  {
370  $mr = new ilModuleReader(ILIAS_ABSOLUTE_PATH."/Modules/".$module["subdir"]."/module.xml",
371  $module["subdir"], "Modules");
372  $mr->getModules();
373  unset($mr);
374  }
375 
376  $sr = new ilServiceReader("", "", "");
377  $sr->clearTables();
378  foreach($services as $service)
379  {
380  $sr = new ilServiceReader(ILIAS_ABSOLUTE_PATH."/Services/".$service["subdir"]."/service.xml",
381  $service["subdir"], "Services");
382  $sr->getServices();
383  unset($sr);
384  }
385 
386  $ilCtrlStructureReader->readStructure();
387 
388  return true;
389  }
Class ilServiceReader.
$ilCtrlStructureReader
const ILIAS_ABSOLUTE_PATH
static getAvailableCoreServices()
Get all available core services.
Class ilModuleReader.
static getAvailableCoreModules()
Get all available core modules.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ optimizeTables()

ilDBUpdate::optimizeTables (   $tables)

Definition at line 553 of file class.ilDBUpdate.php.

References $_POST, $query, and $res.

554  {
555  $msg = array();
556  foreach ($_POST["tables"] as $key => $value)
557  {
558  $query = "OPTIMIZE TABLE ".$key;
559  $res = $this->db->query($query);
560  $msg[] = "table $key: ok";
561  }
562  return $msg;
563  }
$_POST['username']
Definition: cron.php:12

◆ readCustomUpdatesFileVersion()

ilDBUpdate::readCustomUpdatesFileVersion (   $a_file_content)

Definition at line 733 of file class.ilDBUpdate.php.

References $row.

Referenced by readCustomUpdatesInfo().

734  {
735  //go through filecontent and search for last occurence of <#x>
736  reset($a_file_content);
737  $regs = array();
738  foreach ($a_file_content as $row)
739  {
740  if (ereg("^<#([0-9]+)>", $row, $regs))
741  {
742  $version = $regs[1];
743  }
744  }
745 
746  return (integer) $version;
747  }
+ Here is the caller graph for this function:

◆ readCustomUpdatesInfo()

ilDBUpdate::readCustomUpdatesInfo (   $a_force = false)

Definition at line 749 of file class.ilDBUpdate.php.

References $GLOBALS, and readCustomUpdatesFileVersion().

Referenced by applyCustomUpdates(), customUpdatesAvailable(), getCustomUpdatesCurrentVersion(), getCustomUpdatesFileVersion(), and setCustomUpdatesCurrentVersion().

750  {
751  if ($this->custom_updates_info_read && !$a_force)
752  {
753  return;
754  }
755  include_once './Services/Administration/classes/class.ilSetting.php';
756  $GLOBALS["ilDB"] = $this->db;
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))
760  {
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);
763  $this->custom_updates_file_version = $this->readCustomUpdatesFileVersion($this->custom_updates_content);
764  }
765  $this->custom_updates_info_read = true;
766  }
ILIAS Setting Class.
$GLOBALS['ct_recipient']
readCustomUpdatesFileVersion($a_file_content)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readDBUpdateFile()

ilDBUpdate::readDBUpdateFile ( )

Definition at line 116 of file class.ilDBUpdate.php.

Referenced by applyUpdate(), getUpdateSteps(), ilDBUpdate(), and ilPluginDBUpdate\ilPluginDBUpdate().

117  {
118  if (!file_exists($this->DB_UPDATE_FILE))
119  {
120  $this->error = "no_db_update_file";
121  $this->filecontent = array();
122  return false;
123  }
124 
125  $this->filecontent = @file($this->DB_UPDATE_FILE);
126  return true;
127  }
+ Here is the caller graph for this function:

◆ readFileVersion()

ilDBUpdate::readFileVersion ( )

Definition at line 199 of file class.ilDBUpdate.php.

References $fileVersion, and $row.

Referenced by ilDBUpdate(), and ilPluginDBUpdate\ilPluginDBUpdate().

200  {
201  //go through filecontent and search for last occurence of <#x>
202  reset($this->lastfilecontent);
203  $regs = array();
204  foreach ($this->lastfilecontent as $row)
205  {
206  if (ereg("^<#([0-9]+)>", $row, $regs))
207  {
208  $version = $regs[1];
209  }
210  }
211 
212  $this->fileVersion = (integer) $version;
213  return $this->fileVersion;
214  }
+ Here is the caller graph for this function:

◆ readHotfixFileVersion()

ilDBUpdate::readHotfixFileVersion (   $a_file_content)

Set current hotfix version.

Definition at line 603 of file class.ilDBUpdate.php.

References $row.

Referenced by readHotfixInfo().

604  {
605  //go through filecontent and search for last occurence of <#x>
606  reset($a_file_content);
607  $regs = array();
608  foreach ($a_file_content as $row)
609  {
610  if (ereg("^<#([0-9]+)>", $row, $regs))
611  {
612  $version = $regs[1];
613  }
614  }
615 
616  return (integer) $version;
617  }
+ Here is the caller graph for this function:

◆ readHotfixInfo()

ilDBUpdate::readHotfixInfo (   $a_force = false)

Get status of hotfix file.

Definition at line 622 of file class.ilDBUpdate.php.

References $GLOBALS, ILIAS_VERSION_NUMERIC, and readHotfixFileVersion().

Referenced by applyHotfix(), getHotfixCurrentVersion(), getHotfixFileVersion(), getHotfixSteps(), hotfixAvailable(), and setHotfixCurrentVersion().

623  {
624  if ($this->hotfix_info_read && !$a_force)
625  {
626  return;
627  }
628  include_once './Services/Administration/classes/class.ilSetting.php';
629  $GLOBALS["ilDB"] = $this->db;
630  $this->hotfix_setting = new ilSetting("common", true);
631  $ilias_version = ILIAS_VERSION_NUMERIC;
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))
637  {
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]);
641  $this->hotfix_file_version = $this->readHotfixFileVersion($this->hotfix_content);
642  }
643  $this->hotfix_info_read = true;
644  }
ILIAS Setting Class.
const ILIAS_VERSION_NUMERIC
$GLOBALS['ct_recipient']
readHotfixFileVersion($a_file_content)
Set current hotfix version.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readLastUpdateFile()

ilDBUpdate::readLastUpdateFile ( )

Definition at line 129 of file class.ilDBUpdate.php.

Referenced by ilDBUpdate(), and ilPluginDBUpdate\ilPluginDBUpdate().

130  {
131  if (!file_exists($this->LAST_UPDATE_FILE))
132  {
133  $this->error = "no_last_update_file";
134  $this->lastfilecontent = array();
135  return false;
136  }
137 
138  $this->lastfilecontent = @file($this->LAST_UPDATE_FILE);
139  return true;
140  }
+ Here is the caller graph for this function:

◆ setCurrentVersion()

ilDBUpdate::setCurrentVersion (   $a_version)

Definition at line 151 of file class.ilDBUpdate.php.

Referenced by applyUpdateNr().

152  {
153  include_once './Services/Administration/classes/class.ilSetting.php';
154  $set = new ilSetting("common", true);
155  $set->set("db_version", $a_version);
156  $this->currentVersion = $a_version;
157 
158  return true;
159  }
ILIAS Setting Class.
+ Here is the caller graph for this function:

◆ setCustomUpdatesCurrentVersion()

ilDBUpdate::setCustomUpdatesCurrentVersion (   $a_version)

Definition at line 719 of file class.ilDBUpdate.php.

References readCustomUpdatesInfo().

Referenced by applyUpdateNr().

720  {
721  $this->readCustomUpdatesInfo();
722  $this->custom_updates_setting->set('db_version_custom', $a_version);
723  $this->custom_updates_current_version = $a_version;
724  return true;
725  }
readCustomUpdatesInfo($a_force=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHotfixCurrentVersion()

ilDBUpdate::setHotfixCurrentVersion (   $a_version)

Set current hotfix version.

Definition at line 582 of file class.ilDBUpdate.php.

References readHotfixInfo().

Referenced by applyUpdateNr().

583  {
584  $this->readHotfixInfo();
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;
588  return true;
589  }
readHotfixInfo($a_force=false)
Get status of hotfix file.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRunningStatus()

ilDBUpdate::setRunningStatus (   $a_nr)

Set running status for a step.

Parameters
intstep number

Definition at line 166 of file class.ilDBUpdate.php.

Referenced by applyUpdateNr().

167  {
168  include_once './Services/Administration/classes/class.ilSetting.php';
169  $set = new ilSetting("common", true);
170  $set->set("db_update_running", $a_nr);
171  $this->db_update_running = $a_nr;
172  }
ILIAS Setting Class.
+ Here is the caller graph for this function:

Field Documentation

◆ $currentVersion

ilDBUpdate::$currentVersion

◆ $DB_UPDATE_FILE

ilDBUpdate::$DB_UPDATE_FILE

db update file

Definition at line 17 of file class.ilDBUpdate.php.

◆ $fileVersion

ilDBUpdate::$fileVersion

Definition at line 29 of file class.ilDBUpdate.php.

Referenced by applyUpdate(), getFileVersion(), getUpdateSteps(), and readFileVersion().


The documentation for this class was generated from the following file: