34 "trac",
"taxf",
"auth",
"rolf",
"assf",
"svyf",
"extt",
"adve",
"fold");
46 "restore_trash" =>
false,
47 "purge_trash" =>
false
118 global $objDefinition,
$ilDB;
121 $this->rbac_object_types =
"'".implode(
"','",$objDefinition->getAllRBACObjects()).
"'";
122 $this->rbac_object_types = $objDefinition->getAllRBACObjects();
126 $this->logging =
true;
130 include_once
"./Services/Logging/classes/class.ilLog.php";
136 include_once
'./Services/Logging/classes/class.ilLog.php';
137 $this->scan_log =
new ilLog(CLIENT_DATA_DIR,
"scanlog.log");
138 $this->scan_log->setLogFormat(
"");
151 return array_keys($this->mode);
167 if ((!in_array($a_mode,array_keys($this->mode)) and $a_mode !=
"all") or !is_bool($a_value))
169 $this->throwError(INVALID_PARAM, FATAL,
DEBUG);
173 if ($a_mode ==
"all")
175 foreach ($this->mode as
$mode => $value)
177 $this->mode[
$mode] = $a_value;
182 $this->mode[$a_mode] = $a_value;
201 if (!in_array($a_mode,array_keys($this->mode)))
203 $this->throwError(VALIDATER_UNKNOWN_MODE, WARNING,
DEBUG);
207 return $this->mode[$a_mode];
227 if ($this->mode[
"restore"] ===
true)
229 $this->mode[
"scan"] =
true;
230 $this->mode[
"purge"] =
false;
233 if ($this->mode[
"purge"] ===
true)
235 $this->mode[
"scan"] =
true;
236 $this->mode[
"restore"] =
false;
239 if ($this->mode[
"restore_trash"] ===
true)
241 $this->mode[
"scan"] =
true;
242 $this->mode[
"purge_trash"] =
false;
245 if ($this->mode[
"purge_trash"] ===
true)
247 $this->mode[
"scan"] =
true;
248 $this->mode[
"restore_trash"] =
false;
251 if ($this->mode[
"clean"] ===
true)
253 $this->mode[
"scan"] =
true;
275 $summary .=
$lng->txt(
"scanning_system");
278 $summary .=
$lng->txt(
"disabled");
282 $summary .=
"<br/>".$lng->txt(
"searching_invalid_refs");
289 $summary .=
$lng->txt(
"found_none");
292 $summary .=
"<br/>".$lng->txt(
"searching_invalid_childs");
300 $summary .=
$lng->txt(
"found_none");
303 $summary .=
"<br/>".$lng->txt(
"searching_missing_objs");
311 $summary .=
$lng->txt(
"found_none");
314 $summary .=
"<br/>".$lng->txt(
"searching_unbound_objs");
322 $summary .=
$lng->txt(
"found_none");
325 $summary .=
"<br/>".$lng->txt(
"searching_deleted_objs");
333 $summary .=
$lng->txt(
"found_none");
336 $summary .=
"<br/>".$lng->txt(
"searching_invalid_rolfs");
344 $summary .=
$lng->txt(
"found_none");
347 $summary .=
"<br/><br/>".$lng->txt(
"analyzing_tree_structure");
350 $summary .=
$lng->txt(
"tree_corrupt");
354 $summary .=
$lng->txt(
"done");
360 $summary .=
"<br /><br />".$lng->txt(
"dumping_tree");
363 $summary .=
$lng->txt(
"disabled");
368 if ($error_count > 0)
370 $summary .=
$lng->txt(
"tree_corrupt");
374 $summary .=
$lng->txt(
"done");
380 $summary .=
"<br /><br />".$lng->txt(
"cleaning");
383 $summary .=
$lng->txt(
"disabled");
387 $summary .=
"<br />".$lng->txt(
"removing_invalid_refs");
390 $summary .= strtolower(
$lng->txt(
"done"));
394 $summary .=
$lng->txt(
"nothing_to_remove").$lng->txt(
"skipped");
397 $summary .=
"<br />".$lng->txt(
"removing_invalid_childs");
400 $summary .= strtolower(
$lng->txt(
"done"));
404 $summary .=
$lng->txt(
"nothing_to_remove").$lng->txt(
"skipped");
407 $summary .=
"<br />".$lng->txt(
"removing_invalid_rolfs");
410 $summary .= strtolower(
$lng->txt(
"done"));
414 $summary .=
$lng->txt(
"nothing_to_remove").$lng->txt(
"skipped");
424 $summary .=
"<br /><br />".$lng->txt(
"restoring");
428 $summary .=
$lng->txt(
"disabled");
432 $summary .=
"<br />".$lng->txt(
"restoring_missing_objs");
435 $summary .= strtolower(
$lng->txt(
"done"));
439 $summary .=
$lng->txt(
"nothing_to_restore").$lng->txt(
"skipped");
442 $summary .=
"<br />".$lng->txt(
"restoring_unbound_objs");
445 $summary .= strtolower(
$lng->txt(
"done"));
449 $summary .=
$lng->txt(
"nothing_to_restore").$lng->txt(
"skipped");
454 $summary .=
"<br /><br />".$lng->txt(
"restoring_trash");
458 $summary .=
$lng->txt(
"disabled");
464 $summary .= strtolower(
$lng->txt(
"done"));
468 $summary .=
$lng->txt(
"nothing_to_restore").$lng->txt(
"skipped");
473 $summary .=
"<br /><br />".$lng->txt(
"purging");
477 $summary .=
$lng->txt(
"disabled");
481 $summary .=
"<br />".$lng->txt(
"purging_missing_objs");
484 $summary .= strtolower(
$lng->txt(
"done"));
488 $summary .=
$lng->txt(
"nothing_to_purge").$lng->txt(
"skipped");
491 $summary .=
"<br />".$lng->txt(
"purging_unbound_objs");
494 $summary .= strtolower(
$lng->txt(
"done"));
498 $summary .=
$lng->txt(
"nothing_to_purge").$lng->txt(
"skipped");
503 $summary .=
"<br /><br />".$lng->txt(
"purging_trash");
507 $summary .=
$lng->txt(
"disabled");
513 $summary .= strtolower(
$lng->txt(
"done"));
517 $summary .=
$lng->txt(
"nothing_to_purge").$lng->txt(
"skipped");
524 $summary .=
"<br /><br />".$lng->txt(
"cleaning_final");
527 $summary .=
"<br />".$lng->txt(
"initializing_gaps").
" ".strtolower(
$lng->txt(
"done"));
535 foreach ($this->mode as
$mode => $value)
537 $arr[] =
$mode.
"[".(int)$value.
"]";
558 if ($this->mode[
"scan"] !==
true)
564 $this->missing_objects = array();
573 $q =
"SELECT object_data.*, ref_id FROM object_data ".
574 "LEFT JOIN object_reference ON object_data.obj_id = object_reference.obj_id ".
575 "LEFT JOIN tree ON object_reference.ref_id = tree.child ".
576 "WHERE tree.child IS NULL ".
577 "AND (object_reference.obj_id IS NOT NULL ".
578 " OR object_data.type <> 'file' AND ".
579 $ilDB->in(
'object_data.type',$this->rbac_object_types,
false,
'text').
581 $r = $this->db->query($q);
585 #if (!in_array($row->type,$this->object_types_exclude))
588 $this->missing_objects[] = array(
589 "obj_id" =>
$row->obj_id,
590 "type" =>
$row->type,
591 "ref_id" =>
$row->ref_id,
592 "child" =>
$row->child,
593 "title" =>
$row->title,
594 "desc" =>
$row->description,
595 "owner" =>
$row->owner,
596 "create_date" =>
$row->create_date,
597 "last_update" =>
$row->last_update
603 if (count($this->missing_objects) > 0)
605 $this->
writeScanLogLine(
"obj_id\ttype\tref_id\tchild\ttitle\tdesc\towner\tcreate_date\tlast_update");
630 if ($this->mode[
"scan"] !==
true)
636 $this->invalid_rolefolders = array();
641 $q =
"SELECT object_data.*, ref_id FROM object_data ".
642 "LEFT JOIN object_reference ON object_data.obj_id = object_reference.obj_id ".
643 "LEFT JOIN tree ON object_reference.ref_id = tree.child ".
644 "WHERE (object_reference.obj_id IS NULL OR tree.child IS NULL) ".
645 "AND object_data.type='rolf'";
646 $r = $this->db->query($q);
650 $this->invalid_rolefolders[] = array(
651 "obj_id" =>
$row->obj_id,
652 "type" =>
$row->type,
653 "ref_id" =>
$row->ref_id,
654 "child" =>
$row->child,
655 "title" =>
$row->title,
656 "desc" =>
$row->description,
657 "owner" =>
$row->owner,
658 "create_date" =>
$row->create_date,
659 "last_update" =>
$row->last_update
664 $q =
"SELECT object_data.*, ref_id FROM object_data ".
665 "LEFT JOIN object_reference ON object_data.obj_id = object_reference.obj_id ".
666 "LEFT JOIN tree ON object_reference.ref_id = tree.child ".
667 "WHERE object_reference.ref_id = ".$ilDB->quote(RECOVERY_FOLDER_ID,
'integer').
" ".
668 "AND object_data.type='rolf'";
669 $r = $this->db->query($q);
673 $this->invalid_rolefolders[] = array(
674 "obj_id" =>
$row->obj_id,
675 "type" =>
$row->type,
676 "ref_id" =>
$row->ref_id,
677 "child" =>
$row->child,
678 "title" =>
$row->title,
679 "desc" =>
$row->description,
680 "owner" =>
$row->owner,
681 "create_date" =>
$row->create_date,
682 "last_update" =>
$row->last_update
687 if (count($this->invalid_rolefolders) > 0)
689 $this->
writeScanLogLine(
"obj_id\ttype\tref_id\tchild\ttitle\tdesc\towner\tcreate_date\tlast_update");
712 if ($this->mode[
"scan"] !==
true)
718 $this->invalid_rbac_entries = array();
722 $q =
"SELECT object_data.*, ref_id FROM object_data ".
723 "LEFT JOIN object_reference ON object_data.obj_id = object_reference.obj_id ".
724 "LEFT JOIN tree ON object_reference.ref_id = tree.child ".
725 "WHERE (object_reference.obj_id IS NULL OR tree.child IS NULL) ".
726 "AND object_data.type='rolf'";
727 $r = $this->db->query($q);
731 $this->invalid_rolefolders[] = array(
732 "obj_id" =>
$row->obj_id,
733 "type" =>
$row->type,
734 "ref_id" =>
$row->ref_id,
735 "child" =>
$row->child,
736 "title" =>
$row->title,
737 "desc" =>
$row->description,
738 "owner" =>
$row->owner,
739 "create_date" =>
$row->create_date,
740 "last_update" =>
$row->last_update
745 $q =
"SELECT object_data.*, ref_id FROM object_data ".
746 "LEFT JOIN object_reference ON object_data.obj_id = object_reference.obj_id ".
747 "LEFT JOIN tree ON object_reference.ref_id = tree.child ".
748 "WHERE object_reference.ref_id =".$ilDB->quote(RECOVERY_FOLDER_ID).
" ".
749 "AND object_data.type='rolf'";
750 $r = $this->db->query($q);
754 $this->invalid_rolefolders[] = array(
755 "obj_id" =>
$row->obj_id,
756 "type" =>
$row->type,
757 "ref_id" =>
$row->ref_id,
758 "child" =>
$row->child,
759 "title" =>
$row->title,
760 "desc" =>
$row->description,
761 "owner" =>
$row->owner,
762 "create_date" =>
$row->create_date,
763 "last_update" =>
$row->last_update
768 if (count($this->invalid_rolefolders) > 0)
770 $this->
writeScanLogLine(
"obj_id\ttype\tref_id\tchild\ttitle\tdesc\towner\tcreate_date\tlast_update");
811 if ($this->mode[
"scan"] !==
true)
817 $this->invalid_references = array();
820 $q =
"SELECT object_reference.* FROM object_reference ".
821 "LEFT JOIN object_data ON object_data.obj_id = object_reference.obj_id ".
822 "WHERE object_data.obj_id IS NULL ".
823 "OR ".$ilDB->in(
'object_data.type',$this->rbac_object_types,
true,
'text');
824 $r = $this->db->query($q);
828 $this->invalid_references[] = array(
829 "ref_id" =>
$row->ref_id,
830 "obj_id" =>
$row->obj_id,
831 "msg" =>
"Object does not exist."
836 if (count($this->invalid_references) > 0)
874 if ($this->mode[
"scan"] !==
true)
880 $this->invalid_childs = array();
884 $q =
"SELECT tree.*,object_reference.ref_id FROM tree ".
885 "LEFT JOIN object_reference ON tree.child = object_reference.ref_id ".
886 "LEFT JOIN object_data ON object_reference.obj_id = object_data.obj_id ".
887 "WHERE object_reference.ref_id IS NULL or object_data.obj_id IS NULL";
888 $r = $this->db->query($q);
891 $this->invalid_childs[] = array(
892 "child" =>
$row->child,
893 "ref_id" =>
$row->ref_id,
894 "msg" =>
"No object found"
898 if (count($this->invalid_childs) > 0)
936 if ($this->mode[
"scan"] !==
true)
942 $this->unbound_objects = array();
946 $q =
"SELECT T1.tree,T1.child,T1.parent,".
947 "T2.tree deleted,T2.parent grandparent ".
949 "LEFT JOIN tree T2 ON T2.child=T1.parent ".
950 "WHERE (T2.tree!=1 OR T2.tree IS NULL) AND T1.parent!=0";
951 $r = $this->db->query($q);
956 if (
$row->deleted === NULL)
958 $this->unbound_objects[] = array(
959 "child" =>
$row->child,
960 "parent" =>
$row->parent,
961 "tree" =>
$row->tree,
962 "msg" =>
"No valid parent node found"
967 if (count($this->unbound_objects) > 0)
992 if ($this->mode[
"scan"] !==
true)
998 $this->deleted_objects = array();
1003 $query =
"SELECT object_data.*,tree.tree,tree.child,tree.parent,deleted ".
1004 "FROM object_data ".
1005 "LEFT JOIN object_reference ON object_data.obj_id=object_reference.obj_id ".
1006 "LEFT JOIN tree ON tree.child=object_reference.ref_id ".
1007 " WHERE tree != 1 ".
1008 " ORDER BY deleted";
1011 include_once
'./Services/Calendar/classes/class.ilDateTime.php';
1016 $this->deleted_objects[] = array(
1017 "child" =>
$row->child,
1018 "parent" =>
$row->parent,
1019 "tree" =>
$row->tree,
1020 "type" =>
$row->type,
1021 "title" =>
$row->title,
1022 "desc" =>
$row->description,
1023 "owner" =>
$row->owner,
1024 "deleted" =>
$row->deleted,
1025 "deleted_timestamp" => $tmp_date->get(
IL_CAL_UNIX),
1026 "create_date" =>
$row->create_date,
1027 "last_update" =>
$row->last_update
1031 if (count($this->deleted_objects) > 0)
1099 if ($this->mode[
"clean"] !==
true)
1106 if ($a_invalid_refs === NULL and isset($this->invalid_references))
1112 if (!is_array($a_invalid_refs))
1114 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1118 if (count($a_invalid_refs) == 0)
1128 $message =
sprintf(
'%s::removeInvalidReferences(): Started...',
1135 foreach ($a_invalid_refs as $entry)
1137 $query =
"DELETE FROM object_reference WHERE ref_id= ".$this->db->quote($entry[
"ref_id"],
'integer').
1138 " AND obj_id = ".$this->db->quote($entry[
"obj_id"],
'integer').
" ";
1141 $message =
sprintf(
'%s::removeInvalidReferences(): Reference %s removed',
1166 if ($this->mode[
"clean"] !==
true)
1173 if ($a_invalid_childs === NULL and isset($this->invalid_childs))
1179 if (!is_array($a_invalid_childs))
1181 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1186 if (count($a_invalid_childs) == 0)
1196 $message =
sprintf(
'%s::removeInvalidChilds(): Started...',
1200 foreach ($a_invalid_childs as $entry)
1202 $q =
"DELETE FROM tree WHERE child='".$entry[
"child"].
"'";
1203 $this->db->query($q);
1205 $message =
sprintf(
'%s::removeInvalidChilds(): Entry child=%s removed',
1231 if ($this->mode[
"clean"] !==
true)
1238 if ($a_invalid_rolefolders === NULL and isset($this->invalid_rolefolders))
1244 if (!is_array($a_invalid_rolefolders))
1246 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1251 if (count($a_invalid_rolefolders) == 0)
1263 $message =
sprintf(
'%s::removeInvalidRolefolders(): Started...',
1270 foreach ($a_invalid_rolefolders as $rolf)
1273 if ($rolf[
"ref_id"] === NULL)
1277 $this->
writeScanLogLine(
"Created missing reference '".$rolf[
"ref_id"].
"' for rolefolder object '".$rolf[
"obj_id"].
"'");
1281 $obj_data =& $ilias->obj_factory->getInstanceByRefId($rolf[
"ref_id"]);
1282 $obj_data->delete();
1285 $this->
writeScanLogLine(
"Removed invalid rolefolder '".$rolf[
"title"].
"' (id=".$rolf[
"obj_id"].
",ref=".$rolf[
"ref_id"].
") from system");
1303 global $ilias,$rbacadmin,
$ilLog;
1306 if ($this->mode[
"restore"] !==
true)
1313 if ($a_missing_objects === NULL and isset($this->missing_objects))
1319 if (!is_array($a_missing_objects))
1321 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1326 if (count($a_missing_objects) == 0)
1338 $message =
sprintf(
'%s::restoreMissingObjects(): Started...',
1345 foreach ($a_missing_objects as $missing_obj)
1348 if ($missing_obj[
"ref_id"] === NULL)
1352 $this->
writeScanLogLine(
"Created missing reference '".$missing_obj[
"ref_id"].
"' for object '".$missing_obj[
"obj_id"].
"'");
1356 #if (!in_array($missing_obj["type"],$this->object_types_exclude))
1359 $rbacadmin->revokePermission($missing_obj[
"ref_id"]);
1360 $obj_data =& $ilias->obj_factory->getInstanceByRefId($missing_obj[
"ref_id"]);
1361 $obj_data->putInTree(RECOVERY_FOLDER_ID);
1362 $obj_data->setPermissions(RECOVERY_FOLDER_ID);
1366 $this->
writeScanLogLine(
"Restored object '".$missing_obj[
"title"].
"' (id=".$missing_obj[
"obj_id"].
",ref=".$missing_obj[
"ref_id"].
") in 'Restored objects folder'");
1389 if (empty($a_obj_id))
1391 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1395 $query =
"INSERT INTO object_reference (ref_id,obj_id) ".
1396 "VALUES (".$next_id =
$ilDB->nextId(
'object_reference').
",".$this->db->quote($a_obj_id,
'integer').
" )";
1399 $message =
sprintf(
'%s::restoreReference(): new reference %s for obj_id %s created',
1423 if ($this->mode[
"restore"] !==
true)
1430 if ($a_unbound_objects === NULL and isset($this->unbound_objects))
1436 if (!is_array($a_unbound_objects))
1438 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1442 $message =
sprintf(
'%s::restoreUnboundObjects(): Started...',
1464 if ($this->mode[
"restore_trash"] !==
true)
1471 if ($a_deleted_objects === NULL and isset($this->deleted_objects))
1477 if (!is_array($a_deleted_objects))
1479 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1483 $message =
sprintf(
'%s::restoreTrash(): Started...',
1492 $q =
"DELETE FROM tree WHERE tree!=1";
1493 $this->db->query($q);
1495 $message =
sprintf(
'%s::restoreTrash(): Removed all trees with tree id <> 1',
1515 global $tree,$rbacadmin,$ilias,
$ilLog;
1518 if (!is_array($a_nodes))
1520 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1525 if (count($a_nodes) == 0)
1531 $message =
sprintf(
'%s::restoreDeletedObjects()): Started...',
1538 foreach ($a_nodes as $key => $node)
1540 if ($node[
"type"] ==
"rolf")
1543 $tree->deleteTree($node);
1545 $obj_data =& $ilias->obj_factory->getInstanceByRefId($node[
"child"]);
1546 $obj_data->delete();
1547 unset($a_nodes[$key]);
1552 foreach ($a_nodes as $node)
1555 $tree->deleteTree($node);
1557 $rbacadmin->revokePermission($node[
"child"]);
1558 $obj_data =& $ilias->obj_factory->getInstanceByRefId($node[
"child"]);
1559 $obj_data->putInTree(RECOVERY_FOLDER_ID);
1560 $obj_data->setPermissions(RECOVERY_FOLDER_ID);
1576 global $tree,$rbacadmin,$ilias,
$ilLog;
1579 if (!is_array($a_nodes))
1581 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1586 if (count($a_nodes) == 0)
1596 $subnodes = array();
1599 $message =
sprintf(
'%s::restoreSubTrees(): Started...',
1604 foreach ($a_nodes as $node)
1607 $topnode = $tree->getNodeData($node[
"child"], $node[
'tree']);
1611 if ($topnode[
"type"] ==
"rolf")
1613 $rolfObj = $ilias->obj_factory->getInstanceByRefId($topnode[
"child"]);
1621 $subnodes[$node[
"child"]] = $tree->getSubtree($topnode);
1624 $tree->deleteTree($topnode);
1629 foreach ($subnodes as $key => $subnode)
1633 $rbacadmin->revokePermission($key);
1634 $obj_data =& $ilias->obj_factory->getInstanceByRefId($key);
1635 $obj_data->putInTree(RECOVERY_FOLDER_ID);
1636 $obj_data->setPermissions(RECOVERY_FOLDER_ID);
1641 array_shift($subnode);
1644 if (count($subnode) > 0)
1646 foreach ($subnode as $node)
1648 $rbacadmin->revokePermission($node[
"child"]);
1649 $obj_data =& $ilias->obj_factory->getInstanceByRefId($node[
"child"]);
1650 $obj_data->putInTree($node[
"parent"]);
1651 $obj_data->setPermissions($node[
"parent"]);
1679 if ($this->mode[
"purge_trash"] !==
true)
1686 if ($a_nodes === NULL and isset($this->deleted_objects))
1692 $message =
sprintf(
'%s::purgeTrash(): Started...',
1714 if ($this->mode[
"purge"] !==
true)
1721 if ($a_nodes === NULL and isset($this->unbound_objects))
1726 $message =
sprintf(
'%s::purgeUnboundObjects(): Started...',
1748 if ($this->mode[
"purge"] !==
true)
1755 if ($a_nodes === NULL and isset($this->missing_objects))
1760 $message =
sprintf(
'%s::purgeMissingObjects(): Started...',
1780 $count_limit = $ilias->account->getPref(
"systemcheck_count_limit");
1781 if (! is_numeric($count_limit) || $count_limit < 0)
1783 $count_limit = count($a_nodes);
1785 $timestamp_limit = time();
1786 $age_limit = $ilias->account->getPref(
"systemcheck_age_limit");
1787 if (is_numeric($age_limit) && $age_limit > 0)
1789 $timestamp_limit -= $age_limit * 60 * 60 * 24;
1791 $type_limit = $ilias->account->getPref(
"systemcheck_type_limit");
1794 $type_limit = trim($type_limit);
1795 if (strlen($type_limit) == 0)
1802 if (!is_array($a_nodes))
1804 $this->throwError(INVALID_PARAM, WARNING,
DEBUG);
1811 foreach ($a_nodes as $node)
1813 if ($type_limit && $node[
'type'] != $type_limit)
1816 $node[
'child'].
"\t\t".$node[
'type'].
"\t\t".$node[
'title']
1823 if ($count > $count_limit)
1825 $this->
writeScanLogLine(
"Stopped purging after ".($count - 1).
" objects, because count limit was reached: ".$count_limit);
1828 if ($node[
"deleted_timestamp"] > $timestamp_limit)
1830 $this->
writeScanLogLine(
"Stopped purging after ".($count - 1).
" objects, because timestamp limit was reached: ".
date(
"c", $timestamp_limit));
1834 $ref_id = ($node[
"child"]) ? $node[
"child"] : $node[
"ref_id"];
1835 $node_obj =& $ilias->obj_factory->getInstanceByRefId(
$ref_id,
false);
1837 if ($node_obj ===
false)
1839 $this->invalid_objects[] = $node;
1843 $message =
sprintf(
'%s::purgeObjects(): Removing object (id:%s ref:%s)',
1846 $node_obj->getId());
1849 $startTime = microtime(
true);
1850 $node_obj->delete();
1852 $endTime = microtime(
true);
1855 "\t".$node[
'type'].
"\t".round($endTime-$startTime,1).
"\t".$node[
'title']);
1881 $message =
sprintf(
'%s::initGapsInTree(): Started...',
1886 if ($this->mode[
"clean"] !==
true)
1892 $tree->renumber(ROOT_FOLDER_ID);
1910 $call_loc =
$error->backtrace[count(
$error->backtrace)-1];
1911 $num_args = count($call_loc[
"args"]);
1915 foreach ($call_loc[
"args"] as $arg)
1917 $type = gettype($arg);
1922 $value = strlen($arg);
1926 $value = count($arg);
1930 $value = get_class($arg);
1934 $value = ($arg) ?
"true" :
"false";
1942 $arg_list[] = array(
1944 "value" =>
"(".$value.
")"
1948 foreach ($arg_list as $arg)
1950 $arg_str .= implode(
"",$arg).
" ";
1954 $err_msg =
"<br/><b>".$error->getCode().
":</b> ".
$error->getMessage().
" in ".$call_loc[
"class"].$call_loc[
"type"].$call_loc[
"function"].
"()".
1955 "<br/>Called from: ".basename($call_loc[
"file"]).
" , line ".$call_loc[
"line"].
1956 "<br/>Passed parameters: [".$num_args.
"] ".$arg_str.
"<br/>";
1959 if (
$error->getUserInfo())
1961 printf(
"<br/>Parameter details:");
1963 var_dump($call_loc[
"args"]);
1967 if (
$error->getCode() == FATAL)
1980 foreach ($a_arr as $entry)
1982 $this->scan_log->write(implode(
"\t",$entry));
1993 $this->scan_log->write($a_msg);
2002 return is_file(CLIENT_DATA_DIR.
"/".$this->scan_log_file);
2010 @unlink(CLIENT_DATA_DIR.
"/".$this->scan_log_file);
2021 $scanfile =& file(CLIENT_DATA_DIR.
"/".$this->scan_log_file);
2034 $logs = array_keys($a_scan_log,$this->scan_log_separator.
"\n");
2036 if (count($logs) > 0)
2038 return array_slice($a_scan_log,array_pop($logs)+2);
2068 $q =
'SELECT child FROM tree GROUP BY child HAVING COUNT(*) > 1';
2069 $r = $this->db->query($q);
2070 $duplicateNodes = array();
2073 $duplicateNodes[] =
$row->child;
2077 $q =
"SELECT tree.*,ref.ref_id,dat.obj_id objobj_id,ref.obj_id refobj_id,ref.deleted,dat.* "
2079 .
"RIGHT JOIN object_reference ref ON tree.child = ref.ref_id "
2080 .
"RIGHT JOIN object_data dat ON ref.obj_id = dat.obj_id "
2082 .
"ORDER BY tree, lft, type, dat.title";
2083 $r = $this->db->query($q);
2087 .
'<td>tree, child, parent, lft, rgt, depth</td>'
2088 .
'<td>ref_id, ref.obj_id, deleted</td>'
2089 .
'<td>obj_id, type, owner, title</td>'
2098 $repository_tree_count = 0;
2099 $trash_trees_count = 0;
2100 $other_trees_count = 0;
2101 $not_in_tree_count = 0;
2104 $previousNumber = 0;
2111 if($this->workspace_object_ids &&
2112 in_array(
$row->objobj_id, $this->workspace_object_ids))
2118 if (is_null(
$row->child))
2120 switch (
$row->type) {
2134 if (is_null(
$row->ref_id)) {
2144 $isParentOkay =
false;
2147 $isDepthOkay =
false;
2161 $isParentOkay =
false;
2164 $isDepthOkay =
false;
2169 $not_in_tree_count++;
2174 .(($isRowOkay) ?
'' :
'<font color=#ff0000>')
2177 .(($isParentOkay) ?
'' :
'parent:<b>')
2179 .(($isParentOkay) ?
'' :
'</b>')
2181 .(($isLftOkay) ?
'' :
'lft:<b>')
2183 .(($isLftOkay) ?
'' :
'</b>')
2185 .(($isRgtOkay) ?
'' :
'rgt:<b>')
2187 .(($isRgtOkay) ?
'' :
'</b>')
2189 .(($isDepthOkay) ?
'' :
'depth:<b>')
2191 .(($isDepthOkay) ?
'' :
'</b>')
2192 .(($isRowOkay) ?
'' :
'</font>')
2194 .(($isRowOkay) ?
'' :
'<font color=#ff0000>')
2195 .(($isRefRefOkay && $isChildOkay) ?
'' :
'ref.ref_id:<b>')
2197 .(($isRefRefOkay && $isChildOkay) ?
'' :
'</b>')
2199 .(($isRefObjOkay) ?
'' :
'ref.obj_id:<b>')
2201 .(($isRefObjOkay) ?
'' :
'</b>')
2202 .(($isRowOkay) ?
'' :
'<font color=#ff0000>')
2203 .((
$row->deleted !=
null) ?
', '.$row->deleted :
'')
2205 .(($isRowOkay) ?
'' :
'<font color=#ff0000>')
2211 .(($isRowOkay) ?
'' :
' <b>*ERROR*</b><font color=#ff0000>')
2221 for ($i = 1; $i <
$row->depth; $i++)
2227 if (count($stack) == 0 || $stack[0]->tree !=
$row->tree)
2230 $previousNumber =
$row->lft - 1;
2236 while (count($stack) > 0 && $stack[count($stack) - 1]->rgt < $row->lft)
2238 $popped = array_pop($stack);
2241 $gap = $popped->rgt - $previousNumber - 1;
2245 for ($i = 1; $i < $popped->depth; $i++)
2247 $poppedIndent .=
". ";
2251 .
'<td colspan=2><div align="right">'
2252 .
'<font color=#00cc00>*gap* for '.($gap/2).
' nodes at end of </font>'
2255 .
'<font color=#00cc00>'
2257 .$popped->obj_id.
', '
2259 .$popped->login.
', '
2266 $previousNumber = $popped->rgt;
2275 $isChildOkay =
true;
2276 $isParentOkay =
true;
2279 $isDepthOkay =
true;
2282 if (count($stack) > 0)
2284 $parent = $stack[count($stack) - 1];
2285 if ($parent->depth + 1 !=
$row->depth)
2287 $isDepthOkay =
false;
2290 if ($parent->child !=
$row->parent)
2292 $isParentOkay =
false;
2295 if(
$GLOBALS[
'ilSetting']->
get(
'main_tree_impl',
'ns') ==
'ns')
2297 if ($parent->lft >=
$row->lft)
2302 if ($parent->rgt <=
$row->rgt)
2311 if(
$GLOBALS[
'ilSetting']->
get(
'main_tree_impl',
'ns') ==
'ns')
2320 if (in_array(
$row->child, $duplicateNodes))
2322 $isChildOkay =
false;
2327 $isRefRefOkay =
true;
2328 $isRefObjOkay =
true;
2329 if (
$row->ref_id ==
null)
2331 $isRefRefOkay =
false;
2334 if (
$row->obj_id ==
null)
2336 $isRefObjOkay =
false;
2347 if(
$GLOBALS[
'ilSetting']->
get(
'main_tree_impl',
'ns') ==
'ns')
2349 $gap =
$row->lft - $previousNumber - 1;
2350 $previousNumber =
$row->lft;
2355 .
'<td colspan=2><div align="right">'
2356 .
'<font color=#00cc00>*gap* for '.($gap/2).
' nodes between </font>'
2359 .
'<font color=#00cc00>siblings</font>'
2371 . (($isRowOkay) ?
'' :
'<font color=#ff0000>')
2373 .
$row->child .
', '
2374 . (($isParentOkay) ?
'' :
'parent:<b>')
2376 . (($isParentOkay) ?
'' :
'</b>')
2378 . (($isLftOkay) ?
'' :
'lft:<b>')
2380 . (($isLftOkay) ?
'' :
'</b>')
2382 . (($isRgtOkay) ?
'' :
'rgt:<b>')
2384 . (($isRgtOkay) ?
'' :
'</b>')
2386 . (($isDepthOkay) ?
'' :
'depth:<b>')
2388 . (($isDepthOkay) ?
'' :
'</b>')
2389 . (($isRowOkay) ?
'' :
'</font>')
2391 . (($isRowOkay) ?
'' :
'<font color=#ff0000>')
2392 . (($isRefRefOkay && $isChildOkay) ?
'' :
'ref.ref_id:<b>')
2394 . (($isRefRefOkay && $isChildOkay) ?
'' :
'</b>')
2396 . (($isRefObjOkay) ?
'' :
'ref.obj_id:<b>')
2398 . (($isRefObjOkay) ?
'' :
'</b>')
2399 . (($isRowOkay) ?
'' :
'<font color=#ff0000>')
2400 . ((
$row->tree < 0) ?
', ' .
$row->deleted :
'')
2402 . (($isRowOkay) ?
'' :
'<font color=#ff0000>')
2404 .
$row->obj_id .
', '
2406 .
$row->login .
', '
2408 . (($isRowOkay) ?
'' :
' <b>*ERROR*</b><font color=#ff0000>')
2420 if (
$row->tree == 1)
2422 $repository_tree_count++;
2424 else if (
$row->tree < 0)
2426 $trash_trees_count++;
2430 $other_trees_count++;
2436 while (count($stack) > 0)
2438 $popped = array_pop($stack);
2441 $gap = $popped->rgt - $previousNumber - 1;
2445 for ($i = 1; $i < $popped->depth; $i++)
2447 $poppedIndent .=
". ";
2451 .
'<td colspan=2><div align="right">'
2452 .
'<font color=#00cc00>*gap* for '.($gap/2).
' nodes at end of </font>'
2455 .
'<font color=#00cc00>'
2457 .$popped->obj_id.
', '
2459 .$popped->login.
', '
2466 $previousNumber = $popped->rgt;
2473 if ($error_count > 0)
2475 $this->
writeScanLogLine(
'<font color=#ff0000>'.$error_count.
' errors found while dumping tree.</font>');
2481 $this->
writeScanLogLine(
"$repository_tree_count nodes in repository tree");
2487 return $error_count;
2494 if(!is_array($this->media_pool_ids))
2496 $this->media_pool_ids = array();
2497 $query =
"SELECT child FROM mep_tree ";
2501 $this->media_pool_ids[] =
$row->child;
2505 return in_array($a_obj_id,$this->media_pool_ids) ? true :
false;
2524 return in_array(
$a_type,$this->object_types_exclude);
2531 if($this->workspace_object_ids ===
null)
2533 $this->workspace_object_ids = array();
2536 $set =
$ilDB->query(
"SELECT DISTINCT(obj_id) FROM object_reference_ws");
2539 $this->workspace_object_ids[] =
$row[
"obj_id"];
2543 $set =
$ilDB->query(
"SELECT id FROM usr_portfolio");
2546 $this->workspace_object_ids[] =
$row[
"id"];
2558 if(is_array($this->workspace_object_ids))
2560 foreach($a_data as $idx => $item)
2562 if(in_array($item[$a_index], $this->workspace_object_ids))
2564 unset($a_data[$idx]);
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
@classDescription Date and time handling
static _removeEntry($a_tree, $a_child, $a_db_table="tree")
STATIC METHOD Removes a single entry from a tree.
ILIAS Data Validator & Recovery Tool.
restoreUnboundObjects($a_unbound_objects=NULL)
Restore objects (and their subobjects) to RecoveryFolder that are valid but not linked correctly in t...
deleteScanLog()
Delete scan log.
findUnboundObjects()
Search database for all tree entries having no valid parent (=> no valid path to root node) and store...
__construct($a_log=false)
Constructor.
handleErr($error)
Callback function handles PEAR_error and outputs detailed infos about error TODO: implement that in g...
isExcludedFromRecovery($a_type, $a_obj_id)
Check if type is excluded from recovery.
restoreReference($a_obj_id)
restore a reference for an object Creates a new reference entry in DB table object_reference for $a_o...
getInvalidChilds()
Gets all tree entries without any link to a valid object.
getDeletedObjects()
Gets all object in trash.
getInvalidReferences()
Gets all reference entries that are not linked with a valid object id.
purgeTrash($a_nodes=NULL)
Removes all objects in trash from system.
writeScanLogArray($a_arr)
filterWorkspaceObjects(array &$a_data, $a_index="obj_id")
getInvalidRolefolders()
Gets invalid rolefolders (same as missing objects)
removeInvalidRolefolders($a_invalid_rolefolders=NULL)
Removes invalid rolefolders.
restoreTrash($a_deleted_objects=NULL)
Restore all objects in trash to RecoveryFolder NOTE: All objects will be restored to top of RecoveryF...
purgeObjects($a_nodes)
removes objects from system
removeInvalidChilds($a_invalid_childs=NULL)
Removes all tree entries without any link to a valid object.
checkTreeStructure($a_startnode=null)
restoreSubTrees($a_nodes)
Restore objects (and their subobjects) to RecoveryFolder.
purgeUnboundObjects($a_nodes=NULL)
Removes all invalid objects from system.
setModeDependencies()
Sets modes by considering mode dependencies; some modes require other modes to be activated.
getUnboundObjects()
Gets all tree entries having no valid parent (=> no valid path to root node) Returns an array with ch...
restoreDeletedObjects($a_nodes)
Restore deleted objects (and their subobjects) to RecoveryFolder.
isModeEnabled($a_mode)
Is a particular mode enabled?
get_last_scan($a_scan_log)
getPossibleModes()
get possible ilValidator modes @access public
findDeletedObjects()
Search database for all tree entries having no valid parent (=> no valid path to root node) and store...
hasScanLog()
Quickly determine if there is a scan log.
dumpTree()
Dumps the Tree structure into the scan log.
findInvalidChilds()
Search database for all tree entries without any link to a valid object and stores result in $this->i...
restoreMissingObjects($a_missing_objects=NULL)
Restores missing reference and/or tree entry for all objects found by this::getMissingObjects() Resto...
setMode($a_mode, $a_value)
set mode of ilValidator Usage: setMode("restore",true) => enable object restorey setMode("all",...
findMissingObjects()
Search database for all object entries with missing reference and/or tree entry and stores result in ...
findInvalidRBACEntries()
Search database for all role entries that are linked to invalid ref_ids.
purgeMissingObjects($a_nodes=NULL)
Removes all missing objects from system.
removeInvalidReferences($a_invalid_refs=NULL)
Removes all reference entries that are linked with invalid object IDs.
findInvalidReferences()
Search database for all reference entries that are not linked with a valid object id and stores resul...
findInvalidRolefolders()
Search database for all rolefolder object entries with missing reference entry.
validate()
Performs the validation for each enabled mode.
getMissingObjects()
Gets all object entries with missing reference and/or tree entry.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.