ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCtrlStructureReader.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
37  var $executed;
38 
40  {
41  $this->class_script = array();
42  $this->class_childs = array();
43  $this->executed = false;
44  }
45 
46  function setErrorObject(&$err)
47  {
48  $this->err_object =& $err;
49  }
50 
54  function getStructure()
55  {
56  $this->get_structure = true;
57  }
58 
62  function readStructure($a_force = false, $a_dir = "", $a_comp_prefix = "")
63  {
64 
65  if (!$this->get_structure && !$a_force)
66  {
67  return;
68  }
69 
70  // prefix for component
71  $this->comp_prefix = $a_comp_prefix;
72 
73  // only run one time per db_update request
74  if (!$this->executed)
75  {
76  if ($a_dir == "")
77  {
78  $this->start_dir = ILIAS_ABSOLUTE_PATH;
79  $this->read(ILIAS_ABSOLUTE_PATH);
80  }
81  else
82  {
83  $this->start_dir = $a_dir;
84  $this->read($a_dir);
85  }
86  $this->store();
87  $this->executed = true;
88  }
89 
90  // read module information
91  // not clear whether this is a good place for module reading info
92  // or not
93  require_once("../classes/class.ilCtrl.php");
94  $ctrl = new ilCtrl();
95  $ctrl->storeCommonStructures();
96  }
97 
103  function read($a_cdir)
104  {
105  global $ilDB, $lng;
106 
107  // check wether $a_cdir is a directory
108  if (!@is_dir($a_cdir))
109  {
110  return false;
111  }
112 
113  // read current directory
114  $dir = opendir($a_cdir);
115 
116  while($file = readdir($dir))
117  {
118  if ($file != "." and
119  $file != "..")
120  {
121  // directories
122  if (@is_dir($a_cdir."/".$file))
123  {
124  if ($a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/data" &&
125  $a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/Customizing")
126  {
127  $this->read($a_cdir."/".$file);
128  }
129  }
130 
131  // files
132  if (@is_file($a_cdir."/".$file))
133  {
134  if (eregi("^class.*php$", $file))
135  {
136  $handle = fopen($a_cdir."/".$file, "r");
137 //echo "<br>".$a_cdir."/".$file;
138  while (!feof($handle)) {
139  $line = fgets($handle, 4096);
140 
141  // handle @ilctrl_calls
142  $pos = strpos(strtolower($line), "@ilctrl_calls");
143  if (is_int($pos))
144  {
145  $com = substr($line, $pos + 14);
146  $pos2 = strpos($com, ":");
147  if (is_int($pos2))
148  {
149  $com_arr = explode(":", $com);
150  $parent = strtolower(trim($com_arr[0]));
151 
152  // check file duplicates
153  if ($parent != "" && isset($this->class_script[$parent]) &&
154  $this->class_script[$parent] != $a_cdir."/".$file)
155  {
156  // delete all class to file assignments
157  $q = "DELETE FROM ctrl_classfile WHERE comp_prefix = ".
158  $ilDB->quote($this->comp_prefix);
159  $ilDB->query($q);
160 
161  // delete all call entries
162  $q = "DELETE FROM ctrl_calls WHERE comp_prefix = ".
163  $ilDB->quote($this->comp_prefix);
164  $ilDB->query($q);
165 
166  $this->err_object->raiseError(
167  sprintf($lng->txt("duplicate_ctrl"),
168  $parent,
169  $this->class_script[$parent],
170  $a_cdir."/".$file)
171  , $this->err_object->MESSAGE);
172  }
173 
174  $this->class_script[$parent] = $a_cdir."/".$file;
175  $childs = explode(",", $com_arr[1]);
176  foreach($childs as $child)
177  {
178  $child = trim(strtolower($child));
179  if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
180  {
181  $this->class_childs[$parent][] = $child;
182  }
183  }
184  }
185  }
186 
187  // handle isCalledBy comments
188  $pos = strpos(strtolower($line), "@ilctrl_iscalledby");
189  if (is_int($pos))
190  {
191  $com = substr($line, $pos + 19);
192  $pos2 = strpos($com, ":");
193  if (is_int($pos2))
194  {
195  $com_arr = explode(":", $com);
196  $child = strtolower(trim($com_arr[0]));
197  $this->class_script[$child] = $a_cdir."/".$file;
198 
199  $parents = explode(",", $com_arr[1]);
200  foreach($parents as $parent)
201  {
202  $parent = trim(strtolower($parent));
203  if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
204  {
205  $this->class_childs[$parent][] = $child;
206  }
207  }
208  }
209  }
210  }
211  fclose($handle);
212  }
213  }
214  }
215  }
216  }
217 
223  function store($a_cdir = "./..")
224  {
225  global $ilDB;
226 
227  // delete all class to file assignments
228  $q = "DELETE FROM ctrl_classfile WHERE comp_prefix = ".
229  $ilDB->quote($this->comp_prefix);
230  $ilDB->query($q);
231 
232  // delete all call entries
233  $q = "DELETE FROM ctrl_calls WHERE comp_prefix = ".
234  $ilDB->quote($this->comp_prefix);
235  $ilDB->query($q);
236 
237  foreach($this->class_script as $class => $script)
238  {
239  $file = substr($script, strlen($this->start_dir) + 1);
240 
241  // store class to file assignment
242  $q = "INSERT INTO ctrl_classfile (class, file, comp_prefix) VALUES".
243  "(".$ilDB->quote($class).",".$ilDB->quote($file).
244  ",".$ilDB->quote($this->comp_prefix).")";
245  $ilDB->query($q);
246  }
247 //$this->class_childs[$parent][] = $child;
248  foreach($this->class_childs as $parent => $v)
249  {
250  if (is_array($this->class_childs[$parent]))
251  {
252  foreach($this->class_childs[$parent] as $child)
253  {
254  // store call entry
255  $q = "INSERT INTO ctrl_calls (parent, child, comp_prefix) VALUES".
256  "(".$ilDB->quote($parent).",".$ilDB->quote($child).
257  ",".$ilDB->quote($this->comp_prefix).")";
258  $ilDB->query($q);
259  }
260  }
261  }
262 
263  }
264 
265 }