eZContentOperationCollection::removeNodes PHP Method

removeNodes() public static method

This function does not check about permissions, this is the responsibility of the caller!
public static removeNodes ( array $removeNodeIdList ) : array
$removeNodeIdList array Array of Node ID to remove
return array An array with operation status, always true
    public static function removeNodes(array $removeNodeIdList)
    {
        $mainNodeChanged = array();
        $nodeAssignmentIdList = array();
        $objectIdList = array();
        $db = eZDB::instance();
        $db->begin();
        foreach ($removeNodeIdList as $nodeId) {
            $node = eZContentObjectTreeNode::fetch($nodeId);
            $objectId = $node->attribute('contentobject_id');
            foreach (eZNodeAssignment::fetchForObject($objectId, eZContentObject::fetch($objectId)->attribute('current_version'), 0, false) as $nodeAssignmentKey => $nodeAssignment) {
                if ($nodeAssignment['parent_node'] == $node->attribute('parent_node_id')) {
                    $nodeAssignmentIdList[$nodeAssignment['id']] = 1;
                }
            }
            if ($nodeId == $node->attribute('main_node_id')) {
                $mainNodeChanged[$objectId] = 1;
            }
            $node->removeThis();
            if (!isset($objectIdList[$objectId])) {
                $objectIdList[$objectId] = eZContentObject::fetch($objectId);
            }
        }
        eZNodeAssignment::purgeByID(array_keys($nodeAssignmentIdList));
        foreach (array_keys($mainNodeChanged) as $objectId) {
            $allNodes = $objectIdList[$objectId]->assignedNodes();
            // Registering node that will be promoted as 'main'
            if (isset($allNodes[0])) {
                $mainNodeChanged[$objectId] = $allNodes[0];
                eZContentObjectTreeNode::updateMainNodeID($allNodes[0]->attribute('node_id'), $objectId, false, $allNodes[0]->attribute('parent_node_id'));
            }
        }
        // Give other search engines that the default one a chance to reindex
        // when removing locations.
        if (!eZSearch::getEngine() instanceof eZSearchEngine) {
            foreach (array_keys($objectIdList) as $objectId) {
                eZContentOperationCollection::registerSearchObject($objectId);
            }
        }
        $db->commit();
        //call appropriate method from search engine
        eZSearch::removeNodes($removeNodeIdList);
        $userClassIdList = eZUser::contentClassIDs();
        foreach ($objectIdList as $objectId => $object) {
            eZContentCacheManager::clearObjectViewCacheIfNeeded($objectId);
            // clear user policy cache if this was a user object
            if (in_array($object->attribute('contentclass_id'), $userClassIdList)) {
                eZUser::purgeUserCacheByUserId($object->attribute('id'));
            }
        }
        // Triggering content/cache filter for Http cache purge
        ezpEvent::getInstance()->filter('content/cache', $removeNodeIdList);
        // we don't clear template block cache here since it's cleared in eZContentObjectTreeNode::removeNode()
        return array('status' => true);
    }

Usage Example

Esempio n. 1
0
             if ($count > 0) {
                 $hasChildren = true;
             }
         }
     }
     if ($hasChildren) {
         $http->setSessionVariable('CurrentViewMode', $viewMode);
         $http->setSessionVariable('DeleteIDArray', array_keys($removeList));
         $http->setSessionVariable('ContentNodeID', $nodeID);
         $http->setSessionVariable('ContentLanguage', $languageCode);
         return $module->redirectToView('removeobject');
     } else {
         if (eZOperationHandler::operationIsAvailable('content_removelocation')) {
             $operationResult = eZOperationHandler::execute('content', 'removelocation', array('node_list' => array_keys($removeList)), null, true);
         } else {
             eZContentOperationCollection::removeNodes(array_keys($removeList));
         }
     }
     return $module->redirectToView('view', array($viewMode, $redirectNodeID, $languageCode));
 } else {
     if ($http->hasPostVariable('EditButton')) {
         if ($http->hasPostVariable('ContentObjectID')) {
             $parameters = array($http->postVariable('ContentObjectID'));
             if ($http->hasPostVariable('ContentObjectVersion')) {
                 $parameters[] = $http->postVariable('ContentObjectVersion');
                 if ($http->hasPostVariable('ContentObjectLanguageCode')) {
                     $parameters[] = $http->postVariable('ContentObjectLanguageCode');
                 }
             } else {
                 if ($http->hasPostVariable('ContentObjectLanguageCode')) {
                     $languageCode = $http->postVariable('ContentObjectLanguageCode');
All Usage Examples Of eZContentOperationCollection::removeNodes