ILIAS  release_8 Revision v8.24
class.ilExternalFeedRemoveMigration.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\Setup;
21
26{
27 protected ilDBInterface $db;
28
29 public function getLabel(): string
30 {
31 return "Remove external feeds from repository.";
32 }
33
35 {
36 return 10;
37 }
38
39 public function getPreconditions(Environment $environment): array
40 {
41 return [
45 ];
46 }
47
48 public function prepare(Environment $environment): void
49 {
51 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
52 $this->db = $db;
53 }
54
55 protected function log(string $str): void
56 {
57 echo "\n" . $str;
58 }
59
60 public function step(Environment $environment): void
61 {
62 $db = $this->db;
63
64 $ref_ids = [];
65 $obj_ids = [];
66
67 $set = $db->queryF(
68 "SELECT * FROM object_data d JOIN object_reference r ON (d.obj_id = r.obj_id) " .
69 " WHERE d.type = %s ",
70 ["text"],
71 ["feed"]
72 );
73 while ($rec = $db->fetchAssoc($set)) {
74 $this->log("Found title: " . $rec["title"] . ", ref id: " . $rec["ref_id"]);
75 $ref_ids[$rec["ref_id"]] = $rec["ref_id"];
76 $obj_ids[$rec["obj_id"]] = $rec["obj_id"];
77 }
78
79 // local roles of feed objects
80 $set = $db->queryF(
81 "SELECT * FROM rbac_fa " .
82 " WHERE " . $db->in("parent", $ref_ids, false, "integer"),
83 [],
84 []
85 );
86 $local_roles = [];
87 while ($rec = $db->fetchAssoc($set)) {
88 $local_roles[$rec["rol_id"]] = $rec["rol_id"];
89 }
90
91 // typ
92 $set = $db->queryF(
93 "SELECT * FROM object_data " .
94 " WHERE type = %s AND title = %s",
95 ["text", "text"],
96 ["typ", "feed"]
97 );
98 $typ_id = 0;
99 if ($rec = $db->fetchAssoc($set)) {
100 $typ_id = $rec["obj_id"];
101 }
102
103 // create ops id
104 $set = $db->queryF(
105 "SELECT * FROM rbac_operations " .
106 " WHERE operation = %s",
107 ["text"],
108 ["create_feed"]
109 );
110 $create_ops_id = 0;
111 if ($rec = $db->fetchAssoc($set)) {
112 $create_ops_id = $rec["ops_id"];
113 }
114
115
116 // ...tree
117 $this->log("Delete tree nodes of feed objects.");
118 $this->manipulate(
119 "DELETE FROM tree WHERE " .
120 " " . $db->in("child", $ref_ids, false, "integer")
121 );
122
123 // ...object_data (feed objects)
124 $this->log("Delete object_data entries of feed objects.");
125 $this->manipulate(
126 "DELETE FROM object_data WHERE " .
127 " " . $db->in("obj_id", $obj_ids, false, "integer")
128 );
129 // ...object_data (roles)
130 $this->log("Delete object_data entries of local roles of feed objects.");
131 $this->manipulate(
132 "DELETE FROM object_data WHERE " .
133 " " . $db->in("obj_id", $local_roles, false, "integer")
134 );
135 // ...object_data (type)
136 $this->log("Delete object_data entry of feed type.");
137 $this->manipulate(
138 "DELETE FROM object_data WHERE " .
139 " obj_id = " . $db->quote($typ_id, "integer")
140 );
141
142 // ...object_description (feed objects)
143 $this->log("Delete object_description entries of feed objects.");
144 $this->manipulate(
145 "DELETE FROM object_description WHERE " .
146 " " . $db->in("obj_id", $obj_ids, false, "integer")
147 );
148
149 //... role data of local roles
150 $this->log("Delete role_data entries of local roles of feed objects.");
151 $this->manipulate(
152 "DELETE FROM role_data WHERE " .
153 " " . $db->in("role_id", $local_roles, false, "integer")
154 );
155
156 // ...object_reference
157 $this->log("Delete object_reference entries of feed objects.");
158 $this->manipulate(
159 "DELETE FROM object_reference WHERE " .
160 " " . $db->in("ref_id", $ref_ids, false, "integer")
161 );
162
163 // ...rbac_pa (permissions on feeds)
164 $this->log("Delete permissions of feed objects.");
165 $this->manipulate(
166 "DELETE FROM rbac_pa WHERE " .
167 " " . $db->in("ref_id", $ref_ids, false, "integer")
168 );
169
170 // ...rbac_fa (local roles of feeds)
171 $this->log("Delete local roles of feed objects.");
172 $this->manipulate(
173 "DELETE FROM rbac_fa WHERE " .
174 " " . $db->in("rol_id", $local_roles, false, "integer")
175 );
176
177 // ...rbac_ta (operations per type)
178 $this->log("Delete operations of feed type.");
179 $this->manipulate(
180 "DELETE FROM rbac_ta WHERE " .
181 " typ_id = " . $db->quote($typ_id, "integer")
182 );
183
184 // ...rbac_templates (template for feed type)
185 $this->log("Delete permission templates of feed type.");
186 $this->manipulate(
187 "DELETE FROM rbac_templates WHERE " .
188 " type = " . $db->quote("feed", "text")
189 );
190
191 // ...rbac_templates (create_feed operation)
192 $this->log("Delete create_feed operation from permission templates.");
193 $this->manipulate(
194 "DELETE FROM rbac_templates WHERE " .
195 " ops_id = " . $db->quote($create_ops_id, "integer")
196 );
197
198
199 // ...conditions
200 $this->log("Delete conditions of feed objects.");
201 $this->manipulate(
202 "DELETE FROM conditions WHERE " .
203 " " . $db->in("target_ref_id", $ref_ids, false, "integer") .
204 " OR " . $db->in("trigger_ref_id", $ref_ids, false, "integer")
205 );
206
207 // ...il_external_feed_block
208 $this->log("Empty il_external_feed_block.");
209 $this->manipulate("DELETE FROM il_external_feed_block");
210
211 // ...il_custom_block
212 $this->log("Delete il_custom_block entries of type 'feed'.");
213 $this->manipulate("DELETE FROM il_custom_block WHERE type = " . $db->quote("feed", "text"));
214 }
215
216 protected function manipulate(string $query): void
217 {
218 $db = $this->db;
220 $this->log($query);
221 }
222
224 {
225 $db = $this->db;
226
227 $set = $db->queryF(
228 "SELECT * FROM object_data d JOIN object_reference r ON (d.obj_id = r.obj_id) " .
229 " WHERE d.type = %s ",
230 ["text"],
231 ["feed"]
232 );
233 $obj_ids = [];
234 while ($rec = $db->fetchAssoc($set)) {
235 $obj_ids[$rec["obj_id"]] = $rec["obj_id"];
236 }
237
238 if (count($obj_ids) > 0) {
239 return 1;
240 }
241 return 0;
242 }
243}
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:29
Interface ilDBInterface.
quote($value, string $type)
manipulate(string $query)
Run a (write) Query on the database.
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
in(string $field, array $values, bool $negate=false, string $type="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query