ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCertificateDatabaseUpdateSteps.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  protected ilDBInterface $db;
24 
25  public function prepare(ilDBInterface $db): void
26  {
27  $this->db = $db;
28  }
29 
30  public function step_1(): void
31  {
32  if ($this->db->tableExists('il_cert_template') && $this->db->tableColumnExists('il_cert_template', 'certificate_content_bu')) {
33  $this->db->dropTableColumn('il_cert_template', 'certificate_content_bu');
34  }
35  if ($this->db->tableExists('il_cert_user_cert') && $this->db->tableColumnExists('il_cert_user_cert', 'certificate_content_bu')) {
36  $this->db->dropTableColumn('il_cert_user_cert', 'certificate_content_bu');
37  }
38  }
39 
40  public function step_2(): void
41  {
42  if ($this->db->tableExists('il_cert_template') && $this->db->tableColumnExists('il_cert_template', 'certificate_content_backup')) {
43  $this->db->dropTableColumn('il_cert_template', 'certificate_content_backup');
44  }
45  if ($this->db->tableExists('il_cert_user_cert') && $this->db->tableColumnExists('il_cert_user_cert', 'certificate_content_backup')) {
46  $this->db->dropTableColumn('il_cert_user_cert', 'certificate_content_backup');
47  }
48  }
49 
50  public function step_3(): void
51  {
52  if ($this->db->tableExists('il_cert_bgtask_migr')) {
53  $this->db->dropTable('il_cert_bgtask_migr');
54  }
55  }
56 
57  public function step_4(): void
58  {
59  if ($this->db->tableExists('il_cert_user_cert') && $this->db->tableColumnExists('il_cert_user_cert', 'user_id')) {
60  $this->db->renameTableColumn('il_cert_user_cert', 'user_id', 'usr_id');
61  }
62  }
63 
64  public function step_5(): void
65  {
66  if (
67  $this->db->tableExists('il_cert_template') &&
68  !$this->db->indexExistsByFields('il_cert_template', ['background_image_path', 'currently_active'])
69  ) {
70  $this->db->addIndex('il_cert_template', ['background_image_path', 'currently_active'], 'i5');
71  }
72 
73  if (
74  $this->db->tableExists('il_cert_user_cert') &&
75  !$this->db->indexExistsByFields('il_cert_user_cert', ['background_image_path', 'currently_active'])
76  ) {
77  $this->db->addIndex('il_cert_user_cert', ['background_image_path', 'currently_active'], 'i7');
78  }
79  }
80 
81  public function step_6(): void
82  {
83  if ($this->db->tableExists('il_cert_user_cert') &&
84  !$this->db->tableColumnExists('il_cert_user_cert', 'certificate_id')) {
85  $this->db->addTableColumn('il_cert_user_cert', 'certificate_id', [
86  'type' => ilDBConstants::T_TEXT,
87  'length' => 64,
88  'notnull' => false,
89  ]);
90  }
91  }
92 
93  public function step_7(): void
94  {
95  if ($this->db->tableExists('il_cert_user_cert') &&
96  $this->db->tableColumnExists('il_cert_user_cert', 'certificate_id')) {
97 
98  try {
99  $this->db->dropUniqueConstraint('il_cert_user_cert', 'c1');
100  } catch (ilDatabaseException|PDOException) {
101  // Nothing to do
102  }
103 
104  $this->db->manipulateF(
105  'UPDATE il_cert_user_cert SET certificate_id = %s WHERE certificate_id IS NULL',
107  ['-']
108  );
109 
110  $this->db->modifyTableColumn('il_cert_user_cert', 'certificate_id', [
111  'type' => ilDBConstants::T_TEXT,
112  'length' => 64,
113  'notnull' => true,
114  'default' => '-'
115  ]);
116  }
117  }
118 
119  public function step_8(): void
120  {
121  $query = 'SELECT COUNT(*) cnt FROM il_cert_user_cert WHERE certificate_id = ' .
122  $this->db->quote('-', ilDBConstants::T_TEXT);
123  $res = $this->db->query($query);
124  $num = (int) $this->db->fetchAssoc($res)['cnt'];
125  if ($num === 0) {
126  $this->db->addUniqueConstraint('il_cert_user_cert', ['certificate_id'], 'c1');
127  }
128  }
129 
130  public function step_9(): void
131  {
132  if (
133  $this->db->tableExists('il_cert_user_cert')
134  ) {
135  $this->db->addTableColumn(
136  'il_cert_user_cert',
137  'background_image_ident',
138  [
139  'type' => ilDBConstants::T_TEXT,
140  'length' => 255,
141  'notnull' => false,
142  ]
143  );
144 
145  $this->db->addTableColumn(
146  'il_cert_user_cert',
147  'thumbnail_image_ident',
148  [
149  'type' => ilDBConstants::T_TEXT,
150  'length' => 255,
151  'notnull' => false,
152  ]
153  );
154  }
155 
156  if (
157  $this->db->tableExists('il_cert_template')
158  ) {
159  $this->db->addTableColumn(
160  'il_cert_template',
161  'background_image_ident',
162  [
163  'type' => ilDBConstants::T_TEXT,
164  'length' => 255,
165  'notnull' => false,
166  ]
167  );
168 
169  $this->db->addTableColumn(
170  'il_cert_template',
171  'thumbnail_image_ident',
172  [
173  'type' => ilDBConstants::T_TEXT,
174  'length' => 255,
175  'notnull' => false,
176  ]
177  );
178  }
179 
180  $res = $this->db->query(
181  'SELECT value FROM settings WHERE keyword = ' .
182  $this->db->quote('defaultImageFileName', ilDBConstants::T_TEXT) . ' AND module = ' .
183  $this->db->quote('certificate', ilDBConstants::T_TEXT)
184  );
185  $row = $this->db->fetchAssoc($res);
186  $defaultImageFileName = $row['value'] ?? '';
187 
188  $this->db->manipulate(
189  'DELETE FROM settings WHERE keyword = ' .
190  $this->db->quote('defaultImageFileName', ilDBConstants::T_TEXT) . ' AND module = ' .
191  $this->db->quote('certificate', ilDBConstants::T_TEXT)
192  );
193  $this->db->insert('settings', [
194  'module' => [ilDBConstants::T_TEXT, 'certificate'],
195  'keyword' => [ilDBConstants::T_TEXT, 'cert_bg_image'],
196  'value' => [ilDBConstants::T_TEXT, $defaultImageFileName],
197  ]);
198  }
199 }
$res
Definition: ltiservices.php:66