ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjDefReader.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
16{
17 protected $component_id;
18
19 protected $readers = array(
20 "copage" => array("class" => "ilCOPageDefReader")
21 );
22 protected $current_reader = null;
23
24 protected $in_mail_templates = false;
25
29 protected $db;
30
34 protected $mail_templates_by_component = array();
35
36 public function __construct($a_path, $a_name, $a_type, \ilDBInterface $db = null)
37 {
38 if ($db !== null) {
39 $this->db = $db;
40 } else {
41 global $ilDB;
42 $this->db = $ilDB;
43 }
44 // init specialized readers
45 foreach ($this->readers as $k => $reader) {
46 $class = $reader["class"];
47 $this->readers[$k]["reader"] = new $class($this->db);
48 }
49
50 $this->name = $a_name;
51 $this->type = $a_type;
52
53 parent::__construct($a_path);
54 }
55
56 public function setHandlers($a_xml_parser)
57 {
58 xml_set_object($a_xml_parser, $this);
59 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
60 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
61 }
62
66 public function clearTables()
67 {
68 $this->db->manipulate("DELETE FROM il_object_def");
69
70 $this->db->manipulate("DELETE FROM il_object_subobj");
71
72 $this->db->manipulate("DELETE FROM il_object_group");
73
74 $this->db->manipulate("DELETE FROM il_pluginslot");
75
76 $this->db->manipulate("DELETE FROM il_component");
77
78 // Keep the plugin listeners in the table
79 // This avoids reading them in the setup
80 // ilPluginReader is called in the plugin administration
81 $this->db->manipulate("DELETE FROM il_event_handling WHERE component NOT LIKE 'Plugins/%'");
82
83 $this->db->manipulate("DELETE FROM il_object_sub_type");
84
85 foreach ($this->readers as $k => $reader) {
86 $this->readers[$k]["reader"]->clearTables();
87 }
88 }
89
93 public static function deleteObjectDefinition($a_id)
94 {
95 $this->db->manipulateF(
96 "DELETE FROM il_object_def WHERE id = %s",
97 array("text"),
98 array($a_id)
99 );
100
101 $this->db->manipulateF(
102 "DELETE FROM il_object_subobj WHERE parent = %s OR subobj = %s",
103 array("text", "text"),
104 array($a_id, $a_id)
105 );
106 }
107
115 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
116 {
117 $this->current_tag = $a_name;
118
119 // check if a special reader needs to be activated
120 if (isset($this->readers[$a_name])) {
121 $this->current_reader = $a_name;
122 }
123
124 // call special reader
125 if ($this->current_reader != "") {
126 $this->readers[$this->current_reader]["reader"]->handlerBeginTag(
127 $a_xml_parser,
128 $a_name,
129 $a_attribs,
130 $this->current_component
131 );
132 } else {
133 // default handling
134 switch ($a_name) {
135 case 'object':
136
137 // if attributes are not given, set default (repository only)
138 if (($a_attribs["repository"] ?? null) === null) {
139 $a_attribs["repository"] = true;
140 }
141 if (($a_attribs["workspace"] ?? null) === null) {
142 $a_attribs["workspace"] = false;
143 }
144
145 $this->current_object = $a_attribs["id"];
146 $this->db->manipulateF(
147 "INSERT INTO il_object_def (id, class_name, component,location," .
148 "checkbox,inherit,translate,devmode,allow_link,allow_copy,rbac,default_pos," .
149 "default_pres_pos,sideblock,grp," . $this->db->quoteIdentifier("system") . ",export,repository,workspace,administration," .
150 "amet,orgunit_permissions,lti_provider,offline_handling) VALUES " .
151 "(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
152 array("text", "text", "text", "text", "integer", "integer", "text", "integer","integer","integer",
153 "integer","integer","integer","integer", "text", "integer", "integer", "integer", "integer",
154 'integer','integer','integer','integer','integer'),
155 array(
156 $a_attribs["id"],
157 $a_attribs["class_name"],
158 $this->current_component,
159 $this->current_component . "/" . $a_attribs["dir"],
160 (int) ($a_attribs["checkbox"] ?? null),
161 (int) ($a_attribs["inherit"] ?? null),
162 $a_attribs["translate"] ?? null,
163 (int) ($a_attribs["devmode"] ?? null),
164 (int) ($a_attribs["allow_link"] ?? null),
165 (int) ($a_attribs["allow_copy"] ?? null),
166 (int) ($a_attribs["rbac"] ?? null),
167 (int) ($a_attribs["default_pos"] ?? null),
168 (int) ($a_attribs["default_pres_pos"] ?? null),
169 (int) ($a_attribs["sideblock"] ?? null),
170 $a_attribs["group"] ?? null,
171 (int) ($a_attribs["system"] ?? null),
172 (int) ($a_attribs["export"] ?? null),
173 (int) ($a_attribs["repository"] ?? null),
174 (int) ($a_attribs["workspace"] ?? null),
175 (int) ($a_attribs['administration'] ?? null),
176 (int) ($a_attribs['amet'] ?? null),
177 (int) ($a_attribs['orgunit_permissions'] ?? null),
178 (int) ($a_attribs['lti_provider'] ?? null),
179 (int) ($a_attribs['offline_handling'] ?? null)
180 )
181 );
182 break;
183
184 case "subobj":
185 $this->db->manipulateF(
186 "INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
187 array("text", "text", "integer"),
188 array($this->current_object, $a_attribs["id"], (int) ($a_attribs["max"] ?? null))
189 );
190 break;
191
192 case "parent":
193 $this->db->manipulateF(
194 "INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
195 array("text", "text", "integer"),
196 array($a_attribs["id"], $this->current_object, (int) ($a_attribs["max"] ?? null))
197 );
198 break;
199
200 case "objectgroup":
201 $this->db->manipulateF(
202 "INSERT INTO il_object_group (id, name, default_pres_pos) VALUES (%s,%s,%s)",
203 array("text", "text", "integer"),
204 array($a_attribs["id"], $a_attribs["name"], $a_attribs["default_pres_pos"])
205 );
206 break;
207
208 case "pluginslot":
209 $this->current_object = $a_attribs["id"];
210 $q = "INSERT INTO il_pluginslot (component, id, name) VALUES (" .
211 $this->db->quote($this->current_component, "text") . "," .
212 $this->db->quote($a_attribs["id"], "text") . "," .
213 $this->db->quote($a_attribs["name"], "text") . ")";
214 $this->db->manipulate($q);
215 break;
216
217 case "event":
218 $component = $a_attribs["component"] ?? null;
219 if (!$component) {
220 $component = $this->current_component;
221 }
222 $q = "INSERT INTO il_event_handling (component, type, id) VALUES (" .
223 $this->db->quote($component, "text") . "," .
224 $this->db->quote($a_attribs["type"], "text") . "," .
225 $this->db->quote($a_attribs["id"], "text") . ")";
226 $this->db->manipulate($q);
227 break;
228
229 case "cron":
230 $component = $a_attribs["component"] ?? null;
231 if (!$component) {
232 $component = $this->current_component;
233 }
234 ilCronManager::updateFromXML($component, $a_attribs["id"], $a_attribs["class"], ($a_attribs["path"] ?? null));
235 $this->has_cron[$component][] = $a_attribs["id"];
236 break;
237
238 case 'mailtemplates':
239 $this->in_mail_templates = true;
240 break;
241
242 case 'context':
243 if (!$this->in_mail_templates) {
244 break;
245 }
246
247 $component = $a_attribs['component'] ?? null;
248 if (!$component) {
249 $component = $this->current_component;
250 }
251
253 $component,
254 $a_attribs['id'],
255 $a_attribs['class'],
256 $a_attribs['path'] ?? null
257 );
258 $this->mail_templates_by_component[$component][] = $a_attribs["id"];
259 break;
260
261 case "sub_type":
262 $this->db->manipulate("INSERT INTO il_object_sub_type " .
263 "(obj_type, sub_type, amet) VALUES (" .
264 $this->db->quote($this->current_object, "text") . "," .
265 $this->db->quote($a_attribs["id"], "text") . "," .
266 $this->db->quote($a_attribs["amet"], "integer") .
267 ")");
268 break;
269
270 case 'systemcheck':
271
272 include_once './Services/SystemCheck/classes/class.ilSCGroups.php';
273 ilSCGroups::getInstance()->updateFromComponentDefinition($this->getComponentId());
274 break;
275
276 case 'systemcheck_task':
277 include_once './Services/SystemCheck/classes/class.ilSCGroups.php';
278 $group_id = ilSCGroups::getInstance()->lookupGroupByComponentId($this->getComponentId());
279
280 include_once './Services/SystemCheck/classes/class.ilSCTasks.php';
281 $tasks = ilSCTasks::getInstanceByGroupId($group_id);
282 $tasks->updateFromComponentDefinition($a_attribs['identifier']);
283 break;
284
285 case "secure_path":
286 require_once('./Services/WebAccessChecker/classes/class.ilWACSecurePath.php');
287 try {
288 $ilWACSecurePath = ilWACSecurePath::findOrFail($a_attribs["path"]);
289 } catch (arException $e) {
290 $ilWACSecurePath = new ilWACSecurePath();
291 $ilWACSecurePath->setPath($a_attribs["path"]);
292 $ilWACSecurePath->create();
293 }
294 $ilWACSecurePath->setCheckingClass($a_attribs["checking-class"]);
295 $ilWACSecurePath->setInSecFolder((bool) ($a_attribs["in-sec-folder"] ?? null));
296 $ilWACSecurePath->setComponentDirectory(dirname($this->xml_file));
297 $ilWACSecurePath->update();
298 break;
299
300 case 'logging':
301 include_once './Services/Logging/classes/class.ilLogComponentLevels.php';
303 break;
304
305 case 'badges':
306 include_once "Services/Badge/classes/class.ilBadgeHandler.php";
308 $this->has_badges[] = $this->getComponentId();
309 break;
310
311 case 'pdfpurpose':
312 require_once './Services/PDFGeneration/classes/class.ilPDFCompInstaller.php';
313 ilPDFCompInstaller::updateFromXML($this->current_component, $a_attribs['name'], $a_attribs['preferred']);
314 break;
315 }
316 }
317 }
318
325 public function handlerEndTag($a_xml_parser, $a_name)
326 {
327 // call special reader
328 if ($this->current_reader != "") {
329 $this->readers[$this->current_reader]["reader"]->handlerEndTag($a_xml_parser, $a_name);
330 } else {
331 if ($a_name == "module" || $a_name == "service") {
333 $this->current_component,
334 ($this->has_cron[$this->current_component] ?? [])
335 );
336
337 ilMailTemplateContextService::clearFromXml($this->current_component, ($this->mail_templates_by_component[$this->current_component] ?? []));
338
339 if (!in_array($this->getComponentId(), ($this->has_badges ?? []))) {
340 include_once "Services/Badge/classes/class.ilBadgeHandler.php";
341 ilBadgeHandler::clearFromXml($this->getComponentId());
342 }
343 }
344 }
345
346 // check if a special reader needs to be activated
347 if (isset($this->readers[$a_name])) {
348 $this->current_reader = null;
349 }
350 }
351
352
360 public function handlerCharacterData($a_xml_parser, $a_data)
361 {
362 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
363 $a_data = preg_replace("/\n/", "", $a_data);
364 $a_data = preg_replace("/\t+/", "", $a_data);
365
366 if (!empty($a_data)) {
367 switch ($this->current_tag) {
368 case '':
369 }
370 }
371 }
372
376 public function setComponentId($a_component_id)
377 {
378 $this->component_id = $a_component_id;
379 }
380
385 public function getComponentId()
386 {
387 return $this->component_id;
388 }
389}
static findOrFail($primary_key, array $add_constructor_args=array())
Tries to find the object and throws an Exception if object is not found, instead of returning null.
An exception for terminatinating execution or to throw for unit testing.
Class arException.
static updateFromXML($a_component_id)
Import component definition.
static updateFromXML($a_component, $a_id, $a_class, $a_path=null)
Process data from module.xml/service.xml.
static clearFromXML($a_component, array $a_xml_job_ids)
Clear job data.
static updateFromXML($a_component_id)
@global type $ilDB
static clearFromXml($a_component, array $a_new_templates)
static insertFromXML($a_component, $a_id, $a_class, $a_path)
Component definition reader (reads common tags in module.xml and service.xml files) Name is misleadin...
__construct($a_path, $a_name, $a_type, \ilDBInterface $db=null)
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
handlerCharacterData($a_xml_parser, $a_data)
end tag handler
static deleteObjectDefinition($a_id)
Delete an object definition (this is currently needed for test cases)
handlerEndTag($a_xml_parser, $a_name)
End tag handler.
getComponentId()
Get component id.
setComponentId($a_component_id)
Set from module or service reader.
clearTables()
clear the tables
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
Start tag handler.
static updateFromXML($service, $purpose, $preferred)
static getInstance()
Get singleton instance.
static getInstanceByGroupId($a_group_id)
Get singleton instance.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
Class ilWACSecurePath.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB