ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilWorkflowEngine9DBUpdateSteps.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  $this->db->manipulate("DELETE FROM settings WHERE keyword = " .
33  $this->db->quote('wfe_activation', "text") . " AND module = " .
34  $this->db->quote('common', "text"));
35 
36  $this->db->manipulate("DELETE FROM settings WHERE module = " .
37  $this->db->quote('wfe', "text"));
38  }
39 
40  public function step_2(): void
41  {
42  $this->db->dropTable('wfe_det_listening');
43  $this->db->dropTable('wfe_startup_events');
44  $this->db->dropTable('wfe_static_inputs');
45  $this->db->dropTable('wfe_workflows');
46  }
47 
48  public function step_3(): void
49  {
50  $this->delete_directory( '../default/wfe');
51  }
52 
53  public function step_4(): void
54  {
55  $res = $this->db->queryF(
56  'SELECT obj_id FROM object_data WHERE type = %s',
57  array('text'),
58  array('wfe')
59  );
60  $row = $this->db->fetchAssoc($res);
61  if (is_array($row) && isset($row['obj_id'])) {
62  $obj_id = $row['obj_id'];
63 
64  $ref_res = $this->db->queryF(
65  'SELECT ref_id FROM object_reference WHERE obj_id = %s',
66  array('integer'),
67  array($obj_id)
68  );
69 
70  while ($ref_row = $this->db->fetchAssoc($ref_res)) {
71  if (is_array($ref_row) && isset($ref_row['ref_id'])) {
72  $ref_id = $ref_row['ref_id'];
73 
74  $this->db->manipulateF(
75  'DELETE FROM tree WHERE child = %s',
76  array('integer'),
77  array($ref_id)
78  );
79 
80  $this->db->manipulateF(
81  'DELETE FROM rbac_pa WHERE ref_id = %s',
82  array('integer'),
83  array($ref_id)
84  );
85 
86  $this->db->manipulateF(
87  'DELETE FROM rbac_templates WHERE parent = %s',
88  array('integer'),
89  array($ref_id)
90  );
91 
92  $this->db->manipulateF(
93  'DELETE FROM rbac_fa WHERE parent = %s',
94  array('integer'),
95  array($ref_id)
96  );
97 
98  }
99  }
100 
101  $this->db->manipulateF(
102  'DELETE FROM object_reference WHERE obj_id = %s',
103  array('integer'),
104  array($obj_id)
105  );
106 
107  $this->db->manipulateF(
108  'DELETE FROM object_data WHERE obj_id = %s',
109  array('integer'),
110  array($obj_id)
111  );
112  }
113 
114  $res = $this->db->queryF(
115  'SELECT obj_id FROM object_data WHERE type = %s AND title = %s',
116  array('text', 'text'),
117  array('typ', 'wfe')
118  );
119  $row = $this->db->fetchAssoc($res);
120 
121  if (is_array($row) && isset($row['obj_id'])) {
122  $obj_id = $row['obj_id'];
123 
124  $this->db->manipulateF(
125  'DELETE FROM rbac_ta WHERE typ_id = %s',
126  array('integer'),
127  array($obj_id)
128  );
129 
130  $this->db->manipulateF(
131  'DELETE FROM object_data WHERE obj_id = %s',
132  array('integer'),
133  array($obj_id)
134  );
135  }
136  }
137 
138  private function delete_directory($dir)
139  {
140  if (!file_exists($dir)) {
141  return true;
142  }
143 
144  if (!is_dir($dir)) {
145  return unlink($dir);
146  }
147 
148  foreach (scandir($dir) as $item) {
149  if ($item == '.' || $item == '..') {
150  continue;
151  }
152 
153  if (!delete_directory($dir . DIRECTORY_SEPARATOR . $item)) {
154  return false;
155  }
156  }
157 
158  return rmdir($dir);
159  }
160 }
$res
Definition: ltiservices.php:69
$ref_id
Definition: ltiauth.php:67