ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilPluginDBUpdate Class Reference

Database Update class. More...

+ Inheritance diagram for ilPluginDBUpdate:
+ Collaboration diagram for ilPluginDBUpdate:

Public Member Functions

 __construct (\ilDBInterface $db, \ilPluginInfo $plugin)
 constructor MagicMethodsValidityInspection More...
 
 getCurrentVersion ()
 
 applyUpdate ()
 Apply update. More...
 
- Public Member Functions inherited from ilDBUpdate
 __construct (protected ilDBInterface $db, protected ?ilIniFile $client_ini=null)
 
 getCustomUpdatesCurrentVersion ()
 
 getCustomUpdatesFileVersion ()
 
 applyCustomUpdates ()
 

Protected Member Functions

 setCurrentVersion (?int $a_version)
 
 checkQuery (string $q)
 
- Protected Member Functions inherited from ilDBUpdate
 checkQuery (string $q)
 
 initGlobalsRequiredForUpdateSteps (?ilCtrlStructureReader &$ilCtrlStructureReader, ?ilDBInterface &$ilDB)
 
 applyUpdateNr (int $nr, bool $custom_update=false)
 Apply a custom database update or a plugin update. More...
 
 setCurrentVersion (?int $a_version)
 

Protected Attributes

const PLUGIN_UPDATE_FILE = "/sql/dbupdate.php"
 
- Protected Attributes inherited from ilDBUpdate
string $updateMsg
 
Iterator $ctrl_structure_iterator
 
string $error
 
string $PATH = "./"
 
array $filecontent
 

Private Member Functions

 readDBUpdateFile ()
 
 readFileVersion ()
 
 getTablePrefix ()
 
 getDBUpdateScriptName ()
 

Private Attributes

ilPluginInfo $plugin
 
string $db_update_file
 
int $current_version
 
int $file_version = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilPluginDBUpdate::__construct ( \ilDBInterface  $db,
\ilPluginInfo  $plugin 
)

constructor MagicMethodsValidityInspection

Definition at line 44 of file class.ilPluginDBUpdate.php.

References $plugin, ilPluginInfo\getCurrentDBVersion(), getDBUpdateScriptName(), null, readDBUpdateFile(), and readFileVersion().

47  {
48  $this->client_ini = null;
49  $this->db = $db;
50  $this->plugin = $plugin;
51 
52  $this->db_update_file = $this->getDBUpdateScriptName();
53 
54  $this->current_version = $plugin->getCurrentDBVersion() ?? 0;
55 
56  $this->readDBUpdateFile();
57  $this->readFileVersion();
58 
59  $class_map = require ILIAS_ABSOLUTE_PATH . '/vendor/composer/vendor/composer/autoload_classmap.php';
60  $this->ctrl_structure_iterator = new ilCtrlArrayIterator($class_map);
61  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Class ilCtrlArrayIterator.
+ Here is the call graph for this function:

Member Function Documentation

◆ applyUpdate()

ilPluginDBUpdate::applyUpdate ( )

Apply update.

Returns
false|void

Definition at line 126 of file class.ilPluginDBUpdate.php.

References $current_version, $file_version, $ilDB, ilDBUpdate\applyUpdateNr(), ilDBUpdate\initGlobalsRequiredForUpdateSteps(), and null.

127  {
128  $ilCtrlStructureReader = null;
129  $ilDB = null;
130  $this->initGlobalsRequiredForUpdateSteps($ilCtrlStructureReader, $ilDB);
131 
134 
135  $this->updateMsg = 'no_changes';
137  $msg = [];
138  for ($i = ($current_version + 1); $i <= $file_version; $i++) {
139  if ($this->applyUpdateNr($i) === false) {
140  $msg[] = 'msg: update_error - ' . $this->error . '; nr: ' . $i . ';';
141  $this->updateMsg = implode("\n", $msg);
142 
143  return false;
144  }
145 
146  $msg[] = 'msg: update_applied; nr: ' . $i . ';';
147  }
148 
149  $this->updateMsg = implode('\n', $msg);
150  }
151  }
applyUpdateNr(int $nr, bool $custom_update=false)
Apply a custom database update or a plugin update.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
initGlobalsRequiredForUpdateSteps(?ilCtrlStructureReader &$ilCtrlStructureReader, ?ilDBInterface &$ilDB)
+ Here is the call graph for this function:

◆ checkQuery()

ilPluginDBUpdate::checkQuery ( string  $q)
protected

Definition at line 99 of file class.ilPluginDBUpdate.php.

References getTablePrefix().

99  : bool
100  {
101  if ((is_int(stripos($q, 'create table')) || is_int(stripos($q, 'alter table')) ||
102  is_int(stripos($q, 'drop table')))
103  && !is_int(stripos($q, $this->getTablePrefix()))) {
104  return false;
105  }
106 
107  return true;
108  }
$q
Definition: shib_logout.php:21
+ Here is the call graph for this function:

◆ getCurrentVersion()

ilPluginDBUpdate::getCurrentVersion ( )

Definition at line 89 of file class.ilPluginDBUpdate.php.

References $current_version.

89  : int
90  {
92  }

◆ getDBUpdateScriptName()

ilPluginDBUpdate::getDBUpdateScriptName ( )
private

Definition at line 117 of file class.ilPluginDBUpdate.php.

Referenced by __construct().

117  : string
118  {
119  return $this->plugin->getPath() . self::PLUGIN_UPDATE_FILE;
120  }
+ Here is the caller graph for this function:

◆ getTablePrefix()

ilPluginDBUpdate::getTablePrefix ( )
private

Definition at line 110 of file class.ilPluginDBUpdate.php.

Referenced by checkQuery().

110  : string
111  {
112  $component = $this->plugin->getComponent();
113  $slot = $this->plugin->getPluginSlot();
114  return $component->getId() . '_' . $slot->getId() . '_' . $this->plugin->getId();
115  }
+ Here is the caller graph for this function:

◆ readDBUpdateFile()

ilPluginDBUpdate::readDBUpdateFile ( )
private

Definition at line 63 of file class.ilPluginDBUpdate.php.

Referenced by __construct().

63  : void
64  {
65  if (!file_exists($this->db_update_file)) {
66  $this->error = 'no_db_update_file';
67  $this->filecontent = [];
68  return;
69  }
70 
71  $this->filecontent = @file($this->db_update_file);
72  }
+ Here is the caller graph for this function:

◆ readFileVersion()

ilPluginDBUpdate::readFileVersion ( )
private

Definition at line 74 of file class.ilPluginDBUpdate.php.

References $version, and ILIAS\Repository\int().

Referenced by __construct().

74  : void
75  {
76  //go through filecontent and search for last occurence of <#x>
77  reset($this->filecontent);
78  $regs = [];
79  $version = 0;
80  foreach ($this->filecontent as $row) {
81  if (preg_match('/^<\#([0-9]+)>/', $row, $regs)) {
82  $version = $regs[1];
83  }
84  }
85 
86  $this->file_version = (int) $version;
87  }
$version
Definition: plugin.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCurrentVersion()

ilPluginDBUpdate::setCurrentVersion ( ?int  $a_version)
protected

Definition at line 94 of file class.ilPluginDBUpdate.php.

94  : void
95  {
96  $this->current_version = $a_version;
97  }

Field Documentation

◆ $current_version

int ilPluginDBUpdate::$current_version
private

Definition at line 37 of file class.ilPluginDBUpdate.php.

Referenced by applyUpdate(), and getCurrentVersion().

◆ $db_update_file

string ilPluginDBUpdate::$db_update_file
private

Definition at line 36 of file class.ilPluginDBUpdate.php.

◆ $file_version

int ilPluginDBUpdate::$file_version = null
private

Definition at line 38 of file class.ilPluginDBUpdate.php.

Referenced by applyUpdate().

◆ $plugin

ilPluginInfo ilPluginDBUpdate::$plugin
private

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

Referenced by __construct().

◆ PLUGIN_UPDATE_FILE

const ilPluginDBUpdate::PLUGIN_UPDATE_FILE = "/sql/dbupdate.php"
protected

Definition at line 32 of file class.ilPluginDBUpdate.php.


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