Ejemplo n.º 1
0
 /**
  * removes objects from system
  * 
  * @access	private
  * @param	array	list of objects
  * @return	boolean
  */
 function purgeObjects($a_nodes)
 {
     global $ilias, $ilLog;
     // Get purge limits
     $count_limit = $ilias->account->getPref("systemcheck_count_limit");
     if (!is_numeric($count_limit) || $count_limit < 0) {
         $count_limit = count($a_nodes);
     }
     $timestamp_limit = time();
     $age_limit = $ilias->account->getPref("systemcheck_age_limit");
     if (is_numeric($age_limit) && $age_limit > 0) {
         $timestamp_limit -= $age_limit * 60 * 60 * 24;
     }
     $type_limit = $ilias->account->getPref("systemcheck_type_limit");
     if ($type_limit) {
         $type_limit = trim($type_limit);
         if (strlen($type_limit) == 0) {
             $type_limit = null;
         }
     }
     // handle wrong input
     if (!is_array($a_nodes)) {
         $this->throwError(INVALID_PARAM, WARNING, DEBUG);
         return false;
     }
     // start delete process
     $this->writeScanLogLine("action\tref_id\tobj_id\ttype\telapsed\ttitle");
     $count = 0;
     foreach ($a_nodes as $node) {
         if ($type_limit && $node['type'] != $type_limit) {
             $this->writeScanLogLine("skip\t" . $node['child'] . "\t\t" . $node['type'] . "\t\t" . $node['title']);
             continue;
         }
         $count++;
         if ($count > $count_limit) {
             $this->writeScanLogLine("Stopped purging after " . ($count - 1) . " objects, because count limit was reached: " . $count_limit);
             break;
         }
         if ($node["deleted_timestamp"] > $timestamp_limit) {
             $this->writeScanLogLine("Stopped purging after " . ($count - 1) . " objects, because timestamp limit was reached: " . date("c", $timestamp_limit));
             continue;
         }
         $ref_id = $node["child"] ? $node["child"] : $node["ref_id"];
         $node_obj =& $ilias->obj_factory->getInstanceByRefId($ref_id, false);
         if ($node_obj === false) {
             $this->invalid_objects[] = $node;
             continue;
         }
         $message = sprintf('%s::purgeObjects(): Removing object (id:%s ref:%s)', get_class($this), $ref_id, $node_obj->getId());
         $ilLog->write($message, $ilLog->WARNING);
         $startTime = microtime(true);
         $node_obj->delete();
         ilTree::_removeEntry($node["tree"], $ref_id);
         $endTime = microtime(true);
         $this->writeScanLogLine("purged\t" . $ref_id . "\t" . $node_obj->getId() . "\t" . $node['type'] . "\t" . round($endTime - $startTime, 1) . "\t" . $node['title']);
     }
     $this->findInvalidChilds();
     $this->removeInvalidChilds();
     return true;
 }