ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
DBUpdateSteps10.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\User\Setup;
22 
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  $this->db->manipulate(
37  'DELETE FROM usr_pref WHERE keyword = ' . $this->db->quote('hits_per_page', \ilDBConstants::T_TEXT)
38  );
39  $this->db->manipulate(
40  'DELETE FROM settings WHERE ' . $this->db->like('keyword', \ilDBConstants::T_TEXT, '%hits_per_page%')
41  );
42  }
43 
44  public function step_2(): void
45  {
46  if (!$this->db->tableColumnExists(ChangeMailTokenDBRepository::TABLE_NAME, 'usr_id')) {
47  $this->db->addTableColumn(
48  ChangeMailTokenDBRepository::TABLE_NAME,
49  'usr_id',
50  [
51  'type' => \ilDBConstants::T_INTEGER,
52  'notnull' => true,
53  'length' => 8
54  ]
55  );
56  }
57  if (!$this->db->tableColumnExists(ChangeMailTokenDBRepository::TABLE_NAME, 'status')) {
58  $this->db->addTableColumn(
59  ChangeMailTokenDBRepository::TABLE_NAME,
60  'status',
61  [
62  'type' => \ilDBConstants::T_INTEGER,
63  'notnull' => false,
64  'length' => 1
65  ]
66  );
67  }
68  if ($this->db->tableColumnExists(ChangeMailTokenDBRepository::TABLE_NAME, 'valid_until')) {
69  $this->db->renameTableColumn(
70  ChangeMailTokenDBRepository::TABLE_NAME,
71  'valid_until',
72  'created_ts'
73  );
74  }
75  if (!$this->db->primaryExistsByFields(ChangeMailTokenDBRepository::TABLE_NAME, ['token'])) {
76  $this->db->manipulate('DELETE token1 FROM ' . ChangeMailTokenDBRepository::TABLE_NAME . ' token1 '
77  . 'INNER JOIN ' . ChangeMailTokenDBRepository::TABLE_NAME . ' token2 '
78  . 'WHERE token1.token = token2.token AND token1.created_ts < token2.created_ts');
79  $this->db->addPrimaryKey(ChangeMailTokenDBRepository::TABLE_NAME, ['token']);
80  }
81  }
82 
83  public function step_3(): void
84  {
85  $query = 'SELECT * FROM settings WHERE module = %s AND keyword = %s';
86  $result = $this->db->queryF(
87  $query,
89  ['common', 'session_reminder_enabled']
90  );
91  $session_reminder = $result->numRows() ? (bool) $this->db->fetchAssoc($result)['value'] : false;
92  $query = 'SELECT * FROM settings WHERE module = %s AND keyword = %s';
93  $result = $this->db->queryF(
94  $query,
96  ['common', 'session_reminder_lead_time']
97  );
98  $session_reminder_lead_time = $result->numRows() ? (int) $this->db->fetchAssoc($result)['value'] : null;
99  if ($session_reminder && !isset($session_reminder_lead_time)) {
100  $query = 'INSERT INTO settings (module, keyword, value) VALUES (%s, %s, %s)';
101  $this->db->manipulateF(
102  $query,
104  ['common', 'session_reminder_lead_time', \ilSessionReminder::SUGGESTED_LEAD_TIME]
105  );
106  }
107  $query = 'DELETE FROM settings WHERE module = %s AND keyword = %s';
108  $this->db->manipulateF(
109  $query,
111  ['common', 'session_reminder_enabled']
112  );
113  $query = 'DELETE FROM usr_pref WHERE keyword = %s';
114  $this->db->manipulateF(
115  $query,
117  ['session_reminder_enabled']
118  );
119  }
120 
121  public function step_4(): void
122  {
123  $query = 'SELECT value FROM settings WHERE module = %s AND keyword = %s';
124  $res = $this->db->queryF(
125  $query,
127  ['common', 'ps_login_max_attempts']
128  );
129 
130  // We should adjust the usr_data values, even if the "Max. Login Attempts" are currently not set
131  $max_login_attempts = min(
132  (int) ($this->db->fetchAssoc($res)['value'] ?? \ilSecuritySettings::MAX_LOGIN_ATTEMPTS),
134  );
135 
136  $max_login_attempts_exceeded = $max_login_attempts + 1;
137 
138  $this->db->manipulateF(
139  'UPDATE usr_data SET login_attempts = %s WHERE login_attempts > %s',
141  [$max_login_attempts_exceeded, $max_login_attempts_exceeded]
142  );
143  }
144 
145  public function step_5(): void
146  {
147  if ($this->db->tableColumnExists('personal_clipboard', 'title')) {
148  $this->db->modifyTableColumn('personal_clipboard', 'title', [
149  'type' => \ilDBConstants::T_TEXT,
150  'length' => 255,
151  'notnull' => false
152  ]);
153  }
154  }
155 }
$res
Definition: ltiservices.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
prepare(\ilDBInterface $db)
Prepare the execution of the steps.