if (!$selectedNode->canMoveTo($classID)) { eZDebug::writeError("Cannot move node {$nodeID} as child of parent node {$selectedNodeID}, the current user does not have create permission for class ID {$classID}", 'content/action'); return $module->redirectToView('view', array('full', 2)); } // Check if we try to move the node as child of itself or one of its children if (in_array($node->attribute('node_id'), $selectedNode->pathArray())) { eZDebug::writeError("Cannot move node {$nodeID} as child of itself or one of its own children (node {$selectedNodeID}).", 'content/action'); return $module->redirectToView('view', array('full', $node->attribute('node_id'))); } } // move selected nodes, this should probably be inside a transaction foreach ($nodeToMoveList as $nodeToMove) { if (eZOperationHandler::operationIsAvailable('content_move')) { $operationResult = eZOperationHandler::execute('content', 'move', array('node_id' => $nodeToMove['node_id'], 'object_id' => $nodeToMove['object_id'], 'new_parent_node_id' => $selectedNodeID), null, true); } else { eZContentOperationCollection::moveNode($nodeToMove['node_id'], $nodeToMove['object_id'], $selectedNodeID); } } return $module->redirectToView('view', array($viewMode, $selectedNodeID, $languageCode)); } else { if ($module->isCurrentAction('MoveNodeRequest')) { /* This action is started through the pop-up menu when a "Move" is * requested and through the use of the "Move" button. It will start the * browser to select where the node should be moved to. */ if (!$module->hasActionParameter('NodeID')) { eZDebug::writeError("Missing NodeID parameter for action " . $module->currentAction(), 'content/action'); return $module->redirectToView('view', array('full', 2)); } $nodeID = $module->actionParameter('NodeID'); $node = eZContentObjectTreeNode::fetch($nodeID); if (!$node) {
/** * Updates content object * * @param $params array( * 'object' => eZContentObject Content object * 'attributes' => array( Content object`s attributes * string identifier => string stringValue * ), * 'parentNode' => eZContentObjectTreeNode Parent node object, not necessary * 'parentNodeID' => int Content object`s parent node ID, not necessary * 'additionalParentNodeIDs' => array additionalParentNodeIDs, Additional parent node ids * 'visibility' => bool Nodes visibility * ) * @return bool true if object was updated, otherwise false */ public function updateObject($params) { $this->db->begin(); $object = $params['object']; if ($object instanceof eZContentObject === false) { $this->error('Content object is empty'); $this->db->rollback(); return false; } $this->debug('Starting update "' . $object->attribute('name') . '" object (class: ' . $object->attribute('class_name') . ') with remote ID ' . $object->attribute('remote_id')); $visibility = isset($params['visibility']) ? (bool) $params['visibility'] : true; $parentNode = false; if (isset($params['parentNode'])) { $parentNode = $params['parentNode']; } elseif (isset($params['parentNodeID'])) { $parentNode = eZContentObjectTreeNode::fetch($params['parentNodeID']); } if ($parentNode instanceof eZContentObjectTreeNode && $object->attribute('main_node') instanceof eZContentObjectTreeNode) { if ($parentNode->attribute('node_id') != $object->attribute('main_node')->attribute('parent_node_id')) { eZContentOperationCollection::moveNode($object->attribute('main_node_id'), $object->attribute('id'), $parentNode->attribute('node_id')); } } $additionalParentNodeIDs = isset($params['additionalParentNodeIDs']) ? (array) $params['additionalParentNodeIDs'] : array(); $additionalParentNodes = array(); foreach ($additionalParentNodeIDs as $nodeID) { $additionalParentNode = eZContentObjectTreeNode::fetch($nodeID); if ($additionalParentNode instanceof eZContentObjectTreeNode) { if ($parentNode instanceof eZContentObjectTreeNode && $nodeID != $parentNode->attribute('node_id')) { $additionalParentNodes[] = $additionalParentNode; } } else { $this->error('Can`t fetch additional parent node by ID: ' . $nodeID); } } if (count($additionalParentNodes) > 0) { $nodeAssigments = eZPersistentObject::fetchObjectList(eZNodeAssignment::definition(), null, array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'is_main' => 0), null, null, true); $removeNodeIDs = array(); foreach ($nodeAssigments as $assigment) { $node = $assigment->attribute('node'); if ($node instanceof eZContentObjectTreeNode) { if (in_array($node->attribute('parent_node_id'), $additionalParentNodeIDs) === false) { $removeNodeIDs[] = $node->attribute('node_id'); $assigment->purge(); } } } if (count($removeNodeIDs) > 0) { $info = eZContentObjectTreeNode::subtreeRemovalInformation($removeNodeIDs); foreach ($info['delete_list'] as $deleteItem) { $node = $deleteItem['node']; if ($node === null) { continue; } if ($deleteItem['can_remove']) { eZContentObjectTreeNode::removeSubtrees(array($node->attribute('node_id')), false); $this->debug('[Removed additional location] "' . $node->attribute('name') . '"', array('red')); } } } foreach ($additionalParentNodes as $node) { $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $node->attribute('node_id'), 'is_main' => 0)); $nodeAssignment->store(); } } $this->setObjectAttributes($object, $params['attributes']); $object->commitInputRelations($object->attribute('current_version')); $object->resetInputRelationList(); eZOperationHandler::execute('content', 'publish', array('object_id' => $object->attribute('id'), 'version' => $object->attribute('current_version'))); $this->db->commit(); $this->updateVisibility($object, $visibility); $this->debug('[Updated] "' . $object->attribute('name') . '"', array('yellow')); return true; }