ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $mail_templates_by_component = array();
30
31 public function __construct($a_path, $a_name, $a_type)
32 {
33 // init specialized readers
34 foreach ($this->readers as $k => $reader) {
35 $class = $reader["class"];
36 $class_path = "./setup/classes/class." . $class . ".php";
37 include_once($class_path);
38 $this->readers[$k]["reader"] = new $class();
39 }
40
41 $this->name = $a_name;
42 $this->type = $a_type;
43 //echo "<br>-".$a_path."-".$this->name."-".$this->type."-";
44 parent::__construct($a_path);
45 }
46
47 public function setHandlers($a_xml_parser)
48 {
49 xml_set_object($a_xml_parser, $this);
50 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
51 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
52 }
53
57 public function clearTables()
58 {
59 global $ilDB;
60
61 $ilDB->manipulate("DELETE FROM il_object_def");
62
63 $ilDB->manipulate("DELETE FROM il_object_subobj");
64
65 $ilDB->manipulate("DELETE FROM il_object_group");
66
67 $ilDB->manipulate("DELETE FROM il_pluginslot");
68
69 $ilDB->manipulate("DELETE FROM il_component");
70
71 // Keep the plugin listeners in the table
72 // This avoids reading them in the setup
73 // ilPluginReader is called in the plugin administration
74 $ilDB->manipulate("DELETE FROM il_event_handling WHERE component NOT LIKE 'Plugins/%'");
75
76 $ilDB->manipulate("DELETE FROM il_object_sub_type");
77
78 foreach ($this->readers as $k => $reader) {
79 $this->readers[$k]["reader"]->clearTables();
80 }
81 }
82
86 public static function deleteObjectDefinition($a_id)
87 {
88 global $ilDB;
89
90 $ilDB->manipulateF(
91 "DELETE FROM il_object_def WHERE id = %s",
92 array("text"),
93 array($a_id)
94 );
95
96 $ilDB->manipulateF(
97 "DELETE FROM il_object_subobj WHERE parent = %s OR subobj = %s",
98 array("text", "text"),
99 array($a_id, $a_id)
100 );
101 }
102
110 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
111 {
112 global $ilDB;
113
114 $this->current_tag = $a_name;
115
116 // check if a special reader needs to be activated
117 if (isset($this->readers[$a_name])) {
118 $this->current_reader = $a_name;
119 }
120
121 // call special reader
122 if ($this->current_reader != "") {
123 $this->readers[$this->current_reader]["reader"]->handlerBeginTag(
124 $a_xml_parser,
125 $a_name,
126 $a_attribs,
127 $this->current_component
128 );
129 } else {
130 // default handling
131 switch ($a_name) {
132 case 'object':
133
134 // if attributes are not given, set default (repository only)
135 if ($a_attribs["repository"] === null) {
136 $a_attribs["repository"] = true;
137 }
138 if ($a_attribs["workspace"] === null) {
139 $a_attribs["workspace"] = false;
140 }
141
142 $this->current_object = $a_attribs["id"];
143 $ilDB->manipulateF(
144 "INSERT INTO il_object_def (id, class_name, component,location," .
145 "checkbox,inherit,translate,devmode,allow_link,allow_copy,rbac,default_pos," .
146 "default_pres_pos,sideblock,grp,system,export,repository,workspace,administration," .
147 "amet,orgunit_permissions,lti_provider,offline_handling) VALUES " .
148 "(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
149 array("text", "text", "text", "text", "integer", "integer", "text", "integer","integer","integer",
150 "integer","integer","integer","integer", "text", "integer", "integer", "integer", "integer",
151 'integer','integer','integer','integer','integer'),
152 array(
153 $a_attribs["id"],
154 $a_attribs["class_name"],
155 $this->current_component,
156 $this->current_component . "/" . $a_attribs["dir"],
157 (int) $a_attribs["checkbox"],
158 (int) $a_attribs["inherit"],
159 $a_attribs["translate"],
160 (int) $a_attribs["devmode"],
161 (int) $a_attribs["allow_link"],
162 (int) $a_attribs["allow_copy"],
163 (int) $a_attribs["rbac"],
164 (int) $a_attribs["default_pos"],
165 (int) $a_attribs["default_pres_pos"],
166 (int) $a_attribs["sideblock"],
167 $a_attribs["group"],
168 (int) $a_attribs["system"],
169 (int) $a_attribs["export"],
170 (int) $a_attribs["repository"],
171 (int) $a_attribs["workspace"],
172 (int) $a_attribs['administration'],
173 (int) $a_attribs['amet'],
174 (int) $a_attribs['orgunit_permissions'],
175 (int) $a_attribs['lti_provider'],
176 (int) $a_attribs['offline_handling']
177 )
178 );
179 break;
180
181 case "subobj":
182 $ilDB->manipulateF(
183 "INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
184 array("text", "text", "integer"),
185 array($this->current_object, $a_attribs["id"], (int) $a_attribs["max"])
186 );
187 break;
188
189 case "parent":
190 $ilDB->manipulateF(
191 "INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
192 array("text", "text", "integer"),
193 array($a_attribs["id"], $this->current_object, (int) $a_attribs["max"])
194 );
195 break;
196
197 case "objectgroup":
198 $ilDB->manipulateF(
199 "INSERT INTO il_object_group (id, name, default_pres_pos) VALUES (%s,%s,%s)",
200 array("text", "text", "integer"),
201 array($a_attribs["id"], $a_attribs["name"], $a_attribs["default_pres_pos"])
202 );
203 break;
204
205 case "pluginslot":
206 $this->current_object = $a_attribs["id"];
207 $q = "INSERT INTO il_pluginslot (component, id, name) VALUES (" .
208 $ilDB->quote($this->current_component, "text") . "," .
209 $ilDB->quote($a_attribs["id"], "text") . "," .
210 $ilDB->quote($a_attribs["name"], "text") . ")";
211 $ilDB->manipulate($q);
212 break;
213
214 case "event":
215 $component = $a_attribs["component"];
216 if (!$component) {
217 $component = $this->current_component;
218 }
219 $q = "INSERT INTO il_event_handling (component, type, id) VALUES (" .
220 $ilDB->quote($component, "text") . "," .
221 $ilDB->quote($a_attribs["type"], "text") . "," .
222 $ilDB->quote($a_attribs["id"], "text") . ")";
223 $ilDB->manipulate($q);
224 break;
225
226 case "cron":
227 $component = $a_attribs["component"];
228 if (!$component) {
229 $component = $this->current_component;
230 }
231 include_once "Services/Cron/classes/class.ilCronManager.php";
232 ilCronManager::updateFromXML($component, $a_attribs["id"], $a_attribs["class"], $a_attribs["path"]);
233 $this->has_cron[$component][] = $a_attribs["id"];
234 break;
235
236 case 'mailtemplates':
237 $this->in_mail_templates = true;
238 break;
239
240 case 'context':
241 if (!$this->in_mail_templates) {
242 break;
243 }
244
245 $component = $a_attribs['component'];
246 if (!$component) {
247 $component = $this->current_component;
248 }
249
251 $component,
252 $a_attribs['id'],
253 $a_attribs['class'],
254 $a_attribs['path']
255 );
256 $this->mail_templates_by_component[$component][] = $a_attribs["id"];
257 break;
258
259 case "sub_type":
260 $ilDB->manipulate("INSERT INTO il_object_sub_type " .
261 "(obj_type, sub_type, amet) VALUES (" .
262 $ilDB->quote($this->current_object, "text") . "," .
263 $ilDB->quote($a_attribs["id"], "text") . "," .
264 $ilDB->quote($a_attribs["amet"], "integer") .
265 ")");
266 break;
267
268 case 'systemcheck':
269
270 include_once './Services/SystemCheck/classes/class.ilSCGroups.php';
271 ilSCGroups::getInstance()->updateFromComponentDefinition($this->getComponentId());
272 break;
273
274 case 'systemcheck_task':
275 include_once './Services/SystemCheck/classes/class.ilSCGroups.php';
276 $group_id = ilSCGroups::getInstance()->lookupGroupByComponentId($this->getComponentId());
277
278 include_once './Services/SystemCheck/classes/class.ilSCTasks.php';
280 $tasks->updateFromComponentDefinition($a_attribs['identifier']);
281 break;
282
283 case "secure_path":
284 require_once('./Services/WebAccessChecker/classes/class.ilWACSecurePath.php');
285 try {
286 $ilWACSecurePath = ilWACSecurePath::findOrFail($a_attribs["path"]);
287 } catch (arException $e) {
288 $ilWACSecurePath = new ilWACSecurePath();
289 $ilWACSecurePath->setPath($a_attribs["path"]);
290 $ilWACSecurePath->create();
291 }
292 $ilWACSecurePath->setCheckingClass($a_attribs["checking-class"]);
293 $ilWACSecurePath->setInSecFolder((bool) $a_attribs["in-sec-folder"]);
294 $ilWACSecurePath->setComponentDirectory(dirname($this->xml_file));
295 $ilWACSecurePath->update();
296 break;
297
298 case 'logging':
299 include_once './Services/Logging/classes/class.ilLogComponentLevels.php';
301 break;
302
303 case 'badges':
304 include_once "Services/Badge/classes/class.ilBadgeHandler.php";
306 $this->has_badges[] = $this->getComponentId();
307 break;
308
309 case 'pdfpurpose':
310 require_once './Services/PDFGeneration/classes/class.ilPDFCompInstaller.php';
311 ilPDFCompInstaller::updateFromXML($this->current_component, $a_attribs['name'], $a_attribs['preferred']);
312 break;
313 case 'gsprovider':
314 // ilGSProviderStorage::installDB();
315 ilGSProviderStorage::registerIdentifications($a_attribs['class_name'], $a_attribs['purpose']);
316 break;
317 }
318 }
319 }
320
327 public function handlerEndTag($a_xml_parser, $a_name)
328 {
329 // call special reader
330 if ($this->current_reader != "") {
331 $this->readers[$this->current_reader]["reader"]->handlerEndTag($a_xml_parser, $a_name);
332 } else {
333 if ($a_name == "module" || $a_name == "service") {
334 include_once "Services/Cron/classes/class.ilCronManager.php";
336 $this->current_component,
337 (array) $this->has_cron[$this->current_component]
338 );
339
340 ilMailTemplateContextService::clearFromXml($this->current_component, (array) $this->mail_templates_by_component[$this->current_component]);
341
342 if (!in_array($this->getComponentId(), (array) $this->has_badges)) {
343 include_once "Services/Badge/classes/class.ilBadgeHandler.php";
344 ilBadgeHandler::clearFromXml($this->getComponentId());
345 }
346 }
347 }
348
349 // check if a special reader needs to be activated
350 if (isset($this->readers[$a_name])) {
351 $this->current_reader = null;
352 }
353 }
354
355
363 public function handlerCharacterData($a_xml_parser, $a_data)
364 {
365 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
366 $a_data = preg_replace("/\n/", "", $a_data);
367 $a_data = preg_replace("/\t+/", "", $a_data);
368
369 if (!empty($a_data)) {
370 switch ($this->current_tag) {
371 case '':
372 }
373 }
374 }
375
379 public function setComponentId($a_component_id)
380 {
381 $this->component_id = $a_component_id;
382 }
383
388 public function getComponentId()
389 {
390 return $this->component_id;
391 }
392}
$tasks
Definition: build.php:4
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 registerIdentifications(string $class_name, string $purpose)
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...
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
__construct($a_path, $a_name, $a_type)
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.
global $ilDB
$a_type
Definition: workflow.php:92