ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
19  function __construct()
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 (preg_match("~^class.*php$~i", $file) || preg_match("~^ilSCORM13Player.php$~i", $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  throw new \Exception(
184  sprintf(
185  $lng->txt("duplicate_ctrl"),
186  $parent,
187  $this->class_script[$parent],
188  $a_cdir."/".$file
189  )
190  );
191  }
192 
193  $this->class_script[$parent] = $a_cdir."/".$file;
194  $childs = explode(",", $com_arr[1]);
195  foreach($childs as $child)
196  {
197  $child = trim(strtolower($child));
198  if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
199  {
200  $this->class_childs[$parent][] = $child;
201  }
202  }
203  }
204  }
205 
206  // handle isCalledBy comments
207  $pos = strpos(strtolower($line), "@ilctrl_iscalledby");
208  if (is_int($pos))
209  {
210  $com = substr($line, $pos + 19);
211  $pos2 = strpos($com, ":");
212  if (is_int($pos2))
213  {
214  $com_arr = explode(":", $com);
215  $child = strtolower(trim($com_arr[0]));
216  $this->class_script[$child] = $a_cdir."/".$file;
217 
218  $parents = explode(",", $com_arr[1]);
219  foreach($parents as $parent)
220  {
221  $parent = trim(strtolower($parent));
222  if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
223  {
224  $this->class_childs[$parent][] = $child;
225  }
226  }
227  }
228  }
229 
230  if (preg_match("~^class\.(.*GUI)\.php$~i", $file, $res))
231  {
232  $cl = strtolower($res[1]);
233  $pos = strpos(strtolower($line), "class ".$cl);
234  if (is_int($pos) && $this->class_script[$cl] == "")
235  {
236  $this->class_script[$cl] = $a_cdir."/".$file;
237  //echo "<br>".$cl."-".$this->class_script[$cl]."-";
238  }
239  }
240  }
241  fclose($handle);
242  }
243  }
244  }
245  }
246  }
247 
253  function store($a_cdir = "./..")
254  {
255  global $ilDB;
256 
257  // delete all class to file assignments
258  $ilDB->manipulate("DELETE FROM ctrl_classfile WHERE comp_prefix = ".
259  $ilDB->quote($this->comp_prefix, "text"));
260  if ($this->comp_prefix == "")
261  {
262  $ilDB->manipulate($q = "DELETE FROM ctrl_classfile WHERE ".
263  $ilDB->equals("comp_prefix", "", "text", true));
264  }
265 
266  // delete all call entries
267  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix = ".
268  $ilDB->quote($this->comp_prefix, "text"));
269  if ($this->comp_prefix == "")
270  {
271  $ilDB->manipulate("DELETE FROM ctrl_calls WHERE ".
272  $ilDB->equals("comp_prefix", "", "text", true));
273  }
274 
275  foreach($this->class_script as $class => $script)
276  {
277  $file = substr($script, strlen($this->start_dir) + 1);
278 
279  // store class to file assignment
280  $ilDB->manipulate(sprintf("INSERT INTO ctrl_classfile (class, filename, comp_prefix, plugin_path) ".
281  " VALUES (%s,%s,%s,%s)",
282  $ilDB->quote($class, "text"),
283  $ilDB->quote($file, "text"),
284  $ilDB->quote($this->comp_prefix, "text"),
285  $ilDB->quote($this->plugin_path, "text")
286  ));
287  }
288 //$this->class_childs[$parent][] = $child;
289  foreach($this->class_childs as $parent => $v)
290  {
291  if (is_array($this->class_childs[$parent]))
292  {
293  foreach($this->class_childs[$parent] as $child)
294  {
295  if(strlen(trim($child)) and strlen(trim($parent)))
296  {
297  // store call entry
298  $ilDB->manipulate(sprintf("INSERT INTO ctrl_calls (parent, child, comp_prefix) ".
299  "VALUES (%s,%s,%s)",
300  $ilDB->quote($parent, "text"),
301  $ilDB->quote($child, "text"),
302  $ilDB->quote($this->comp_prefix, "text")));
303  }
304  }
305  }
306  }
307 
308  }
309 
314  {
315  global $ilDB;
316 
317  $ilDB->manipulate("UPDATE ctrl_classfile SET ".
318  " cid = ".$ilDB->quote("", "text")
319  );
320  $set = $ilDB->query("SELECT * FROM ctrl_classfile ");
321  $cnt = 1;
322  while ($rec = $ilDB->fetchAssoc($set))
323  {
324  $cid = base_convert((string) $cnt, 10, 36);
325  $ilDB->manipulate("UPDATE ctrl_classfile SET ".
326  " cid = ".$ilDB->quote($cid, "text").
327  " WHERE class = ".$ilDB->quote($rec["class"], "text")
328  );
329  $cnt++;
330  }
331  }
332 }
333 ?>
This class provides processing control methods.
determineClassFileIds()
Determine class file IDS.
Class ilCtrlStructureReader.
getStructure()
parse code files and store call structure in db
Create styles array
The data for the language used.
store($a_cdir="./..")
read structure into internal variables
global $lng
Definition: privfeed.php:17
global $ilDB
readStructure($a_force=false, $a_dir="", $a_comp_prefix="", $a_plugin_path="")
read structure
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
read($a_cdir)
read structure into internal variables