ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilPluginDBUpdate Class Reference

Database Update class. More...

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

Public Member Functions

 __construct (\ilDBInterface $db, \ilPluginInfo $plugin)
 constructor @noinspection 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"
 
string $error = ''
 
- 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 @noinspection MagicMethodsValidityInspection

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

49 {
50 $this->client_ini = null;
51 $this->db = $db;
52 $this->plugin = $plugin;
53
54 $this->db_update_file = $this->getDBUpdateScriptName();
55
56 $this->current_version = $plugin->getCurrentDBVersion() ?? 0;
57
58 $this->readDBUpdateFile();
59 $this->readFileVersion();
60
61 $class_map = require ILIAS_ABSOLUTE_PATH . '/vendor/composer/vendor/composer/autoload_classmap.php';
62 $this->ctrl_structure_iterator = new ilCtrlArrayIterator($class_map);
63 }
Class ilCtrlArrayIterator.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ applyUpdate()

ilPluginDBUpdate::applyUpdate ( )

Apply update.

Returns
false|void

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

129 {
130 $ilCtrlStructureReader = null;
131 $ilDB = null;
132 $this->initGlobalsRequiredForUpdateSteps($ilCtrlStructureReader, $ilDB);
133
136
137 $this->updateMsg = 'no_changes';
139 $msg = [];
140 for ($i = ($current_version + 1); $i <= $file_version; $i++) {
141 if ($this->applyUpdateNr($i) === false) {
142 $msg[] = 'msg: update_error - ' . $this->error . '; nr: ' . $i . ';';
143 $this->updateMsg = implode("\n", $msg);
144
145 return false;
146 }
147
148 $msg[] = 'msg: update_applied; nr: ' . $i . ';';
149 }
150
151 $this->updateMsg = implode('\n', $msg);
152 }
153 }
error(string $a_errmsg)
initGlobalsRequiredForUpdateSteps(?ilCtrlStructureReader &$ilCtrlStructureReader, ?ilDBInterface &$ilDB)
applyUpdateNr(int $nr, bool $custom_update=false)
Apply a custom database update or a plugin update.

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

+ Here is the call graph for this function:

◆ checkQuery()

ilPluginDBUpdate::checkQuery ( string  $q)
protected

Reimplemented from ilDBUpdate.

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

101 : bool
102 {
103 if ((is_int(stripos($q, 'create table')) || is_int(stripos($q, 'alter table')) ||
104 is_int(stripos($q, 'drop table')))
105 && !is_int(stripos($q, $this->getTablePrefix()))) {
106 return false;
107 }
108
109 return true;
110 }
$q
Definition: shib_logout.php:23

References $q, and getTablePrefix().

+ Here is the call graph for this function:

◆ getCurrentVersion()

ilPluginDBUpdate::getCurrentVersion ( )

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

91 : int
92 {
94 }

References $current_version.

◆ getDBUpdateScriptName()

ilPluginDBUpdate::getDBUpdateScriptName ( )
private

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

119 : string
120 {
121 return $this->plugin->getPath() . self::PLUGIN_UPDATE_FILE;
122 }

References PLUGIN_UPDATE_FILE.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getTablePrefix()

ilPluginDBUpdate::getTablePrefix ( )
private

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

112 : string
113 {
114 $component = $this->plugin->getComponent();
115 $slot = $this->plugin->getPluginSlot();
116 return $component->getId() . '_' . $slot->getId() . '_' . $this->plugin->getId();
117 }

Referenced by checkQuery().

+ Here is the caller graph for this function:

◆ readDBUpdateFile()

ilPluginDBUpdate::readDBUpdateFile ( )
private

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

65 : void
66 {
67 if (!file_exists($this->db_update_file)) {
68 $this->error = 'no_db_update_file';
69 $this->filecontent = [];
70 return;
71 }
72
73 $this->filecontent = @file($this->db_update_file);
74 }

References error().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readFileVersion()

ilPluginDBUpdate::readFileVersion ( )
private

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

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

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

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCurrentVersion()

ilPluginDBUpdate::setCurrentVersion ( ?int  $a_version)
protected

Reimplemented from ilDBUpdate.

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

96 : void
97 {
98 $this->current_version = $a_version;
99 }

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.

◆ $error

string ilPluginDBUpdate::$error = ''
protected

Definition at line 40 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.

Referenced by getDBUpdateScriptName().


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