private function fetchNodeInfoFromId($nodeId) { if (!eepValidate::validateContentNodeId($nodeId)) { throw new Exception("This is not a node id: [" . $nodeId . "]"); } $keepers = array("Name", "ContentObjectID", "MainNodeID", "ClassIdentifier", "PathIdentificationString", "PathString", "ParentNodeID", "CurrentLanguage", "ContentObjectVersion", "RemoteID", "IsHidden", "IsInvisible", "ContentObjectIsPublished"); // get the node $node = eZContentObjectTreeNode::fetch($nodeId); //var_dump($node); // extract the members we want $results[] = array("key", "value"); foreach ($keepers as $key) { $results[] = array($key, $node->{$key}); } // additional info $results[] = array("Reverse related count", eZContentObjectTreeNode::reverseRelatedCount(array($nodeId))); $params = array('Depth' => 1, 'DepthOperator' => 'eq', 'Limitation' => array()); $results[] = array("Children count", eZContentObjectTreeNode::subTreeCountByNodeID($params, $nodeId)); $results[] = array("URL Alias", $node->urlAlias()); // do output eep::printTable($results, "contentnode info [" . $nodeId . "]"); }
static function removeSubtrees($deleteIDArray, $moveToTrash = true, $infoOnly = false) { $moveToTrashAllowed = true; $deleteResult = array(); $totalChildCount = 0; $totalLoneNodeCount = 0; $canRemoveAll = true; $hasPendingObject = false; $db = eZDB::instance(); $db->begin(); foreach ($deleteIDArray as $deleteID) { $node = eZContentObjectTreeNode::fetch($deleteID); if ($node === null) { continue; } $object = $node->attribute('object'); if ($object === null) { continue; } $class = $object->attribute('content_class'); $canRemove = $node->attribute('can_remove'); $canRemoveSubtree = true; $nodeID = $node->attribute('node_id'); $nodeName = $object->attribute('name'); $childCount = 0; $newMainNodeID = false; $objectNodeCount = 0; $readableChildCount = 0; if ($canRemove) { $moveToTrashAllowed = $node->isNodeTrashAllowed(); $readableChildCount = $node->subTreeCount(array('Limitation' => array())); $childCount = $node->subTreeCount(array('IgnoreVisibility' => true)); $totalChildCount += $childCount; $allAssignedNodes = $object->attribute('assigned_nodes'); $objectNodeCount = count($allAssignedNodes); // We need to find a new main node ID if we are trying // to remove the current main node. if ($node->attribute('main_node_id') == $nodeID) { if (count($allAssignedNodes) > 1) { foreach ($allAssignedNodes as $assignedNode) { $assignedNodeID = $assignedNode->attribute('node_id'); if ($assignedNodeID == $nodeID) { continue; } $newMainNodeID = $assignedNodeID; break; } } } if ($infoOnly) { // Find the number of items in the subtree we are allowed to remove // if this differs from the total count it means we have items we cannot remove // We do this by fetching the limitation list for content/remove // and passing it to the subtree count function. $currentUser = eZUser::currentUser(); $accessResult = $currentUser->hasAccessTo('content', 'remove'); if ($accessResult['accessWord'] == 'limited') { $limitationList = $accessResult['policies']; $removeableChildCount = $node->subTreeCount(array('Limitation' => $limitationList, 'IgnoreVisibility' => true)); $canRemoveSubtree = $removeableChildCount == $childCount; $canRemove = $canRemoveSubtree; } //check if there is sub object in pending status $limitCount = 100; $offset = 0; while (1) { $children = $node->subTree(array('Limitation' => array(), 'SortBy' => array('path', false), 'Offset' => $offset, 'Limit' => $limitCount, 'IgnoreVisibility' => true, 'AsObject' => false)); // fetch pending node assignment(pending object) $idList = array(); //add node itself into idList if ($offset === 0) { $idList[] = $nodeID; } foreach ($children as $child) { $idList[] = $child['node_id']; } if (count($idList) === 0) { break; } $pendingChildCount = eZNodeAssignment::fetchChildCountByVersionStatus($idList, eZContentObjectVersion::STATUS_PENDING); if ($pendingChildCount !== 0) { // there is pending object $hasPendingObject = true; break; } $offset += $limitCount; } } // We will only remove the subtree if are allowed // and are told to do so. if ($canRemove and !$infoOnly) { $moveToTrashTemp = $moveToTrash; if (!$moveToTrashAllowed) { $moveToTrashTemp = false; } // Remove children, fetching them by 100 to avoid memory overflow. // removeNodeFromTree -> removeThis handles cache clearing while (1) { // We should remove the latest subitems first, // so we should fetch subitems sorted by 'path_string' DESC $children = $node->subTree(array('Limitation' => array(), 'SortBy' => array('path', false), 'Limit' => 100, 'IgnoreVisibility' => true)); if (!$children) { break; } foreach ($children as $child) { $child->removeNodeFromTree($moveToTrashTemp); eZContentObject::clearCache(); } } $node->removeNodeFromTree($moveToTrashTemp); } } if (!$canRemove) { $canRemoveAll = false; } // Do not create info list if we are removing subtrees if (!$infoOnly) { continue; } $soleNodeCount = $node->subtreeSoleNodeCount(); $totalLoneNodeCount += $soleNodeCount; if ($objectNodeCount <= 1) { ++$totalLoneNodeCount; } $item = array("nodeName" => $nodeName, "childCount" => $childCount, "additionalWarning" => '', 'node' => $node, 'object' => $object, 'class' => $class, 'node_name' => $nodeName, 'child_count' => $childCount, 'object_node_count' => $objectNodeCount, 'sole_node_count' => $soleNodeCount, 'can_remove' => $canRemove, 'can_remove_subtree' => $canRemoveSubtree, 'real_child_count' => $readableChildCount, 'new_main_node_id' => $newMainNodeID); $deleteResult[] = $item; } $db->commit(); if (!$infoOnly) { return true; } if ($moveToTrashAllowed and $totalLoneNodeCount == 0) { $moveToTrashAllowed = false; } return array('move_to_trash' => $moveToTrashAllowed, 'total_child_count' => $totalChildCount, 'can_remove_all' => $canRemoveAll, 'delete_list' => $deleteResult, 'has_pending_object' => $hasPendingObject, 'reverse_related_count' => eZContentObjectTreeNode::reverseRelatedCount($deleteIDArray)); }
/** * Checks if a node is an orphan * * An orphan node is a node without any reverse relations. (e.g no other * objects related to the node). * * @param eZContentObjectTreeNode $node * @return bool **/ protected function isNodeOrphan( $node ) { return ( eZContentObjectTreeNode::reverseRelatedCount( array( $node->attribute('node_id') ) ) <= 0 ); }