ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
DualOptInDatabaseUpdateSteps.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data\UUID\Factory as UUIDFactory;
24
26{
27 protected \ilDBInterface $db;
28
29 public function prepare(\ilDBInterface $db): void
30 {
31 $this->db = $db;
32 }
33
34 public function step_1(): void
35 {
36 if ($this->db->tableExists('reg_dual_opt_in')) {
37 return;
38 }
39
40 $fields = [
41 'id' => [
42 'type' => \ilDBConstants::T_TEXT,
43 'length' => 36,
44 'fixed' => true,
45 'notnull' => true,
46 ],
47 'usr_id' => [
49 'length' => 8,
50 'notnull' => true
51 ],
52 'reg_hash' => [
53 'type' => \ilDBConstants::T_TEXT,
54 'length' => 16,
55 'fixed' => true,
56 'notnull' => true
57 ],
58 'creation_date' => [
60 'length' => 8,
61 'notnull' => true
62 ]
63 ];
64
65 $this->db->createTable('reg_dual_opt_in', $fields);
66 $this->db->addPrimaryKey('reg_dual_opt_in', ['id']);
67 }
68
69 public function step_2(): void
70 {
71 if (!$this->db->tableExists('usr_data') ||
72 !$this->db->tableColumnExists('usr_data', 'reg_hash')) {
73 return;
74 }
75
76 $res = $this->db->query(
77 <<<SQL
78 SELECT ud.usr_id, ud.reg_hash, ud.create_date
79 FROM usr_data ud
80 INNER JOIN object_data od ON od.obj_id = ud.usr_id
81 WHERE ud.reg_hash IS NOT NULL AND ud.reg_hash <> ''
82SQL
83 );
84
85 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
86 $this->db->manipulateF(
87 'INSERT INTO reg_dual_opt_in (id, usr_id, reg_hash, creation_date) VALUES (%s, %s, %s, %s)',
88 [
93 ],
94 [
95 (new UUIDFactory())->uuid4(),
96 $row->usr_id,
97 $row->reg_hash,
98 (new \DateTimeImmutable($row->create_date, new \DateTimeZone('UTC')))->getTimestamp()
99 ]
100 );
101 }
102 }
103
104 public function step_3(): void
105 {
106 if (!$this->db->tableExists('usr_data') ||
107 !$this->db->tableColumnExists('usr_data', 'reg_hash')) {
108 return;
109 }
110
111 $this->db->dropTableColumn('usr_data', 'reg_hash');
112 }
113
114 public function step_4(): void
115 {
116 if ($this->db->tableExists('reg_dual_opt_in') &&
117 !$this->db->indexExistsByFields('reg_dual_opt_in', ['reg_hash'])) {
118 $this->db->addIndex('reg_dual_opt_in', ['reg_hash'], 'i1');
119 }
120
121 if ($this->db->tableExists('reg_dual_opt_in') &&
122 !$this->db->indexExistsByFields('reg_dual_opt_in', ['usr_id'])) {
123 $this->db->addIndex('reg_dual_opt_in', ['usr_id'], 'i2');
124 }
125 }
126}
prepare(\ilDBInterface $db)
Prepare the execution of the steps.
return true
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69