ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
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,amet,orgunit_permissions,lti_provider) VALUES " .
147  "(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
148  array("text", "text", "text", "text", "integer", "integer", "text", "integer","integer","integer",
149  "integer","integer","integer","integer", "text", "integer", "integer", "integer", "integer",'integer','integer','integer','integer'),
150  array(
151  $a_attribs["id"],
152  $a_attribs["class_name"],
153  $this->current_component,
154  $this->current_component . "/" . $a_attribs["dir"],
155  (int) $a_attribs["checkbox"],
156  (int) $a_attribs["inherit"],
157  $a_attribs["translate"],
158  (int) $a_attribs["devmode"],
159  (int) $a_attribs["allow_link"],
160  (int) $a_attribs["allow_copy"],
161  (int) $a_attribs["rbac"],
162  (int) $a_attribs["default_pos"],
163  (int) $a_attribs["default_pres_pos"],
164  (int) $a_attribs["sideblock"],
165  $a_attribs["group"],
166  (int) $a_attribs["system"],
167  (int) $a_attribs["export"],
168  (int) $a_attribs["repository"],
169  (int) $a_attribs["workspace"],
170  (int) $a_attribs['administration'],
171  (int) $a_attribs['amet'],
172  (int) $a_attribs['orgunit_permissions'],
173  (int) $a_attribs['lti_provider']
174  )
175  );
176  break;
177 
178  case "subobj":
179  $ilDB->manipulateF(
180  "INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
181  array("text", "text", "integer"),
182  array($this->current_object, $a_attribs["id"], (int) $a_attribs["max"])
183  );
184  break;
185 
186  case "parent":
187  $ilDB->manipulateF(
188  "INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
189  array("text", "text", "integer"),
190  array($a_attribs["id"], $this->current_object, (int) $a_attribs["max"])
191  );
192  break;
193 
194  case "objectgroup":
195  $ilDB->manipulateF(
196  "INSERT INTO il_object_group (id, name, default_pres_pos) VALUES (%s,%s,%s)",
197  array("text", "text", "integer"),
198  array($a_attribs["id"], $a_attribs["name"], $a_attribs["default_pres_pos"])
199  );
200  break;
201 
202  case "pluginslot":
203  $this->current_object = $a_attribs["id"];
204  $q = "INSERT INTO il_pluginslot (component, id, name) VALUES (" .
205  $ilDB->quote($this->current_component, "text") . "," .
206  $ilDB->quote($a_attribs["id"], "text") . "," .
207  $ilDB->quote($a_attribs["name"], "text") . ")";
208  $ilDB->manipulate($q);
209  break;
210 
211  case "event":
212  $component = $a_attribs["component"];
213  if (!$component) {
214  $component = $this->current_component;
215  }
216  $q = "INSERT INTO il_event_handling (component, type, id) VALUES (" .
217  $ilDB->quote($component, "text") . "," .
218  $ilDB->quote($a_attribs["type"], "text") . "," .
219  $ilDB->quote($a_attribs["id"], "text") . ")";
220  $ilDB->manipulate($q);
221  break;
222 
223  case "cron":
224  $component = $a_attribs["component"];
225  if (!$component) {
226  $component = $this->current_component;
227  }
228  include_once "Services/Cron/classes/class.ilCronManager.php";
229  ilCronManager::updateFromXML($component, $a_attribs["id"], $a_attribs["class"], $a_attribs["path"]);
230  $this->has_cron[$component][] = $a_attribs["id"];
231  break;
232 
233  case 'mailtemplates':
234  $this->in_mail_templates = true;
235  break;
236 
237  case 'context':
238  if (!$this->in_mail_templates) {
239  break;
240  }
241 
242  $component = $a_attribs['component'];
243  if (!$component) {
244  $component = $this->current_component;
245  }
246 
247  require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
249  $component,
250  $a_attribs['id'],
251  $a_attribs['class'],
252  $a_attribs['path']
253  );
254  $this->mail_templates_by_component[$component][] = $a_attribs["id"];
255  break;
256 
257  case "sub_type":
258  $ilDB->manipulate("INSERT INTO il_object_sub_type " .
259  "(obj_type, sub_type, amet) VALUES (" .
260  $ilDB->quote($this->current_object, "text") . "," .
261  $ilDB->quote($a_attribs["id"], "text") . "," .
262  $ilDB->quote($a_attribs["amet"], "integer") .
263  ")");
264  break;
265 
266  case 'systemcheck':
267 
268  include_once './Services/SystemCheck/classes/class.ilSCGroups.php';
269  ilSCGroups::getInstance()->updateFromComponentDefinition($this->getComponentId());
270  break;
271 
272  case 'systemcheck_task':
273  include_once './Services/SystemCheck/classes/class.ilSCGroups.php';
274  $group_id = ilSCGroups::getInstance()->lookupGroupByComponentId($this->getComponentId());
275 
276  include_once './Services/SystemCheck/classes/class.ilSCTasks.php';
277  $tasks = ilSCTasks::getInstanceByGroupId($group_id);
278  $tasks->updateFromComponentDefinition($a_attribs['identifier']);
279  break;
280 
281  case "secure_path":
282  require_once('./Services/WebAccessChecker/classes/class.ilWACSecurePath.php');
283  try {
284  $ilWACSecurePath = ilWACSecurePath::findOrFail($a_attribs["path"]);
285  } catch (arException $e) {
286  $ilWACSecurePath = new ilWACSecurePath();
287  $ilWACSecurePath->setPath($a_attribs["path"]);
288  $ilWACSecurePath->create();
289  }
290  $ilWACSecurePath->setCheckingClass($a_attribs["checking-class"]);
291  $ilWACSecurePath->setInSecFolder((bool) $a_attribs["in-sec-folder"]);
292  $ilWACSecurePath->setComponentDirectory(dirname($this->xml_file));
293  $ilWACSecurePath->update();
294  break;
295 
296  case 'logging':
297  include_once './Services/Logging/classes/class.ilLogComponentLevels.php';
299  break;
300 
301  case 'badges':
302  include_once "Services/Badge/classes/class.ilBadgeHandler.php";
304  $this->has_badges[] = $this->getComponentId();
305  break;
306 
307  case 'pdfpurpose':
308  require_once './Services/PDFGeneration/classes/class.ilPDFCompInstaller.php';
309  ilPDFCompInstaller::updateFromXML($this->current_component, $a_attribs['name'], $a_attribs['preferred']);
310  break;
311  }
312  }
313  }
314 
321  public function handlerEndTag($a_xml_parser, $a_name)
322  {
323  // call special reader
324  if ($this->current_reader != "") {
325  $this->readers[$this->current_reader]["reader"]->handlerEndTag($a_xml_parser, $a_name);
326  } else {
327  if ($a_name == "module" || $a_name == "service") {
328  include_once "Services/Cron/classes/class.ilCronManager.php";
330  $this->current_component,
331  (array) $this->has_cron[$this->current_component]
332  );
333 
334  require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
335  ilMailTemplateService::clearFromXml($this->current_component, (array) $this->mail_templates_by_component[$this->current_component]);
336 
337  if (!in_array($this->getComponentId(), (array) $this->has_badges)) {
338  include_once "Services/Badge/classes/class.ilBadgeHandler.php";
339  ilBadgeHandler::clearFromXml($this->getComponentId());
340  }
341  }
342  }
343 
344  // check if a special reader needs to be activated
345  if (isset($this->readers[$a_name])) {
346  $this->current_reader = null;
347  }
348  }
349 
350 
358  public function handlerCharacterData($a_xml_parser, $a_data)
359  {
360  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
361  $a_data = preg_replace("/\n/", "", $a_data);
362  $a_data = preg_replace("/\t+/", "", $a_data);
363 
364  if (!empty($a_data)) {
365  switch ($this->current_tag) {
366  case '':
367  }
368  }
369  }
370 
374  public function setComponentId($a_component_id)
375  {
376  $this->component_id = $a_component_id;
377  }
378 
383  public function getComponentId()
384  {
385  return $this->component_id;
386  }
387 }
clearTables()
clear the tables
setComponentId($a_component_id)
Set from module or service reader.
static updateFromXML($a_component, $a_id, $a_class, $a_path=null)
Process data from module.xml/service.xml.
static insertFromXML($a_component, $a_id, $a_class, $a_path)
static updateFromXML($service, $purpose, $preferred)
static clearFromXml($a_component, array $a_new_templates)
static updateFromXML($a_component_id)
Import component definition.
handlerCharacterData($a_xml_parser, $a_data)
end tag handler
Class ilWACSecurePath.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setHandlers($a_xml_parser)
$a_type
Definition: workflow.php:92
static updateFromXML($a_component_id)
type $ilDB
getComponentId()
Get component id.
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...
__construct($a_path, $a_name, $a_type)
static getInstance()
Get singleton instance.
static getInstanceByGroupId($a_group_id)
Get singleton instance.
Create styles array
The data for the language used.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
Start tag handler.
handlerEndTag($a_xml_parser, $a_name)
End tag handler.
Class arException.
Component definition reader (reads common tags in module.xml and service.xml files) Name is misleadin...
static clearFromXML($a_component, array $a_xml_job_ids)
Clear job data.
global $ilDB
static deleteObjectDefinition($a_id)
Delete an object definition (this is currently needed for test cases)