ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilECSUpdateSteps9.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
26{
27 protected ilDBInterface $db;
28
29 private function ensure_index_exists(string $table, array $fields, string $name): void
30 {
31 if (!$this->db->indexExistsByFields($table, $fields)) {
32 $this->db->addIndex($table, $fields, $name);
33 }
34 }
35
36 private function ensure_indices_exist(): void
37 {
38 $this->ensure_index_exists('ecs_course_assignments', ['obj_id'], 'i1');
39 $this->ensure_index_exists('ecs_import', ['obj_id'], 'i1');
40 $this->ensure_index_exists('ecs_import', ['sub_id'], 'i2');
41 }
42
43 private function fix_duplicate_import_types(string $types): string
44 {
45 $pattern = '/^(a:\d+:\{.*\})\1+$/s';
46 return (preg_match($pattern, $types, $matches)) ? $matches[1] : $types;
47 }
48
49 public function prepare(ilDBInterface $db): void
50 {
51 $this->db = $db;
52 }
53
57 public function step_1(): void
58 {
59 $this->ensure_indices_exist();
60 $this->db->manipulate('UPDATE `ecs_course_assignments` inner join ecs_import on ecs_course_assignments.obj_id = ecs_import.obj_id SET ecs_course_assignments.`cms_sub_id`=ecs_import.sub_id WHERE ecs_import.sub_id is null;');
61 }
62
63 public function step_2(): void
64 {
69 $this->ensure_indices_exist();
70 }
71
72 public function step_3(): void
73 {
74 $query = 'SELECT sid, mid, import_types FROM ecs_part_settings';
75 $rows = $this->db->query($query);
76 while ($row = $rows->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
77 $fixed = $this->fix_duplicate_import_types($row->import_types);
78 if ($row->import_types !== $fixed) {
79 $update_query = 'UPDATE ecs_part_settings SET ' .
80 'import_types = ' . $this->db->quote($fixed, ilDBConstants::T_TEXT) . ' ' .
81 'WHERE sid = ' . $row->sid . ' ' .
82 'AND mid = ' . $row->mid;
83 $this->db->manipulate($update_query);
84 }
85 }
86 }
87}
Class ilECSUpdateSteps9 contains update steps for release 9.
prepare(ilDBInterface $db)
ensure_index_exists(string $table, array $fields, string $name)
fix_duplicate_import_types(string $types)
step_1()
Fix wrong data entries in ecs_course_assignments.
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...