19declare(strict_types=1);
48 $index_exists_user_id_state = $this->db->indexExistsByFields(self::TABLE_BUCKET, [
'user_id',
'state']);
50 $this->db->indexExistsByFields(self::TABLE_BUCKET, [
'user_id'])
51 && !$index_exists_user_id_state
53 $this->db->dropIndexByFields(self::TABLE_BUCKET, [
'user_id']);
56 if (!$index_exists_user_id_state) {
57 $this->db->addIndex(self::TABLE_BUCKET, [
'user_id',
'state'],
'i1');
60 if (!$this->db->indexExistsByFields(self::TABLE_TASK, [
'bucket_id'])) {
61 $this->db->addIndex(self::TABLE_TASK, [
'bucket_id'],
'i1');
64 if (!$this->db->indexExistsByFields(self::TABLE_VALUE_TO_TASK, [
'bucket_id'])) {
65 $this->db->addIndex(self::TABLE_VALUE_TO_TASK, [
'bucket_id'],
'i3');
84 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_TASK_BUCKET, self::TABLE_TASK)) {
85 $this->db->addForeignKey(
86 self::FOREIGN_KEY_TASK_BUCKET,
96 if (!$this->db->foreignKeyExists(self::FOREIGN_KEY_VALUE_BUCKET, self::TABLE_VALUE)) {
97 $this->db->addForeignKey(
98 self::FOREIGN_KEY_VALUE_BUCKET,
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,
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,
124 self::TABLE_VALUE_TO_TASK,
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,
136 self::TABLE_VALUE_TO_TASK,
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,
148 self::TABLE_VALUE_TO_TASK,
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,
164 ForeignKeyConstraints::SET_NULL
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,
176 ForeignKeyConstraints::SET_NULL
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'
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'
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'
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'
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'
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'
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'
246 foreach ($tables as $table) {
247 if (!$this->db->tableExists($table)) {
251 $result = $this->db->queryF(
252 'SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s',
256 $row = $this->db->fetchAssoc($result);
259 $innodb_tables[] = $table;
263 return $innodb_tables;
const FOREIGN_KEY_VALUE_TO_TASK_BUCKET
const FOREIGN_KEY_VALUE_BUCKET
const FOREIGN_KEY_VALUE_TO_TASK_VALUE
const FOREIGN_KEY_BUCKET_ROOT_TASK
const FOREIGN_KEY_BUCKET_CURRENT_TASK
const FOREIGN_KEY_VALUE_PARENT_TASK
const FOREIGN_KEY_VALUE_TO_TASK_TASK
prepare(ilDBInterface $db)
filterInnoDBTables(array $tables)
const TABLE_VALUE_TO_TASK
const FOREIGN_KEY_TASK_BUCKET
const MYSQL_ENGINE_INNODB
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...