ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 public $executed;
18
19 public function __construct($a_ini_file = null)
20 {
21 $this->class_script = array();
22 $this->class_childs = array();
23 $this->executed = false;
24 $this->ini = $a_ini_file;
25 }
26
27 public function setIniFile($a_ini_file)
28 {
29 $this->ini = $a_ini_file;
30 }
31
35 public function getStructure()
36 {
37 global $ilDB;
38
39 $this->ini->setVariable("db", "structure_reload", "1");
40 $this->ini->write();
41 if ($this->ini->readVariable("db", "structure_reload") != "1") {
42 echo "Error Cannot write client.ini.file.";
43 }
44 //$this->get_structure = true;
45 }
46
50 public function readStructure(
51 $a_force = false,
52 $a_dir = "",
53 $a_comp_prefix = "",
54 $a_plugin_path = ""
55 ) {
56 global $ilDB;
57
58 if (!$a_force && $this->ini->readVariable("db", "structure_reload") != "1") {
59 return;
60 }
61
62 require_once('./Services/UICore/classes/class.ilCachedCtrl.php');
64 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
65 ilGlobalCache::flushAll();
66
67 // prefix for component
68 $this->comp_prefix = $a_comp_prefix;
69
70 // plugin path
71 $this->plugin_path = $a_plugin_path;
72
73 // only run one time per db_update request
74 if (!$this->executed) {
75 if ($a_dir == "") {
76 $this->start_dir = ILIAS_ABSOLUTE_PATH;
77 $this->read(ILIAS_ABSOLUTE_PATH);
78 } else {
79 $this->start_dir = $a_dir;
80 $this->read($a_dir);
81 }
82 $this->store();
83 $this->determineClassFileIds();
84 $this->executed = true;
85 if (!$a_force) {
86 $this->ini->setVariable("db", "structure_reload", "0");
87 $this->ini->write();
88 }
89 }
90 }
91
97 public function read($a_cdir)
98 {
99 global $ilDB, $lng;
100
101 // check wether $a_cdir is a directory
102 if (!@is_dir($a_cdir)) {
103 return false;
104 }
105
106 // read current directory
107 $dir = opendir($a_cdir);
108
109 while ($file = readdir($dir)) {
110 if ($file != "." and
111 $file != "..") {
112 // directories
113 if (@is_dir($a_cdir . "/" . $file)) {
114 if ($a_cdir . "/" . $file != ILIAS_ABSOLUTE_PATH . "/data" &&
115 $a_cdir . "/" . $file != ILIAS_ABSOLUTE_PATH . "/Customizing") {
116 $this->read($a_cdir . "/" . $file);
117 }
118 }
119
120 // files
121 if (@is_file($a_cdir . "/" . $file)) {
122 if (preg_match("~^class.*php$~i", $file) || preg_match("~^ilSCORM13Player.php$~i", $file)) {
123 $handle = fopen($a_cdir . "/" . $file, "r");
124 //echo "<br>".$a_cdir."/".$file;
125 while (!feof($handle)) {
126 $line = fgets($handle, 4096);
127
128 // handle @ilctrl_calls
129 $pos = strpos(strtolower($line), "@ilctrl_calls");
130 if (is_int($pos)) {
131 $com = substr($line, $pos + 14);
132 $pos2 = strpos($com, ":");
133 if (is_int($pos2)) {
134 $com_arr = explode(":", $com);
135 $parent = strtolower(trim($com_arr[0]));
136
137 // check file duplicates
138 if ($parent != "" && isset($this->class_script[$parent]) &&
139 $this->class_script[$parent] != $a_cdir . "/" . $file) {
140 // delete all class to file assignments
141 $ilDB->manipulate("DELETE FROM ctrl_classfile WHERE comp_prefix = " .
142 $ilDB->quote($this->comp_prefix, "text"));
143 if ($this->comp_prefix == "") {
144 $ilDB->manipulate($q = "DELETE FROM ctrl_classfile WHERE " .
145 $ilDB->equals("comp_prefix", "", "text", true));
146 }
147
148 // delete all call entries
149 $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix = " .
150 $ilDB->quote($this->comp_prefix, "text"));
151 if ($this->comp_prefix == "") {
152 $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix IS NULL");
153 }
154
155 throw new \Exception(
156 sprintf(
157 $lng->txt("duplicate_ctrl"),
158 $parent,
159 $this->class_script[$parent],
160 $a_cdir . "/" . $file
161 )
162 );
163 }
164
165 $this->class_script[$parent] = $a_cdir . "/" . $file;
166 $childs = explode(",", $com_arr[1]);
167 foreach ($childs as $child) {
168 $child = trim(strtolower($child));
169 if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent])) {
170 $this->class_childs[$parent][] = $child;
171 }
172 }
173 }
174 }
175
176 // handle isCalledBy comments
177 $pos = strpos(strtolower($line), "@ilctrl_iscalledby");
178 if (is_int($pos)) {
179 $com = substr($line, $pos + 19);
180 $pos2 = strpos($com, ":");
181 if (is_int($pos2)) {
182 $com_arr = explode(":", $com);
183 $child = strtolower(trim($com_arr[0]));
184 $this->class_script[$child] = $a_cdir . "/" . $file;
185
186 $parents = explode(",", $com_arr[1]);
187 foreach ($parents as $parent) {
188 $parent = trim(strtolower($parent));
189 if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent])) {
190 $this->class_childs[$parent][] = $child;
191 }
192 }
193 }
194 }
195
196 if (preg_match("~^class\.(.*GUI)\.php$~i", $file, $res)) {
197 $cl = strtolower($res[1]);
198 $pos = strpos(strtolower($line), "class " . $cl);
199 if (is_int($pos) && $this->class_script[$cl] == "") {
200 $this->class_script[$cl] = $a_cdir . "/" . $file;
201 //echo "<br>".$cl."-".$this->class_script[$cl]."-";
202 }
203 }
204 }
205 fclose($handle);
206 }
207 }
208 }
209 }
210 }
211
217 public function store($a_cdir = "./..")
218 {
219 global $ilDB;
220
221 // delete all class to file assignments
222 $ilDB->manipulate("DELETE FROM ctrl_classfile WHERE comp_prefix = " .
223 $ilDB->quote($this->comp_prefix, "text"));
224 if ($this->comp_prefix == "") {
225 $ilDB->manipulate($q = "DELETE FROM ctrl_classfile WHERE " .
226 $ilDB->equals("comp_prefix", "", "text", true));
227 }
228
229 // delete all call entries
230 $ilDB->manipulate("DELETE FROM ctrl_calls WHERE comp_prefix = " .
231 $ilDB->quote($this->comp_prefix, "text"));
232 if ($this->comp_prefix == "") {
233 $ilDB->manipulate("DELETE FROM ctrl_calls WHERE " .
234 $ilDB->equals("comp_prefix", "", "text", true));
235 }
236
237 foreach ($this->class_script as $class => $script) {
238 $file = substr($script, strlen($this->start_dir) + 1);
239
240 // store class to file assignment
241 $ilDB->manipulate(sprintf(
242 "INSERT INTO ctrl_classfile (class, filename, comp_prefix, plugin_path) " .
243 " VALUES (%s,%s,%s,%s)",
244 $ilDB->quote($class, "text"),
245 $ilDB->quote($file, "text"),
246 $ilDB->quote($this->comp_prefix, "text"),
247 $ilDB->quote($this->plugin_path, "text")
248 ));
249 }
250 //$this->class_childs[$parent][] = $child;
251 foreach ($this->class_childs as $parent => $v) {
252 if (is_array($this->class_childs[$parent])) {
253 foreach ($this->class_childs[$parent] as $child) {
254 if (strlen(trim($child)) and strlen(trim($parent))) {
255 // store call entry
256 $ilDB->manipulate(sprintf(
257 "INSERT INTO ctrl_calls (parent, child, comp_prefix) " .
258 "VALUES (%s,%s,%s)",
259 $ilDB->quote($parent, "text"),
260 $ilDB->quote($child, "text"),
261 $ilDB->quote($this->comp_prefix, "text")
262 ));
263 }
264 }
265 }
266 }
267 }
268
272 public function determineClassFileIds()
273 {
274 global $ilDB;
275
276 $ilDB->manipulate(
277 "UPDATE ctrl_classfile SET " .
278 " cid = " . $ilDB->quote("", "text")
279 );
280 $set = $ilDB->query("SELECT * FROM ctrl_classfile ");
281 $cnt = 1;
282 while ($rec = $ilDB->fetchAssoc($set)) {
283 $cid = base_convert((string) $cnt, 10, 36);
284 $ilDB->manipulate(
285 "UPDATE ctrl_classfile SET " .
286 " cid = " . $ilDB->quote($cid, "text") .
287 " WHERE class = " . $ilDB->quote($rec["class"], "text")
288 );
289 $cnt++;
290 }
291 }
292}
An exception for terminatinating execution or to throw for unit testing.
Class ilCtrlStructureReader.
determineClassFileIds()
Determine class file IDS.
store($a_cdir="./..")
read structure into internal variables
readStructure( $a_force=false, $a_dir="", $a_comp_prefix="", $a_plugin_path="")
read structure
read($a_cdir)
read structure into internal variables
getStructure()
parse code files and store call structure in db
$lng
foreach($_POST as $key=> $value) $res
global $ilDB