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();
     $userClassIDArray = eZUser::contentClassIDs();
     foreach ($deleteIDArray as $deleteID) {
         $node = eZContentObjectTreeNodeNoLanguage::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) {
             $isUserClass = in_array($class->attribute('id'), $userClassIDArray);
             if ($moveToTrashAllowed and $isUserClass) {
                 $moveToTrashAllowed = false;
             }
             $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) {
                         $childObject = $child->attribute('object');
                         $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' => eZContentObjectTreeNodeNoLanguage::reverseRelatedCount($deleteIDArray));
 }