22 $this->class_script = array();
23 $this->class_childs = array();
24 $this->executed =
false;
25 $this->ini = $a_ini_file;
30 $this->ini = $a_ini_file;
40 $this->ini->setVariable(
"db",
"structure_reload",
"1");
42 if ($this->ini->readVariable(
"db",
"structure_reload") !=
"1") {
43 echo
"Error Cannot write client.ini.file.";
59 if (!$a_force && $this->ini->readVariable(
"db",
"structure_reload") !=
"1") {
63 require_once(
'./Services/UICore/classes/class.ilCachedCtrl.php');
65 require_once(
'./Services/GlobalCache/classes/class.ilGlobalCache.php');
66 ilGlobalCache::flushAll();
69 $this->comp_prefix = $a_comp_prefix;
72 $this->plugin_path = $a_plugin_path;
75 if (!$this->executed) {
77 $this->start_dir = ILIAS_ABSOLUTE_PATH;
78 $this->
read(ILIAS_ABSOLUTE_PATH);
80 $this->start_dir = $a_dir;
85 $this->executed =
true;
87 $this->ini->setVariable(
"db",
"structure_reload",
"0");
99 return realpath(str_replace([
'//'], [
'/'], $path));
110 if (defined(ILIAS_ABSOLUTE_PATH)) {
111 $il_absolute_path = ILIAS_ABSOLUTE_PATH;
113 $il_absolute_path = dirname(__FILE__, 5);
117 if (!@is_dir($a_cdir)) {
122 $dir = opendir($a_cdir);
124 while ($file = readdir($dir)) {
128 if (@is_dir($a_cdir .
"/" . $file)) {
132 $this->
read($a_cdir .
"/" . $file);
137 if (@is_file($a_cdir .
"/" . $file)) {
138 if (preg_match(
"~^class.*php$~i", $file) || preg_match(
"~^ilSCORM13Player.php$~i", $file)) {
139 $handle = fopen($a_cdir .
"/" . $file,
"r");
141 while (!feof($handle)) {
142 $line = fgets($handle, 4096);
145 $pos = strpos(strtolower($line),
"@ilctrl_calls");
147 $com = substr($line, $pos + 14);
148 $pos2 = strpos($com,
":");
150 $com_arr = explode(
":", $com);
151 $parent = strtolower(trim($com_arr[0]));
154 if ($parent !=
"" && isset($this->class_script[$parent]) &&
155 $this->class_script[$parent] != $a_cdir .
"/" . $file) {
157 $ilDB->manipulate(
"DELETE FROM ctrl_classfile WHERE comp_prefix = " .
158 $ilDB->quote($this->comp_prefix,
"text"));
159 if ($this->comp_prefix ==
"") {
160 $ilDB->manipulate($q =
"DELETE FROM ctrl_classfile WHERE " .
161 $ilDB->equals(
"comp_prefix",
"",
"text",
true));
165 $ilDB->manipulate(
"DELETE FROM ctrl_calls WHERE comp_prefix = " .
166 $ilDB->quote($this->comp_prefix,
"text"));
167 if ($this->comp_prefix ==
"") {
168 $ilDB->manipulate(
"DELETE FROM ctrl_calls WHERE comp_prefix IS NULL");
171 $msg = implode(
"\n", [
172 "Error: Duplicate call structure definition found (Class %s) in files:",
176 "Please remove the file, that does not belong to the official ILIAS distribution.",
177 "After that invoke 'Tools' -> 'Reload Control Structure' in the ILIAS Setup." 180 throw new \Exception(
184 $this->class_script[$parent],
185 $a_cdir .
"/" . $file
190 $this->class_script[$parent] = $a_cdir .
"/" . $file;
191 $childs = explode(
",", $com_arr[1]);
192 foreach ($childs as $child) {
193 $child = trim(strtolower($child));
194 if (!isset($this->class_childs[$parent]) || !is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent])) {
195 $this->class_childs[$parent][] = $child;
202 $pos = strpos(strtolower($line),
"@ilctrl_iscalledby");
204 $com = substr($line, $pos + 19);
205 $pos2 = strpos($com,
":");
207 $com_arr = explode(
":", $com);
208 $child = strtolower(trim($com_arr[0]));
209 $this->class_script[$child] = $a_cdir .
"/" . $file;
211 $parents = explode(
",", $com_arr[1]);
212 foreach ($parents as $parent) {
213 $parent = trim(strtolower($parent));
214 if (!isset($this->class_childs[$parent]) || !is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent])) {
215 $this->class_childs[$parent][] = $child;
221 if (preg_match(
"~^class\.(.*GUI)\.php$~i", $file,
$res)) {
222 $cl = strtolower(
$res[1]);
223 $pos = strpos(strtolower($line),
"class " . $cl);
224 if (is_int($pos) && (!isset($this->class_script[$cl]) || $this->class_script[$cl] ==
"")) {
225 $this->class_script[$cl] = $a_cdir .
"/" . $file;
242 public function store($a_cdir =
"./..")
247 $ilDB->manipulate(
"DELETE FROM ctrl_classfile WHERE comp_prefix = " .
248 $ilDB->quote($this->comp_prefix,
"text"));
249 if ($this->comp_prefix ==
"") {
250 $ilDB->manipulate($q =
"DELETE FROM ctrl_classfile WHERE " .
251 $ilDB->equals(
"comp_prefix",
"",
"text",
true));
255 $ilDB->manipulate(
"DELETE FROM ctrl_calls WHERE comp_prefix = " .
256 $ilDB->quote($this->comp_prefix,
"text"));
257 if ($this->comp_prefix ==
"") {
258 $ilDB->manipulate(
"DELETE FROM ctrl_calls WHERE " .
259 $ilDB->equals(
"comp_prefix",
"",
"text",
true));
262 foreach ($this->class_script as $class => $script) {
263 $file = substr($script, strlen($this->start_dir) + 1);
266 $ilDB->manipulate(sprintf(
267 "INSERT INTO ctrl_classfile (class, filename, comp_prefix, plugin_path) " .
268 " VALUES (%s,%s,%s,%s)",
269 $ilDB->quote($class,
"text"),
270 $ilDB->quote($file,
"text"),
271 $ilDB->quote($this->comp_prefix,
"text"),
272 $ilDB->quote($this->plugin_path,
"text")
276 foreach ($this->class_childs as $parent => $v) {
277 if (is_array($this->class_childs[$parent])) {
278 foreach ($this->class_childs[$parent] as $child) {
279 if (strlen(trim($child)) and strlen(trim($parent))) {
281 $ilDB->manipulate(sprintf(
282 "INSERT INTO ctrl_calls (parent, child, comp_prefix) " .
284 $ilDB->quote($parent,
"text"),
285 $ilDB->quote($child,
"text"),
286 $ilDB->quote($this->comp_prefix,
"text")
302 "UPDATE ctrl_classfile SET " .
303 " cid = " .
$ilDB->quote(
"",
"text")
305 $set =
$ilDB->query(
"SELECT * FROM ctrl_classfile ");
307 while ($rec =
$ilDB->fetchAssoc($set)) {
308 $cid = base_convert((
string) $cnt, 10, 36);
310 "UPDATE ctrl_classfile SET " .
311 " cid = " .
$ilDB->quote($cid,
"text") .
312 " WHERE class = " .
$ilDB->quote($rec[
"class"],
"text")
320 $clone = clone $this;
327 if (!is_null($this->db)) {
determineClassFileIds()
Determine class file IDS.
readStructure( $a_force=false, $a_dir="", $a_comp_prefix="", $a_plugin_path="")
read structure
__construct($a_ini_file=null)
Class ilCtrlStructureReader.
foreach($_POST as $key=> $value) $res
normalizePath(string $path)
withDB(\ilDBInterface $db)
getStructure()
parse code files and store call structure in db
store($a_cdir="./..")
read structure into internal variables
read($a_cdir)
read structure into internal variables