ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilBackgroundTasksDBHotfixes10 Class Reference
+ Inheritance diagram for ilBackgroundTasksDBHotfixes10:
+ Collaboration diagram for ilBackgroundTasksDBHotfixes10:

Public Member Functions

 prepare (ilDBInterface $db)
 
 step_1 ()
 
 step_2 ()
 
- Public Member Functions inherited from ilDatabaseUpdateSteps
 prepare (\ilDBInterface $db)
 Prepare the execution of the steps. More...
 

Protected Attributes

ilDBInterface $db
 

Private Member Functions

 removeOrphanedRecords ()
 
 filterInnoDBTables (array $tables)
 

Private Attributes

const TABLE_BUCKET = 'il_bt_bucket'
 
const TABLE_TASK = 'il_bt_task'
 
const TABLE_VALUE = 'il_bt_value'
 
const TABLE_VALUE_TO_TASK = 'il_bt_value_to_task'
 
const FOREIGN_KEY_BUCKET_ROOT_TASK = 'il_bt_bucket_fk_root_task'
 
const FOREIGN_KEY_BUCKET_CURRENT_TASK = 'il_bt_bucket_fk_current_task'
 
const FOREIGN_KEY_TASK_BUCKET = 'il_bt_task_fk_bucket'
 
const FOREIGN_KEY_VALUE_BUCKET = 'il_bt_value_fk_bucket'
 
const FOREIGN_KEY_VALUE_PARENT_TASK = 'il_bt_value_fk_parent_task'
 
const FOREIGN_KEY_VALUE_TO_TASK_TASK = 'il_bt_value_to_task_fk_task'
 
const FOREIGN_KEY_VALUE_TO_TASK_VALUE = 'il_bt_value_to_task_fk_value'
 
const FOREIGN_KEY_VALUE_TO_TASK_BUCKET = 'il_bt_value_to_task_fk_bucket'
 

Detailed Description

Definition at line 23 of file class.ilBackgroundTasksDBHotfixes10.php.

Member Function Documentation

◆ filterInnoDBTables()

ilBackgroundTasksDBHotfixes10::filterInnoDBTables ( array  $tables)
private
Parameters
string[]$tables
Returns
array<string, true>

Definition at line 242 of file class.ilBackgroundTasksDBHotfixes10.php.

242 : array
243 {
244 $innodb_tables = [];
245
246 foreach ($tables as $table) {
247 if (!$this->db->tableExists($table)) {
248 continue;
249 }
250
251 $result = $this->db->queryF(
252 'SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s',
254 [$table]
255 );
256 $row = $this->db->fetchAssoc($result);
257
258 if (strcasecmp((string) ($row['ENGINE'] ?? ''), ilDBConstants::MYSQL_ENGINE_INNODB) === 0) {
259 $innodb_tables[] = $table;
260 }
261 }
262
263 return $innodb_tables;
264 }
const MYSQL_ENGINE_INNODB

References ilDBConstants\MYSQL_ENGINE_INNODB, and ilDBConstants\T_TEXT.

Referenced by step_2().

+ Here is the caller graph for this function:

◆ prepare()

ilBackgroundTasksDBHotfixes10::prepare ( ilDBInterface  $db)

Definition at line 41 of file class.ilBackgroundTasksDBHotfixes10.php.

41 : void
42 {
43 $this->db = $db;
44 }

References $db.

◆ removeOrphanedRecords()

ilBackgroundTasksDBHotfixes10::removeOrphanedRecords ( )
private

Definition at line 181 of file class.ilBackgroundTasksDBHotfixes10.php.

181 : void
182 {
183 if ($this->db->tableExists(self::TABLE_VALUE_TO_TASK)) {
184 $this->db->manipulate(
185 'DELETE vt FROM ' . self::TABLE_VALUE_TO_TASK . ' vt'
186 . ' LEFT JOIN ' . self::TABLE_BUCKET . ' b ON b.id = vt.bucket_id'
187 . ' LEFT JOIN ' . self::TABLE_TASK . ' t ON t.id = vt.task_id'
188 . ' LEFT JOIN ' . self::TABLE_VALUE . ' v ON v.id = vt.value_id'
189 . ' WHERE b.id IS NULL OR t.id IS NULL OR v.id IS NULL'
190 );
191 }
192
193 if ($this->db->tableExists(self::TABLE_VALUE)) {
194 $this->db->manipulate(
195 'UPDATE ' . self::TABLE_VALUE
196 . ' SET parent_task_id = NULL'
197 . ' WHERE parent_task_id = 0 OR has_parent_task = 0'
198 );
199
200 $this->db->manipulate(
201 'DELETE v FROM ' . self::TABLE_VALUE . ' v'
202 . ' LEFT JOIN ' . self::TABLE_BUCKET . ' b ON b.id = v.bucket_id'
203 . ' WHERE b.id IS NULL'
204 );
205
206 $this->db->manipulate(
207 'DELETE v FROM ' . self::TABLE_VALUE . ' v'
208 . ' LEFT JOIN ' . self::TABLE_TASK . ' t ON t.id = v.parent_task_id'
209 . ' WHERE v.parent_task_id IS NOT NULL AND t.id IS NULL'
210 );
211 }
212
213 if ($this->db->tableExists(self::TABLE_TASK)) {
214 $this->db->manipulate(
215 'DELETE t FROM ' . self::TABLE_TASK . ' t'
216 . ' LEFT JOIN ' . self::TABLE_BUCKET . ' b ON b.id = t.bucket_id'
217 . ' WHERE b.id IS NULL'
218 );
219 }
220
221 if ($this->db->tableExists(self::TABLE_BUCKET)) {
222 $this->db->manipulate(
223 'UPDATE ' . self::TABLE_BUCKET . ' b'
224 . ' LEFT JOIN ' . self::TABLE_TASK . ' rt ON rt.id = b.root_task_id'
225 . ' SET b.root_task_id = NULL'
226 . ' WHERE b.root_task_id IS NOT NULL AND b.root_task_id != 0 AND rt.id IS NULL'
227 );
228
229 $this->db->manipulate(
230 'UPDATE ' . self::TABLE_BUCKET . ' b'
231 . ' LEFT JOIN ' . self::TABLE_TASK . ' ct ON ct.id = b.current_task_id'
232 . ' SET b.current_task_id = NULL'
233 . ' WHERE b.current_task_id IS NOT NULL AND b.current_task_id != 0 AND ct.id IS NULL'
234 );
235 }
236 }

Referenced by step_2().

+ Here is the caller graph for this function:

◆ step_1()

ilBackgroundTasksDBHotfixes10::step_1 ( )

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

46 : void
47 {
48 $index_exists_user_id_state = $this->db->indexExistsByFields(self::TABLE_BUCKET, ['user_id', 'state']);
49 if (
50 $this->db->indexExistsByFields(self::TABLE_BUCKET, ['user_id'])
51 && !$index_exists_user_id_state
52 ) {
53 $this->db->dropIndexByFields(self::TABLE_BUCKET, ['user_id']);
54 }
55
56 if (!$index_exists_user_id_state) {
57 $this->db->addIndex(self::TABLE_BUCKET, ['user_id', 'state'], 'i1');
58 }
59
60 if (!$this->db->indexExistsByFields(self::TABLE_TASK, ['bucket_id'])) {
61 $this->db->addIndex(self::TABLE_TASK, ['bucket_id'], 'i1');
62 }
63
64 if (!$this->db->indexExistsByFields(self::TABLE_VALUE_TO_TASK, ['bucket_id'])) {
65 $this->db->addIndex(self::TABLE_VALUE_TO_TASK, ['bucket_id'], 'i3');
66 }
67 }

◆ step_2()

ilBackgroundTasksDBHotfixes10::step_2 ( )

Definition at line 69 of file class.ilBackgroundTasksDBHotfixes10.php.

69 : void
70 {
71 $tables = [
76 ];
77
78 if ($tables !== $this->filterInnoDBTables($tables)) {
79 return;
80 }
81
82 $this->removeOrphanedRecords();
83
84 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_TASK_BUCKET, self::TABLE_TASK)) {
85 $this->db->addForeignKey(
86 self::FOREIGN_KEY_TASK_BUCKET,
87 ['bucket_id'],
88 self::TABLE_TASK,
89 ['id'],
90 self::TABLE_BUCKET,
91 null,
93 );
94 }
95
96 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_VALUE_BUCKET, self::TABLE_VALUE)) {
97 $this->db->addForeignKey(
98 self::FOREIGN_KEY_VALUE_BUCKET,
99 ['bucket_id'],
100 self::TABLE_VALUE,
101 ['id'],
102 self::TABLE_BUCKET,
103 null,
105 );
106 }
107
108 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_VALUE_PARENT_TASK, self::TABLE_VALUE)) {
109 $this->db->addForeignKey(
110 self::FOREIGN_KEY_VALUE_PARENT_TASK,
111 ['parent_task_id'],
112 self::TABLE_VALUE,
113 ['id'],
114 self::TABLE_TASK,
115 null,
117 );
118 }
119
120 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_VALUE_TO_TASK_TASK, self::TABLE_VALUE_TO_TASK)) {
121 $this->db->addForeignKey(
122 self::FOREIGN_KEY_VALUE_TO_TASK_TASK,
123 ['task_id'],
124 self::TABLE_VALUE_TO_TASK,
125 ['id'],
126 self::TABLE_TASK,
127 null,
129 );
130 }
131
132 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_VALUE_TO_TASK_VALUE, self::TABLE_VALUE_TO_TASK)) {
133 $this->db->addForeignKey(
134 self::FOREIGN_KEY_VALUE_TO_TASK_VALUE,
135 ['value_id'],
136 self::TABLE_VALUE_TO_TASK,
137 ['id'],
138 self::TABLE_VALUE,
139 null,
141 );
142 }
143
144 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_VALUE_TO_TASK_BUCKET, self::TABLE_VALUE_TO_TASK)) {
145 $this->db->addForeignKey(
146 self::FOREIGN_KEY_VALUE_TO_TASK_BUCKET,
147 ['bucket_id'],
148 self::TABLE_VALUE_TO_TASK,
149 ['id'],
150 self::TABLE_BUCKET,
151 null,
153 );
154 }
155
156 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_BUCKET_ROOT_TASK, self::TABLE_BUCKET)) {
157 $this->db->addForeignKey(
158 self::FOREIGN_KEY_BUCKET_ROOT_TASK,
159 ['root_task_id'],
160 self::TABLE_BUCKET,
161 ['id'],
162 self::TABLE_TASK,
163 null,
164 ForeignKeyConstraints::SET_NULL
165 );
166 }
167
168 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_BUCKET_CURRENT_TASK, self::TABLE_BUCKET)) {
169 $this->db->addForeignKey(
170 self::FOREIGN_KEY_BUCKET_CURRENT_TASK,
171 ['current_task_id'],
172 self::TABLE_BUCKET,
173 ['id'],
174 self::TABLE_TASK,
175 null,
176 ForeignKeyConstraints::SET_NULL
177 );
178 }
179 }
const CASCADE
Definition: Title.php:33

References CASCADE, filterInnoDBTables(), removeOrphanedRecords(), TABLE_BUCKET, TABLE_TASK, TABLE_VALUE, and TABLE_VALUE_TO_TASK.

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilBackgroundTasksDBHotfixes10::$db
protected

Definition at line 39 of file class.ilBackgroundTasksDBHotfixes10.php.

Referenced by prepare().

◆ FOREIGN_KEY_BUCKET_CURRENT_TASK

const ilBackgroundTasksDBHotfixes10::FOREIGN_KEY_BUCKET_CURRENT_TASK = 'il_bt_bucket_fk_current_task'
private

Definition at line 31 of file class.ilBackgroundTasksDBHotfixes10.php.

◆ FOREIGN_KEY_BUCKET_ROOT_TASK

const ilBackgroundTasksDBHotfixes10::FOREIGN_KEY_BUCKET_ROOT_TASK = 'il_bt_bucket_fk_root_task'
private

Definition at line 30 of file class.ilBackgroundTasksDBHotfixes10.php.

◆ FOREIGN_KEY_TASK_BUCKET

const ilBackgroundTasksDBHotfixes10::FOREIGN_KEY_TASK_BUCKET = 'il_bt_task_fk_bucket'
private

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

◆ FOREIGN_KEY_VALUE_BUCKET

const ilBackgroundTasksDBHotfixes10::FOREIGN_KEY_VALUE_BUCKET = 'il_bt_value_fk_bucket'
private

Definition at line 33 of file class.ilBackgroundTasksDBHotfixes10.php.

◆ FOREIGN_KEY_VALUE_PARENT_TASK

const ilBackgroundTasksDBHotfixes10::FOREIGN_KEY_VALUE_PARENT_TASK = 'il_bt_value_fk_parent_task'
private

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

◆ FOREIGN_KEY_VALUE_TO_TASK_BUCKET

const ilBackgroundTasksDBHotfixes10::FOREIGN_KEY_VALUE_TO_TASK_BUCKET = 'il_bt_value_to_task_fk_bucket'
private

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

◆ FOREIGN_KEY_VALUE_TO_TASK_TASK

const ilBackgroundTasksDBHotfixes10::FOREIGN_KEY_VALUE_TO_TASK_TASK = 'il_bt_value_to_task_fk_task'
private

Definition at line 35 of file class.ilBackgroundTasksDBHotfixes10.php.

◆ FOREIGN_KEY_VALUE_TO_TASK_VALUE

const ilBackgroundTasksDBHotfixes10::FOREIGN_KEY_VALUE_TO_TASK_VALUE = 'il_bt_value_to_task_fk_value'
private

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

◆ TABLE_BUCKET

const ilBackgroundTasksDBHotfixes10::TABLE_BUCKET = 'il_bt_bucket'
private

Definition at line 25 of file class.ilBackgroundTasksDBHotfixes10.php.

Referenced by step_2().

◆ TABLE_TASK

const ilBackgroundTasksDBHotfixes10::TABLE_TASK = 'il_bt_task'
private

Definition at line 26 of file class.ilBackgroundTasksDBHotfixes10.php.

Referenced by step_2().

◆ TABLE_VALUE

const ilBackgroundTasksDBHotfixes10::TABLE_VALUE = 'il_bt_value'
private

Definition at line 27 of file class.ilBackgroundTasksDBHotfixes10.php.

Referenced by step_2().

◆ TABLE_VALUE_TO_TASK

const ilBackgroundTasksDBHotfixes10::TABLE_VALUE_TO_TASK = 'il_bt_value_to_task'
private

Definition at line 28 of file class.ilBackgroundTasksDBHotfixes10.php.

Referenced by step_2().


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