static function move($nodeID, $newParentNodeID)
 {
     $result = false;
     if (!is_numeric($nodeID) || !is_numeric($newParentNodeID)) {
         return false;
     }
     $node = eZContentObjectTreeNode::fetch($nodeID);
     if (!$node) {
         return false;
     }
     $object = $node->object();
     if (!$object) {
         return false;
     }
     $objectID = $object->attribute('id');
     $oldParentNode = $node->fetchParent();
     $oldParentObject = $oldParentNode->object();
     // clear user policy cache if this is a user object
     if (in_array($object->attribute('contentclass_id'), eZUser::contentClassIDs())) {
         eZUser::purgeUserCacheByUserId($object->attribute('id'));
     }
     // clear cache for old placement.
     // If child count exceeds threshold, do nothing here, and instead clear all view cache at the end.
     $childCountInThresholdRange = eZContentCache::inCleanupThresholdRange($node->childrenCount(false));
     if ($childCountInThresholdRange) {
         eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     }
     $db = eZDB::instance();
     $db->begin();
     $node->move($newParentNodeID);
     $newNode = eZContentObjectTreeNode::fetchNode($objectID, $newParentNodeID);
     if ($newNode) {
         $newNode->updateSubTreePath(true, true);
         if ($newNode->attribute('main_node_id') == $newNode->attribute('node_id')) {
             // If the main node is moved we need to check if the section ID must change
             $newParentNode = $newNode->fetchParent();
             $newParentObject = $newParentNode->object();
             if ($object->attribute('section_id') != $newParentObject->attribute('section_id')) {
                 eZContentObjectTreeNode::assignSectionToSubTree($newNode->attribute('main_node_id'), $newParentObject->attribute('section_id'), $oldParentObject->attribute('section_id'));
             }
         }
         // modify assignment
         $curVersion = $object->attribute('current_version');
         $nodeAssignment = eZNodeAssignment::fetch($objectID, $curVersion, $oldParentNode->attribute('node_id'));
         if ($nodeAssignment) {
             $nodeAssignment->setAttribute('parent_node', $newParentNodeID);
             $nodeAssignment->setAttribute('op_code', eZNodeAssignment::OP_CODE_MOVE);
             $nodeAssignment->store();
             // update search index specifying we are doing a move operation
             $nodeIDList = array($nodeID);
             eZSearch::removeNodeAssignment($node->attribute('main_node_id'), $newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList);
             eZSearch::addNodeAssignment($newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList, true);
         }
         $result = true;
     } else {
         eZDebug::writeError("Node {$nodeID} was moved to {$newParentNodeID} but fetching the new node failed");
     }
     $db->commit();
     // clear cache for new placement.
     // If child count exceeds threshold, clear all view cache instead.
     if ($childCountInThresholdRange) {
         eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     } else {
         eZContentCacheManager::clearAllContentCache();
     }
     return $result;
 }
 /**
  * Removes a nodeAssignment or a list of nodeAssigments
  *
  * @deprecated since 4.3
  *
  * @param int $nodeID
  * @param int $objectID
  * @param array $removeList
  * @param bool $moveToTrash
  *
  * @return array An array with operation status, always true
  */
 public static function removeAssignment($nodeID, $objectID, $removeList, $moveToTrash)
 {
     $mainNodeChanged = false;
     $nodeIDList = array();
     $mainNodeID = $nodeID;
     $userClassIDArray = eZUser::contentClassIDs();
     $object = eZContentObject::fetch($objectID);
     $nodeAssignmentIDList = array();
     $db = eZDB::instance();
     $db->begin();
     foreach ($removeList as $key => $node) {
         $removeObjectID = $node->attribute('contentobject_id');
         $removeObject = eZContentObject::fetch($removeObjectID);
         $nodeAssignmentList = eZNodeAssignment::fetchForObject($removeObjectID, $removeObject->attribute('current_version'), 0, false);
         foreach ($nodeAssignmentList as $nodeAssignmentKey => $nodeAssignment) {
             if ($nodeAssignment['parent_node'] == $node->attribute('parent_node_id')) {
                 $nodeAssignmentIDList[] = $nodeAssignment['id'];
                 unset($nodeAssignmentList[$nodeAssignmentKey]);
             }
         }
         if ($node->attribute('node_id') == $node->attribute('main_node_id')) {
             $mainNodeChanged = true;
         }
         $node->removeThis();
         $nodeIDList[] = $node->attribute('node_id');
     }
     eZNodeAssignment::purgeByID(array_unique($nodeAssignmentIDList));
     if ($mainNodeChanged) {
         $allNodes = $object->assignedNodes();
         $mainNode = $allNodes[0];
         $mainNodeID = $mainNode->attribute('node_id');
         eZContentObjectTreeNode::updateMainNodeID($mainNodeID, $objectID, false, $mainNode->attribute('parent_node_id'));
     }
     // Give other search engines that the default one a chance to reindex
     // when removing locations.
     if (!eZSearch::getEngine() instanceof eZSearchEngine) {
         eZContentOperationCollection::registerSearchObject($objectID);
     }
     $db->commit();
     //call appropriate method from search engine
     eZSearch::removeNodeAssignment($nodeID, $mainNodeID, $objectID, $nodeIDList);
     eZContentCacheManager::clearObjectViewCacheIfNeeded($objectID);
     // clear user policy cache if this was a user object
     if (in_array($object->attribute('contentclass_id'), $userClassIDArray)) {
         eZUser::purgeUserCacheByUserId($object->attribute('id'));
     }
     // we don't clear template block cache here since it's cleared in eZContentObjectTreeNode::removeNode()
     return array('status' => true);
 }
    static function move( $nodeID, $newParentNodeID )
    {
        $result = false;

        if ( !is_numeric( $nodeID ) || !is_numeric( $newParentNodeID ) )
            return false;

        $node = eZContentObjectTreeNode::fetch( $nodeID );
        if ( !$node )
            return false;

        $object = $node->object();
        if ( !$object )
            return false;

        $objectID = $object->attribute( 'id' );
        $oldParentNode = $node->fetchParent();
        $oldParentObject = $oldParentNode->object();

        // clear user policy cache if this is a user object
        if ( in_array( $object->attribute( 'contentclass_id' ), eZUser::contentClassIDs() ) )
        {
            eZUser::purgeUserCacheByUserId( $object->attribute( 'id' ) );
        }

        // clear cache for old placement.
        eZContentCacheManager::clearContentCacheIfNeeded( $objectID );

        $db = eZDB::instance();
        $db->begin();

        $node->move( $newParentNodeID );

        $newNode = eZContentObjectTreeNode::fetchNode( $objectID, $newParentNodeID );

        if ( $newNode )
        {
            $newNode->updateSubTreePath( true, true );
            if ( $newNode->attribute( 'main_node_id' ) == $newNode->attribute( 'node_id' ) )
            {
                // If the main node is moved we need to check if the section ID must change
                $newParentNode = $newNode->fetchParent();
                $newParentObject = $newParentNode->object();
                if ( $object->attribute( 'section_id' ) != $newParentObject->attribute( 'section_id' ) )
                {

                    eZContentObjectTreeNode::assignSectionToSubTree( $newNode->attribute( 'main_node_id' ),
                                                                     $newParentObject->attribute( 'section_id' ),
                                                                     $oldParentObject->attribute( 'section_id' ) );
                }
            }

            // modify assignment
            $curVersion     = $object->attribute( 'current_version' );
            $nodeAssignment = eZNodeAssignment::fetch( $objectID, $curVersion, $oldParentNode->attribute( 'node_id' ) );

            if ( $nodeAssignment )
            {
                $nodeAssignment->setAttribute( 'parent_node', $newParentNodeID );
                $nodeAssignment->setAttribute( 'op_code', eZNodeAssignment::OP_CODE_MOVE );
                $nodeAssignment->store();

                // update search index
                $nodeIDList = array( $nodeID );
                eZSearch::removeNodeAssignment( $node->attribute( 'main_node_id' ), $newNode->attribute( 'main_node_id' ), $object->attribute( 'id' ), $nodeIDList );
                eZSearch::addNodeAssignment( $newNode->attribute( 'main_node_id' ), $object->attribute( 'id' ), $nodeIDList );
            }

            $result = true;
        }
        else
        {
            eZDebug::writeError( "Node $nodeID was moved to $newParentNodeID but fetching the new node failed" );
        }

        $db->commit();

        // clear cache for new placement.
        eZContentCacheManager::clearContentCacheIfNeeded( $objectID );

        return $result;
    }