/** * Remove objects from system */ function removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder = false) { global $lng; if (!is_array($a_ref_ids) || count($a_ref_ids) == 0) { ilUtil::sendFailure($lng->txt("no_checkbox"), true); return false; } else { include_once "./Services/Repository/classes/class.ilRepUtil.php"; try { ilRepUtil::removeObjectsFromSystem($a_ref_ids, $a_from_recovery_folder); ilUtil::sendSuccess($lng->txt("msg_removed"), true); } catch (Exception $e) { ilUtil::sendFailure($e->getMessage(), true); return false; } } return true; }
/** * Delete objects. Move them to trash (if trash feature is enabled). * * @param integer current ref id * @param array array of ref(!) ids to be deleted */ public static function deleteObjects($a_cur_ref_id, $a_ids) { global $ilAppEventHandler, $rbacsystem, $rbacadmin, $log, $ilUser, $tree, $lng, $ilSetting; include_once './Services/Payment/classes/class.ilPaymentObject.php'; include_once "./Services/Repository/exceptions/class.ilRepositoryException.php"; // Remove duplicate ids from array $a_ids = array_unique((array) $a_ids); // FOR ALL SELECTED OBJECTS foreach ($a_ids as $id) { if ($tree->isDeleted($id)) { $log->write(__METHOD__ . ': Object with ref_id: ' . $id . ' already deleted.'); throw new ilRepositoryException($lng->txt("msg_obj_already_deleted")); } // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES $node_data = $tree->getNodeData($id); $subtree_nodes = $tree->getSubTree($node_data); $all_node_data[] = $node_data; $all_subtree_nodes[] = $subtree_nodes; // CHECK DELETE PERMISSION OF ALL OBJECTS foreach ($subtree_nodes as $node) { if ($node['type'] == 'rolf') { continue; } if (!$rbacsystem->checkAccess('delete', $node["child"])) { $not_deletable[] = $node["child"]; $perform_delete = false; } else { if (ilPaymentObject::_isBuyable($node['child'])) { $buyable[] = $node['child']; $perform_delete = false; } } } } // IF THERE IS ANY OBJECT WITH NO PERMISSION TO DELETE if (count($not_deletable)) { $not_deletable = implode(',', $not_deletable); ilSession::clear("saved_post"); throw new ilRepositoryException($lng->txt("msg_no_perm_delete") . " " . $not_deletable . "<br/>" . $lng->txt("msg_cancel")); } if (count($buyable)) { foreach ($buyable as $id) { $tmp_object = ilObjectFactory::getInstanceByRefId($id); $titles[] = $tmp_object->getTitle(); } $title_str = implode(',', $titles); throw new ilRepositoryException($lng->txt('msg_obj_not_deletable_sold') . ' ' . $title_str); } // DELETE THEM if (!$all_node_data[0]["type"]) { // alex: this branch looks suspicious to me... I deactivate it for // now. Objects that aren't in the tree should overwrite this method. throw new ilRepositoryException($lng->txt("ilRepUtil::deleteObjects: Type information missing.")); // OBJECTS ARE NO 'TREE OBJECTS' if ($rbacsystem->checkAccess('delete', $a_cur_ref_id)) { foreach ($a_ids as $id) { $obj =& ilObjectFactory::getInstanceByObjId($id); $obj->delete(); // write log entry $log->write("ilObjectGUI::confirmedDeleteObject(), deleted obj_id " . $obj->getId() . ", type: " . $obj->getType() . ", title: " . $obj->getTitle()); } } else { throw new ilRepositoryException($lng->txt("no_perm_delete") . "<br/>" . $lng->txt("msg_cancel")); } } else { // SAVE SUBTREE AND DELETE SUBTREE FROM TREE $affected_ids = array(); foreach ($a_ids as $id) { if ($tree->isDeleted($id)) { $log->write(__METHOD__ . ': Object with ref_id: ' . $id . ' already deleted.'); throw new ilRepositoryException($lng->txt("msg_obj_already_deleted")); } // DELETE OLD PERMISSION ENTRIES $subnodes = $tree->getSubtree($tree->getNodeData($id)); foreach ($subnodes as $subnode) { $rbacadmin->revokePermission($subnode["child"]); // remove item from all user desktops $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]); $affected_ids[$subnode["child"]] = $subnode["child"]; // TODO: inform users by mail that object $id was deleted //$mail->sendMail($id,$msg,$affected_users); // should go to appevents at the end } // TODO: needs other handling // This class shouldn't have to know anything about ECS include_once './Services/WebServices/ECS/classes/class.ilECSObjectSettings.php'; ilECSObjectSettings::_handleDelete($subnodes); if (!$tree->saveSubTree($id, true)) { $log->write(__METHOD__ . ': Object with ref_id: ' . $id . ' already deleted.'); throw new ilRepositoryException($lng->txt("msg_obj_already_deleted")); } // write log entry $log->write("ilObjectGUI::confirmedDeleteObject(), moved ref_id " . $id . " to trash"); // remove item from all user desktops $affected_users = ilUtil::removeItemFromDesktops($id); $affected_ids[$id] = $id; // TODO: inform users by mail that object $id was deleted //$mail->sendMail($id,$msg,$affected_users); } // send global events foreach ($affected_ids as $aid) { $ilAppEventHandler->raise("Services/Object", "toTrash", array("obj_id" => ilObject::_lookupObjId($aid), "ref_id" => $aid)); } // inform other objects in hierarchy about paste operation //$this->object->notify("confirmedDelete", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$_SESSION["saved_post"]); } if (!$ilSetting->get('enable_trash')) { ilRepUtil::removeObjectsFromSystem($a_ids); } }