/**
  * Moves a node
  *
  * @param int $nodeID
  * @param int $objectID
  * @param int $newParentNodeID
  *
  * @return array An array with operation status, always true
  */
 public static function moveNode($nodeID, $objectID, $newParentNodeID)
 {
     if (!eZContentObjectTreeNodeOperations::move($nodeID, $newParentNodeID)) {
         eZDebug::writeError("Failed to move node {$nodeID} as child of parent node {$newParentNodeID}", __METHOD__);
         return array('status' => false);
     }
     eZContentObject::fixReverseRelations($objectID, 'move');
     return array('status' => true);
 }
Ejemplo n.º 2
0
    function moveTreeNode( $params )
    {
        $nodeID = $this->nodeIdByName( $params['node'] );
        $parentNodeID = $this->nodeIdByName( $params['parent_node'] );

        $result = eZContentObjectTreeNodeOperations::move( $nodeID, $parentNodeID );

        return $result;
    }
 /**
  * Moves the node specified by the path $source to $destination.
  *
  * @param string $sourceSite Eg. 'plain_site_user'
  * @param string $destinationSite Eg. 'plain_site_user'
  * @param string $sourceVFolder Eg. 'Content'
  * @param string $destinationVFolder Eg. 'Content'
  * @param string $source Eg. 'Folder1/file1.txt'
  * @param string $destination Eg. 'Folder2/file1.txt'
  * @return bool
  */
 protected function moveContent($sourceSite, $destinationSite, $sourceVFolder, $destinationVFolder, $source, $destination, $fullSource, $fullDestination)
 {
     $nodePath = $this->internalNodePath($sourceVFolder, $source);
     $destinationNodePath = $this->internalNodePath($destinationVFolder, $destination);
     // Get rid of possible extensions, remove .jpeg .txt .html etc..
     $source = $this->fileBasename($source);
     $sourceNode = $this->fetchNodeByTranslation($nodePath);
     if (!$sourceNode) {
         return false;
         // @as self::FAILED_NOT_FOUND;
     }
     // Can we move the node from $sourceNode
     if (!$sourceNode->canMoveFrom()) {
         $this->appendLogEntry("No access to move the node '{$sourceSite}':'{$nodePath}'", 'CS:moveContent');
         return false;
         // @as self::FAILED_FORBIDDEN;
     }
     $object = $sourceNode->attribute('object');
     $classID = $object->attribute('contentclass_id');
     // Get rid of possible extensions, remove .jpeg .txt .html etc..
     $destination = $this->fileBasename($destination);
     $destinationNode = $this->fetchNodeByTranslation($destinationNodePath);
     $this->appendLogEntry("Destination: {$destinationNodePath}", 'CS:moveContent');
     if ($destinationNode) {
         return false;
         // @as self::FAILED_EXISTS;
     }
     $destinationNode = $this->fetchParentNodeByTranslation($destinationNodePath);
     // Can we move the node to $destinationNode
     if (!$destinationNode->canMoveTo($classID)) {
         $this->appendLogEntry("No access to move the node '{$sourceSite}':'{$nodePath}' to '{$destinationSite}':'{$destinationNodePath}'", 'CS:moveContent');
         return false;
         // @as self::FAILED_FORBIDDEN;
     }
     $srcParentPath = $this->splitLastPathElement($nodePath, $srcNodeName);
     $dstParentPath = $this->splitLastPathElement($destinationNodePath, $dstNodeName);
     if ($srcParentPath == $dstParentPath) {
         // @as 2009-03-02 - removed urldecode of name before renaming
         $dstNodeName = $this->fileBasename($dstNodeName);
         if (!$object->rename($dstNodeName)) {
             $this->appendLogEntry("Unable to rename the node '{$sourceSite}':'{$nodePath}' to '{$destinationSite}':'{$destinationNodePath}'", 'CS:moveContent');
             return false;
             // @as self::FAILED_FORBIDDEN;
         }
     } else {
         if (!eZContentObjectTreeNodeOperations::move($sourceNode->attribute('node_id'), $destinationNode->attribute('node_id'))) {
             $this->appendLogEntry("Unable to move the node '{$sourceSite}':'{$nodePath}' to '{$destinationSite}':'{$destinationNodePath}'", 'CS:moveContent');
             return false;
             // @as self::FAILED_FORBIDDEN;
         }
     }
     /*
     
     // Todo: add lookup of the name setting for the current object
                 $contentObjectID = $object->attribute( 'id' );
                 $contentObjectAttributes =& $object->contentObjectAttributes();
                 $contentObjectAttributes[0]->setAttribute( 'data_text', basename( $destination ) );
                 $contentObjectAttributes[0]->store();
     
                 $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID, 'version' => 1 ) );
                 $object->store();
     */
     return true;
     // @as self::OK_CREATED;
 }
Ejemplo n.º 4
0
function moveNode($node, $new_parent_node_id)
{
    $node_id = $node->attribute('node_id');
    $class_id = $node->attribute('class_identifier');
    if (!$node->canMoveFrom()) {
        eZDebug::writeError("Missing permissions to move node with id {$node_id}", 'batchtool/move');
        return false;
    }
    $new_parent_node = eZContentObjectTreeNode::fetch($new_parent_node_id);
    if (!$new_parent_node) {
        eZDebug::writeError("Can't fetch new parent {$new_parent_node_id} for node with id {$node_id}", 'batchtool/move');
        return false;
    }
    if (!$new_parent_node->canMoveTo($class_id)) {
        eZDebug::writeError("Missing permissions to move node with id {$node_id} to {$new_parent_node_id}", 'batchtool/move');
        return false;
    }
    if (in_array($node->attribute('node_id'), $new_parent_node->pathArray())) {
        eZDebug::writeError("Can't move node with id {$node_id} to itself", 'batchtool/move');
        return false;
    }
    $parent_id_array = $node->attribute('object')->attribute('parent_nodes');
    if (in_array($new_parent_node_id, $parent_id_array)) {
        eZDebug::writeError("A node of this object with object id " . $node->attribute('ezcontentobject_id') . " already exist under new parent node with node id {$new_parent_node_id}", 'batchtool/move');
        return false;
    }
    return eZContentObjectTreeNodeOperations::move($node_id, $new_parent_node_id);
}
Ejemplo n.º 5
0
 /**
  * Moves the node to a new location
  *
  * This method can only be called after the object which this node belongs
  * to has been published. No node exists before after publishing.
  *
  * @param int $newParentNodeID
  * @return void
  */
 function move($newParentNodeID)
 {
     return eZContentObjectTreeNodeOperations::move($this->node_id, $newParentNodeID);
 }
Ejemplo n.º 6
0
function moveNode($node, $new_parent_node_id)
{
    $node_id = $node->attribute('node_id');
    $class_id = $node->attribute('class_identifier');
    if (!$node->canMoveFrom()) {
        eZDebug::writeError("Missing permissions to move node with id {$node_id}", 'batchtool/move');
        return false;
    }
    $new_parent_node = eZContentObjectTreeNode::fetch($new_parent_node_id);
    if (!$new_parent_node) {
        eZDebug::writeError("Can't fetch new parent {$new_parent_node_id} for node with id {$node_id}", 'batchtool/move');
        return false;
    }
    if (!$new_parent_node->canMoveTo($class_id)) {
        eZDebug::writeError("Missing permissions to move node with id {$node_id} to {$new_parent_node_id}", 'batchtool/move');
        return false;
    }
    if (in_array($node->attribute('node_id'), $new_parent_node->pathArray())) {
        eZDebug::writeError("Can't move node with id {$node_id} to itself", 'batchtool/move');
        return false;
    }
    return eZContentObjectTreeNodeOperations::move($node_id, $new_parent_node_id);
}
Ejemplo n.º 7
0
function merge_ContentActionHandler(&$module, &$http, &$objectID)
{
    $selected_array = array();
    $merge_node_master = 0;
    $translation_map = array();
    if ($http->hasSessionVariable('MergeNodeSelectionList')) {
        $selected_array = $http->sessionVariable('MergeNodeSelectionList');
    }
    if ($http->hasSessionVariable('MergeNodeMaster')) {
        $merge_node_master = $http->sessionVariable('MergeNodeMaster');
    }
    if ($http->hasSessionVariable('MergeObjectTranslationMap')) {
        $translation_map = $http->sessionVariable('MergeObjectTranslationMap');
    }
    // Update master node
    if ($http->hasPostVariable('MergeNodeMaster')) {
        if ($merge_node_master != $http->postVariable('MergeNodeMaster')) {
            $merge_node_master = $http->postVariable('MergeNodeMaster');
            $http->setSessionVariable('MergeNodeMaster', $merge_node_master);
        }
        // Update translation map
        $count = 0;
        while ($http->hasPostVariable('MergeTranslation_' . $count)) {
            $values = explode('_', $http->postVariable('MergeTranslation_' . $count));
            $translation_map[$values[0]] = $values[1];
            $count++;
        }
        $http->setSessionVariable('MergeObjectTranslationMap', $translation_map);
    }
    // Remove selected nodes
    if ($http->hasPostVariable('RemoveObjects')) {
        $remove_list = array();
        if ($http->hasPostVariable('RemoveNode')) {
            $remove_list = $http->postVariable('RemoveNode');
            $selected_array = array_values(array_diff($selected_array, $remove_list));
            $http->setSessionVariable('MergeNodeSelectionList', $selected_array);
            // Check master node
            if (!in_array($merge_node_master, $selected_array)) {
                $merge_node_master = 0;
                $http->setSessionVariable('MergeNodeMaster', 0);
            }
            // Remove any related selected translations
            $update_translation_map = false;
            foreach ($translation_map as $language => $node_id) {
                if (in_array($node_id, $remove_list)) {
                    unset($translation_map[$language]);
                    $update_translation_map = true;
                }
            }
            if ($update_translation_map) {
                $http->setSessionVariable('MergeObjectTranslationMap', $translation_map);
            }
        }
        $module->redirectTo('/merge/select');
    }
    // Go to browse module to choose nodes to merge
    if ($http->hasPostVariable('MergeBrowse')) {
        $ini = eZINI::instance('merge.ini');
        $class_list = $ini->variable('MergeSettings', 'ClassList');
        $start_node_id = $ini->variable('MergeSettings', 'BrowseNodeID');
        eZContentBrowse::browse(array('action_name' => 'MergeObjects', 'description_template' => 'design:content/browse_placement.tpl', 'ignore_nodes_select' => $selected_array, 'ignore_nodes_click' => array(), 'selection' => 'radio', 'class_array' => $class_list, 'start_node' => $start_node_id, 'from_page' => '/merge/select'), $module);
    }
    // Actual merge operation
    if ($http->hasPostVariable('MergeAction')) {
        if (count($selected_array) != 2) {
            $module->redirectTo('/merge/select');
        }
        // Set up correct order according to selected master
        if ($selected_array[1] == $merge_node_master) {
            $selected_array = array_reverse($selected_array);
        }
        // Fetch objects to merge
        $mnode1 = eZFunctionHandler::execute('content', 'node', array('node_id' => $selected_array[0]));
        $mnode2 = eZFunctionHandler::execute('content', 'node', array('node_id' => $selected_array[1]));
        $mobject1 = $mnode1->attribute('object');
        $mobject2 = $mnode2->attribute('object');
        // Do sanity check
        if ($mobject1->attribute('contentclass_id') != $mobject2->attribute('contentclass_id')) {
            $module->redirectTo('/merge/select');
        }
        $db = eZDB::instance();
        $db->begin();
        foreach ($translation_map as $language => $node_id) {
            $object1 = $object2 = null;
            $node1 = eZFunctionHandler::execute('content', 'node', array('node_id' => $selected_array[0], 'language_code' => $language));
            $node2 = eZFunctionHandler::execute('content', 'node', array('node_id' => $selected_array[1], 'language_code' => $language));
            // Make sure we get correct language
            if ($node1) {
                $object1 = $node1->attribute('object');
                if (!in_array($language, $object1->attribute('available_languages'))) {
                    $object1 = $mobject1;
                }
            } else {
                $object1 = $mobject1;
            }
            $object2 = null;
            if ($node2) {
                $object2 = $node2->attribute('object');
                if (!in_array($language, $object2->attribute('available_languages'))) {
                    $object2 = null;
                }
            }
            // Copy language in specified direction, if it exist in both objects
            $use_object1_values = $node_id == $selected_array[0];
            if ($object1 and $object2) {
                doContentObjectMerge($object1, $object2, $language, $use_object1_values);
            }
        }
        $main_node_id1 = $mobject1->attribute('main_node_id');
        foreach ($mobject2->attribute('assigned_nodes') as $node2) {
            // Move any children of object2 nodes to object1 main node
            $children2 = eZFunctionHandler::execute('content', 'list', array('parent_node_id' => $node2->attribute('node_id')));
            foreach ($children2 as $child2) {
                eZContentObjectTreeNodeOperations::move($child2->attribute('node_id'), $main_node_id1);
            }
            // Tentative solution to add a history url redirect from object2 nodes to the object1 main node.
            // Uncertain if this is the correct way to do this.
            /*            $urlalias_list = eZURLAliasML::fetchByAction( 'eznode', $node2->attribute( 'node_id' ) );
                        foreach ( $urlalias_list as $url_alias )
                        {
                            $url_alias->setAttribute( 'action', 'eznode:' . $main_node_id1 );
                            $url_alias->setAttribute( 'is_original', 0 );
                            $url_alias->store();
                        }*/
        }
        // Delete object2
        $mobject2->purge();
        $db->commit();
        //        $db->rollback(); // For debugging
        // Clean up session variables
        $http->removeSessionVariable('MergeNodeSelectionList');
        $http->removeSessionVariable('MergeNodeMaster');
        $http->removeSessionVariable('MergeObjectTranslationMap');
        $module->redirectTo($mnode1->attribute('url_alias'));
    }
}
 /**
  * Workflow Event Type execute method
  */
 function execute($process, $event)
 {
     /**
      * Fetch workflow process parameters
      */
     $parameters = $process->attribute('parameter_list');
     $objectID = $parameters['object_id'];
     self::writeDebug('writeNotice', "Start '" . self::WORKFLOW_TYPE_STRING . "' workflow event execute method");
     $ini = eZINI::instance('site.ini');
     $bcUserRegisterUserPlacementINI = eZINI::instance('bcuserregisteruserplacement.ini');
     /**
      * Reading the default user class id as it is required to check that we only
      * perform the workflow event on user class content and not other class of objects
      */
     $defaultUserClassID = $ini->hasVariable('UserSettings', 'UserClassID') == true ? $ini->variable('UserSettings', 'UserClassID') : false;
     /**
      * Reading the default user placement nodeID as it is the default location where new users are stored
      */
     $userGroupID = $ini->hasVariable('UserSettings', 'DefaultUserPlacement') == true ? $ini->variable('UserSettings', 'DefaultUserPlacement') : 0;
     self::writeDebug('writeNotice', "User class id is: " . $defaultUserClassID . ' Default user group is: ' . $userGroupID);
     $userGroups = $bcUserRegisterUserPlacementINI->hasVariable('BCUserRegisterUserPlacement', 'MoveToUserGroupId') == true ? $bcUserRegisterUserPlacementINI->variable('BCUserRegisterUserPlacement', 'MoveToUserGroupId') : array();
     $objectSelectionAttributeIdentifier = $bcUserRegisterUserPlacementINI->hasVariable('BCUserRegisterUserPlacement', 'UserAttributeSelectionIdentifier') == true ? $bcUserRegisterUserPlacementINI->variable('BCUserRegisterUserPlacement', 'UserAttributeSelectionIdentifier') : false;
     $move = $bcUserRegisterUserPlacementINI->hasVariable('BCUserRegisterUserPlacement', 'Move') == true && strtolower($bcUserRegisterUserPlacementINI->variable('BCUserRegisterUserPlacement', 'Move')) == 'enabled' ? true : false;
     $setMainNode = $bcUserRegisterUserPlacementINI->hasVariable('BCUserRegisterUserPlacement', 'SetMainNode') == true && strtolower($bcUserRegisterUserPlacementINI->variable('BCUserRegisterUserPlacement', 'SetMainNode')) == 'enabled' ? true : false;
     $selectedNodeID = false;
     // Fetch content object from the workflow process provided object_id
     $object = eZContentObject::fetch($objectID);
     // Fetch content object attributes required
     $objectName = $object->attribute('name');
     self::writeDebug('writeNotice', "Object name: " . $objectName);
     $objectContentClass = $object->attribute('class_name');
     self::writeDebug('writeNotice', "Content Class is: " . $objectContentClass);
     $objectContentClassID = $object->attribute('contentclass_id');
     self::writeDebug('writeNotice', "Default user class id is: " . $defaultUserClassID . ". This object class id is: " . $objectContentClassID);
     /**
      * Test if content object class ID matches ini settings default user content object class ID
      * Only perform workflow event operations on content objects of the correct content class
      */
     if ($objectContentClassID == $defaultUserClassID) {
         // Fetch content object attributes needed
         $assignedNodes = $object->attribute('assigned_nodes');
         $objectDataMap = $object->attribute('data_map');
         $objectNodeAssignments = eZNodeAssignment::fetchForObject($objectID, $object->attribute('current_version'), 0, false);
         //$objectNodeAssignments = $object->attribute( 'assigned_nodes' );
         // Get the selection content
         $objectSelectionAttributeContent = $objectDataMap[$objectSelectionAttributeIdentifier]->attribute('content');
         $objectSelectionAttributeContentString = implode(',', $objectSelectionAttributeContent);
         self::writeDebug('writeNotice', "User object attribute " . $objectSelectionAttributeIdentifier . " content is set to: " . $objectSelectionAttributeContentString);
         /**
          * Test to ensure that object selection attribute content is greater than 0 (no selection) or
          * that object selection attribute count is less than the count of userGroups (defined in ini settings)
          */
         if ($objectSelectionAttributeContent > 0 || $objectSelectionAttributeContent < count($userGroups)) {
             // Set userGroupID from ini defined user groups based on content object selection attribute content
             $userGroupID = $userGroups[$objectSelectionAttributeContentString];
             $selectedNodeID = $userGroupID;
         }
         $parentNodeIDs = array();
         $ourNode = false;
         /**
          * Iterate over object assigned nodes and object node assignements
          * test for parent node id matches and build array of parent_node_ids
          * test for user content object selection attribute content selected node id
          * and set node to move based on match
          */
         foreach ($assignedNodes as $assignedNode) {
             $append = false;
             foreach ($objectNodeAssignments as $nodeAssignment) {
                 if ($nodeAssignment['parent_node'] == $assignedNode->attribute('parent_node_id')) {
                     $append = true;
                     break;
                 }
             }
             if ($append) {
                 $parentNodeIDs[] = $assignedNode->attribute('parent_node_id');
             }
             if ($assignedNode->attribute('parent_node_id') == $selectedNodeID) {
                 $ourNode = $assignedNode;
             }
         }
         /**
          * Test if we are to move the current main node to the selected location
          */
         if ($move) {
             self::writeDebug('writeDebug', 'Moving tactic');
             if (!is_object($ourNode)) {
                 self::writeDebug('writeDebug', 'Node not found, so moving existing main node...');
                 eZContentObjectTreeNodeOperations::move($object->attribute('main_node_id'), $selectedNodeID);
             }
         } else {
             /**
              * Create a new node location assignment
              */
             self::writeDebug('writeDebug', 'New node tactic');
             if (!is_object($ourNode)) {
                 self::writeDebug('writeDebug', 'Node not found, so creating a new one ...');
                 $parentNode = eZContentObjectTreeNode::fetch($selectedNodeID);
                 $parentNodeObject = $parentNode->attribute('object');
                 // Add user content object location
                 $ourNode = $object->addLocation($selectedNodeID, true);
                 // Now set node as published and fix main_node_id
                 $ourNode->setAttribute('contentobject_is_published', 1);
                 $ourNode->setAttribute('main_node_id', $object->attribute('main_node_id'));
                 $ourNode->setAttribute('contentobject_version', $object->attribute('current_version'));
                 // Make sure the node's path_identification_string is set correctly
                 $ourNode->updateSubTreePath();
                 $ourNode->sync();
                 eZUser::cleanupCache();
             }
             if ($setMainNode) {
                 self::writeDebug('writeDebug', "'Setting as main node is enabled'", "", true);
                 if ($object->attribute('main_node_id') != $ourNode->attribute('node_id')) {
                     self::writeDebug('writeDebug', 'Existing main node is not our node, so updating main node', "", true);
                     eZContentObjectTreeNode::updateMainNodeID($ourNode->attribute('node_id'), $objectID, false, $selectedNodeID);
                     eZContentCacheManager::clearContentCacheIfNeeded($objectID);
                 }
             }
         }
     } else {
         self::writeDebug('writeNotice', $objectName . ' is not a user class object');
     }
     if (self::WORKFLOW_TYPE_DEBUG_STOP_EXECUTION === true) {
         die("<hr />\n\nWorkflow: " . self::WORKFLOW_TYPE_STRING . " execution has been ended before normal completion for debugging");
     }
     /**
      * Return default succesful workflow event status code, by default, regardless of results of execution, always.
      * Image alias image variation image files may not always need to be created. Also returning any other status
      * will result in problems with the succesfull and normal completion of the workflow event process
      */
     return eZWorkflowType::STATUS_ACCEPTED;
 }
Ejemplo n.º 9
0
<?php

$return = false;
$newParentNodeId = (int) $_REQUEST['new_parent_node_id'];
$nodeId = (int) $_REQUEST['node_id'];
if ($newParentNodeId && $nodeId) {
    $return = eZContentObjectTreeNodeOperations::move($nodeId, $newParentNodeId);
}
header('Content-Type: application/json');
echo json_encode($return);
eZExecution::cleanExit();
Ejemplo n.º 10
0
Archivo: index.php Proyecto: truffo/eep
 private function move($nodeId, $parentNodeId)
 {
     if (!eepValidate::validateContentNodeId($nodeId)) {
         throw new Exception("This is not a node id: [" . $nodeId . "]");
     }
     if (!eepValidate::validateContentNodeId($parentNodeId)) {
         throw new Exception("This is not a node id: [" . $parentNodeId . "]");
     }
     eZContentObjectTreeNodeOperations::move($nodeId, $parentNodeId);
 }