ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCtrlStructureReader.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
17  var $executed;
18 
20  {
21  $this->class_script = array();
22  $this->class_childs = array();
23  $this->executed = false;
24  $this->ini = $a_ini_file;
25  }
26 
27  function setIniFile($a_ini_file)
28  {
29  $this->ini = $a_ini_file;
30  }
31 
32  function setErrorObject(&$err)
33  {
34  $this->err_object =& $err;
35  }
36 
40  function getStructure()
41  {
42  global $ilDB;
43 
44  $this->ini->setVariable("db","structure_reload", "1");
45  $this->ini->write();
46  if ($this->ini->readVariable("db","structure_reload") != "1")
47  {
48  echo "Error Cannot write client.ini.file.";
49  }
50  //$this->get_structure = true;
51  }
52 
56  function readStructure($a_force = false, $a_dir = "", $a_comp_prefix = "",
57  $a_plugin_path = "")
58  {
59  global $ilDB;
60 
61  if (!$a_force && $this->ini->readVariable("db","structure_reload") != "1")
62  {
63  return;
64  }
65 
66  require_once('./Services/UICore/classes/class.ilCachedCtrl.php');
68  require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
69  ilGlobalCache::flushAll();
70 
71  // prefix for component
72  $this->comp_prefix = $a_comp_prefix;
73 
74  // plugin path
75  $this->plugin_path = $a_plugin_path;
76 
77  // only run one time per db_update request
78  if (!$this->executed)
79  {
80  if ($a_dir == "")
81  {
82  $this->start_dir = ILIAS_ABSOLUTE_PATH;
83  $this->read(ILIAS_ABSOLUTE_PATH);
84  }
85  else
86  {
87  $this->start_dir = $a_dir;
88  $this->read($a_dir);
89  }
90  $this->store();
91  $this->determineClassFileIds();
92  $this->executed = true;
93  if (!$a_force)
94  {
95  $this->ini->setVariable("db","structure_reload", "0");
96  $this->ini->write();
97  }
98  }
99 
100  // read module information
101  // not clear whether this is a good place for module reading info
102  // or not
103  include_once("./Services/UICore/classes/class.ilCtrl.php");
104  $ctrl = new ilCtrl();
105 // $ctrl->storeCommonStructures();
106  }
107 
113  function read($a_cdir)
114  {
115  global $ilDB, $lng;
116 
117  // check wether $a_cdir is a directory
118  if (!@is_dir($a_cdir))
119  {
120  return false;
121  }
122 
123  // read current directory
124  $dir = opendir($a_cdir);
125 
126  while($file = readdir($dir))
127  {
128  if ($file != "." and
129  $file != "..")
130  {
131  // directories
132  if (@is_dir($a_cdir."/".$file))
133  {
134  if ($a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/data" &&
135  $a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/Customizing")
136  {
137  $this->read($a_cdir."/".$file);
138  }
139  }
140 
141  // files
142  if (@is_file($a_cdir."/".$file))
143  {
144  if (eregi("^class.*php$", $file) || eregi("^ilSCORM13Player.php$", $file))
145  {
146  $handle = fopen($a_cdir."/".$file, "r");
147 //echo "<br>".$a_cdir."/".$file;
148  while (!feof($handle)) {
149  $line = fgets($handle, 4096);
150 
151  // handle @ilctrl_calls
152  $pos = strpos(strtolower($line), "@ilctrl_calls");
153  if (is_int($pos))
154  {
155  $com = substr($line, $pos + 14);
156  $pos2 = strpos($com, ":");
157  if (is_int($pos2))
158  {
159  $com_arr = explode(":", $com);
160  $parent = strtolower(trim($com_arr[0]));
161 
162  // check file duplicates
163  if ($parent != "" && isset($this->class_script[$parent]) &&
164  $this->class_script[$parent] != $a_cdir."/".$file)
165  {
166  // delete all class to file assignments
167  $ilDB->manipulate("DELETE FROM ctrl_classfile WHERE comp_prefix = ".
168  $ilDB->quote($this->comp_prefix, "text"));
169  if ($this->comp_prefix == "")
170  {
171  $ilDB->manipulate($q = "DELETE FROM ctrl_classfile WHERE ".
172  $ilDB->equals("comp_prefix", "", "text", true));
173  }
174 
175  // delete all call entries
176  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix = ".
177  $ilDB->quote($this->comp_prefix, "text"));
178  if ($this->comp_prefix == "")
179  {
180  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix IS NULL");
181  }
182 
183  $this->err_object->raiseError(
184  sprintf($lng->txt("duplicate_ctrl"),
185  $parent,
186  $this->class_script[$parent],
187  $a_cdir."/".$file)
188  , $this->err_object->MESSAGE);
189  }
190 
191  $this->class_script[$parent] = $a_cdir."/".$file;
192  $childs = explode(",", $com_arr[1]);
193  foreach($childs as $child)
194  {
195  $child = trim(strtolower($child));
196  if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
197  {
198  $this->class_childs[$parent][] = $child;
199  }
200  }
201  }
202  }
203 
204  // handle isCalledBy comments
205  $pos = strpos(strtolower($line), "@ilctrl_iscalledby");
206  if (is_int($pos))
207  {
208  $com = substr($line, $pos + 19);
209  $pos2 = strpos($com, ":");
210  if (is_int($pos2))
211  {
212  $com_arr = explode(":", $com);
213  $child = strtolower(trim($com_arr[0]));
214  $this->class_script[$child] = $a_cdir."/".$file;
215 
216  $parents = explode(",", $com_arr[1]);
217  foreach($parents as $parent)
218  {
219  $parent = trim(strtolower($parent));
220  if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
221  {
222  $this->class_childs[$parent][] = $child;
223  }
224  }
225  }
226  }
227 
228  if (eregi("^class\.(.*GUI)\.php$", $file, $res))
229  {
230  $cl = strtolower($res[1]);
231  $pos = strpos(strtolower($line), "class ".$cl);
232  if (is_int($pos) && $this->class_script[$cl] == "")
233  {
234  $this->class_script[$cl] = $a_cdir."/".$file;
235  //echo "<br>".$cl."-".$this->class_script[$cl]."-";
236  }
237  }
238  }
239  fclose($handle);
240  }
241  }
242  }
243  }
244  }
245 
251  function store($a_cdir = "./..")
252  {
253  global $ilDB;
254 
255  // delete all class to file assignments
256  $ilDB->manipulate("DELETE FROM ctrl_classfile WHERE comp_prefix = ".
257  $ilDB->quote($this->comp_prefix, "text"));
258  if ($this->comp_prefix == "")
259  {
260  $ilDB->manipulate($q = "DELETE FROM ctrl_classfile WHERE ".
261  $ilDB->equals("comp_prefix", "", "text", true));
262  }
263 
264  // delete all call entries
265  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix = ".
266  $ilDB->quote($this->comp_prefix, "text"));
267  if ($this->comp_prefix == "")
268  {
269  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE ".
270  $ilDB->equals("comp_prefix", "", "text", true));
271  }
272 
273  foreach($this->class_script as $class => $script)
274  {
275  $file = substr($script, strlen($this->start_dir) + 1);
276 
277  // store class to file assignment
278  $ilDB->manipulate(sprintf("INSERT INTO ctrl_classfile (class, filename, comp_prefix, plugin_path) ".
279  " VALUES (%s,%s,%s,%s)",
280  $ilDB->quote($class, "text"),
281  $ilDB->quote($file, "text"),
282  $ilDB->quote($this->comp_prefix, "text"),
283  $ilDB->quote($this->plugin_path, "text")
284  ));
285  }
286 //$this->class_childs[$parent][] = $child;
287  foreach($this->class_childs as $parent => $v)
288  {
289  if (is_array($this->class_childs[$parent]))
290  {
291  foreach($this->class_childs[$parent] as $child)
292  {
293  // store call entry
294  $ilDB->manipulate(sprintf("INSERT INTO ctrl_calls (parent, child, comp_prefix) ".
295  "VALUES (%s,%s,%s)",
296  $ilDB->quote($parent, "text"),
297  $ilDB->quote($child, "text"),
298  $ilDB->quote($this->comp_prefix, "text")));
299  }
300  }
301  }
302 
303  }
304 
309  {
310  global $ilDB;
311 
312  $ilDB->manipulate("UPDATE ctrl_classfile SET ".
313  " cid = ".$ilDB->quote("", "text")
314  );
315  $set = $ilDB->query("SELECT * FROM ctrl_classfile ");
316  $cnt = 1;
317  while ($rec = $ilDB->fetchAssoc($set))
318  {
319  $cid = base_convert((string) $cnt, 10, 36);
320  $ilDB->manipulate("UPDATE ctrl_classfile SET ".
321  " cid = ".$ilDB->quote($cid, "text").
322  " WHERE class = ".$ilDB->quote($rec["class"], "text")
323  );
324  $cnt++;
325  }
326  }
327 }
328 ?>