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; }
public static function publishNode($parentNodeID, $objectID, $versionNum, $mainNodeID) { $object = eZContentObject::fetch($objectID); $nodeAssignment = eZNodeAssignment::fetch($objectID, $versionNum, $parentNodeID); $version = $object->version($versionNum); $fromNodeID = $nodeAssignment->attribute('from_node_id'); $originalObjectID = $nodeAssignment->attribute('contentobject_id'); $nodeID = $nodeAssignment->attribute('parent_node'); $opCode = $nodeAssignment->attribute('op_code'); $parentNode = eZContentObjectTreeNode::fetch($nodeID); // if parent doesn't exist, return. See issue #18320 if (!$parentNode instanceof eZContentObjectTreeNode) { eZDebug::writeError("Parent node doesn't exist. object id: {$objectID}, node_assignment id: " . $nodeAssignment->attribute('id'), __METHOD__); return; } $parentNodeID = $parentNode->attribute('node_id'); $existingNode = null; $db = eZDB::instance(); $db->begin(); if (strlen($nodeAssignment->attribute('parent_remote_id')) > 0) { $existingNode = eZContentObjectTreeNode::fetchByRemoteID($nodeAssignment->attribute('parent_remote_id')); } if (!$existingNode) { } $existingNode = eZContentObjectTreeNode::findNode($nodeID, $object->attribute('id'), true); $updateSectionID = false; // now we check the op_code to see what to do if (($opCode & 1) == eZNodeAssignment::OP_CODE_NOP) { // There is nothing to do so just return $db->commit(); if ($mainNodeID == false) { return $object->attribute('main_node_id'); } return; } $updateFields = false; if ($opCode == eZNodeAssignment::OP_CODE_MOVE || $opCode == eZNodeAssignment::OP_CODE_CREATE) { // if ( $fromNodeID == 0 || $fromNodeID == -1) if ($opCode == eZNodeAssignment::OP_CODE_CREATE || $opCode == eZNodeAssignment::OP_CODE_SET) { // If the node already exists it means we have a conflict (for 'CREATE'). // We resolve this by leaving node-assignment data be. if ($existingNode == null) { $parentNode = eZContentObjectTreeNode::fetch($nodeID); $user = eZUser::currentUser(); if (!eZSys::isShellExecution() and !$user->isAnonymous()) { eZContentBrowseRecent::createNew($user->id(), $parentNode->attribute('node_id'), $parentNode->attribute('name')); } $updateFields = true; $existingNode = $parentNode->addChild($object->attribute('id'), true); if ($fromNodeID == -1) { $updateSectionID = true; } } elseif ($opCode == eZNodeAssignment::OP_CODE_SET) { $updateFields = true; } } elseif ($opCode == eZNodeAssignment::OP_CODE_MOVE) { if ($fromNodeID == 0 || $fromNodeID == -1) { eZDebug::writeError("NodeAssignment '" . $nodeAssignment->attribute('id') . "' is marked with op_code='{$opCode}' but has no data in from_node_id. Cannot use it for moving node.", __METHOD__); } else { // clear cache for old placement. $additionalNodeIDList = array($fromNodeID); eZContentCacheManager::clearContentCacheIfNeeded($objectID, $versionNum, $additionalNodeIDList); $originalNode = eZContentObjectTreeNode::fetchNode($originalObjectID, $fromNodeID); if ($originalNode->attribute('main_node_id') == $originalNode->attribute('node_id')) { $updateSectionID = true; } $originalNode->move($parentNodeID); $existingNode = eZContentObjectTreeNode::fetchNode($originalObjectID, $parentNodeID); $updateFields = true; } } } elseif ($opCode == eZNodeAssignment::OP_CODE_REMOVE) { $db->commit(); return; } if ($updateFields) { if (strlen($nodeAssignment->attribute('parent_remote_id')) > 0) { $existingNode->setAttribute('remote_id', $nodeAssignment->attribute('parent_remote_id')); } $existingNode->setAttribute('sort_field', $nodeAssignment->attribute('sort_field')); $existingNode->setAttribute('sort_order', $nodeAssignment->attribute('sort_order')); } $existingNode->setAttribute('contentobject_is_published', 1); eZDebug::createAccumulatorGroup('nice_urls_total', 'Nice urls'); if ($mainNodeID > 0) { $existingNodeID = $existingNode->attribute('node_id'); if ($existingNodeID != $mainNodeID) { eZContentBrowseRecent::updateNodeID($existingNodeID, $mainNodeID); } $existingNode->setAttribute('main_node_id', $mainNodeID); } else { $existingNode->setAttribute('main_node_id', $existingNode->attribute('node_id')); } $existingNode->store(); if ($updateSectionID) { eZContentOperationCollection::updateSectionID($objectID, $versionNum); } $db->commit(); if ($mainNodeID == false) { return $existingNode->attribute('node_id'); } }
function checkNodeActions( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage ) { // If the object has been previously published we do not allow node assignment operations if ( $object->attribute( 'status' ) != eZContentObject::STATUS_DRAFT ) { if ( !$module->isCurrentAction( 'BrowseForPrimaryNodes' ) ) { return; } } $http = eZHTTPTool::instance(); if ( $module->isCurrentAction( 'BrowseForNodes' ) || $module->isCurrentAction( 'BrowseForPrimaryNodes' ) ) { // Remove custom actions from attribute editing. $http->removeSessionVariable( 'BrowseCustomAction' ); $ignoreNodesSelect = array(); $ignoreNodesClick = array(); $assigned = $version->nodeAssignments(); $publishedAssigned = $object->assignedNodes( false ); $isTopLevel = false; foreach ( $publishedAssigned as $element ) { $append = false; if ( $element['parent_node_id'] == 1 ) $isTopLevel = true; foreach ( $assigned as $ass ) { if ( $ass->attribute( 'parent_node' ) == $element['parent_node_id'] ) $append = true; } /* If the current version (draft) has no assigned nodes then * we should disallow adding assignments under nodes * the previous published version is assignned to. * Thus we avoid fatal errors in eZ Publish. */ if ( count($assigned) == 0 ) { $ignoreNodesSelect[] = $element['node_id']; $ignoreNodesClick[] = $element['node_id']; } if ( $append ) { $ignoreNodesSelect[] = $element['node_id']; $ignoreNodesClick[] = $element['node_id']; $ignoreNodesSelect[] = $element['parent_node_id']; } } if ( !$isTopLevel ) { $ignoreNodesSelect = array_unique( $ignoreNodesSelect ); $objectID = $object->attribute( 'id' ); $action = 'AddNodeAssignment'; if ( $module->isCurrentAction( 'BrowseForPrimaryNodes' ) ) { $action = 'AddPrimaryNodeAssignment'; } eZContentBrowse::browse( array( 'action_name' => $action, 'description_template' => 'design:content/browse_placement.tpl', 'keys' => array( 'class' => $class->attribute( 'id' ), 'class_id' => $class->attribute( 'identifier' ), 'classgroup' => $class->attribute( 'ingroup_id_list' ), 'section' => $object->attribute( 'section_id' ) ), 'ignore_nodes_select' => $ignoreNodesSelect, 'ignore_nodes_click' => $ignoreNodesClick, 'content' => array( 'object_id' => $objectID, 'object_version' => $editVersion, 'object_language' => $editLanguage ), 'from_page' => "/content/edit/$objectID/$editVersion/$editLanguage/$fromLanguage" ), $module ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } // If node assignment handling is diabled we return $useNodeAssigments = true; if ( $http->hasPostVariable( 'UseNodeAssigments' ) ) $useNodeAssigments = (bool)$http->postVariable( 'UseNodeAssigments' ); if ( !$useNodeAssigments ) return; // Remove custom actions from attribute editing. $http->removeSessionVariable( 'BrowseCustomAction' ); if ( $module->isCurrentAction( 'ConfirmAssignmentDelete' ) && $http->hasPostVariable( 'RemoveNodeID' ) ) { $nodeID = $http->postVariable( 'RemoveNodeID' ); $db = eZDB::instance(); $db->begin(); $version->removeAssignment( $nodeID ); $db->commit(); } if ( $module->isCurrentAction( 'DeleteNode' ) ) { if ( $http->hasPostVariable( 'RemoveNodeID' ) ) { $nodeID = $http->postVariable( 'RemoveNodeID' ); } $mainNodeID = $http->postVariable( 'MainNodeID' ); // if ( $nodeID != $mainNodeID ) { $objectID = $object->attribute( 'id' ); $publishedNode = eZContentObjectTreeNode::fetchNode( $objectID, $nodeID ); if ( $publishedNode != null ) { $publishParentNodeID = $publishedNode->attribute( 'parent_node_id' ); if ( $publishParentNodeID > 1 ) { $childrenCount = $publishedNode->childrenCount(); if ( $childrenCount != 0 ) { $module->redirectToView( 'removenode', array( $objectID, $editVersion, $editLanguage, $nodeID ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } else { $db = eZDB::instance(); $db->begin(); $version->removeAssignment( $nodeID ); $db->commit(); } } } else { $nodeAssignment = eZNodeAssignment::fetch( $objectID, $version->attribute( 'version' ), $nodeID ); if ( $nodeAssignment->attribute( 'from_node_id' ) != 0 ) { $publishedNode = eZContentObjectTreeNode::fetchNode( $objectID, $nodeAssignment->attribute( 'from_node_id' ) ); $childrenCount = 0; if ( $publishedNode !== null ) $childrenCount = $publishedNode->childrenCount(); if ( $childrenCount != 0 ) { $module->redirectToView( 'removenode', array( $objectID, $editVersion, $editLanguage, $nodeID ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } $db = eZDB::instance(); $db->begin(); $version->removeAssignment( $nodeID ); $db->commit(); } } } if ( $module->isCurrentAction( 'RemoveAssignments' ) ) { if( $http->hasPostVariable( 'AssignmentIDSelection' ) ) { $selected = $http->postVariable( 'AssignmentIDSelection' ); $objectID = $object->attribute( 'id' ); $versionInt = $version->attribute( 'version' ); $hasChildren = false; $assignmentsIDs = array(); $assignments = array(); // Determine if at least one node of ones we remove assignments for has children. foreach ( $selected as $parentNodeID ) { $assignment = eZNodeAssignment::fetch( $objectID, $versionInt, $parentNodeID ); if( !$assignment ) { eZDebug::writeWarning( "No assignment found for object $objectID version $versionInt, parent node $parentNodeID" ); continue; } $assignmentID = $assignment->attribute( 'id' ); $assignmentsIDs[] = $assignmentID; $assignments[] = $assignment; $node = $assignment->attribute( 'node' ); if( !$node ) continue; if( $node->childrenCount( false ) > 0 ) $hasChildren = true; unset( $assignment ); } if ( $hasChildren ) { // We need user confirmation if at least one node we want to remove assignment for contains children. // Aactual removal is done in content/removeassignment in this case. $http->setSessionVariable( 'AssignmentRemoveData', array( 'remove_list' => $assignmentsIDs, 'object_id' => $objectID, 'edit_version' => $versionInt, 'edit_language' => $editLanguage, 'from_language' => $fromLanguage ) ); $module->redirectToView( 'removeassignment' ); return eZModule::HOOK_STATUS_CANCEL_RUN; } else { // Just remove all the selected locations. $mainNodeChanged = false; $db = eZDB::instance(); $db->begin(); foreach ( $assignments as $assignment ) { $assignmentID = $assignment->attribute( 'id' ); if ( $assignment->attribute( 'is_main' ) ) $mainNodeChanged = true; eZNodeAssignment::removeByID( $assignmentID ); } if ( $mainNodeChanged ) eZNodeAssignment::setNewMainAssignment( $objectID, $versionInt ); $db->commit(); unset( $mainNodeChanged ); } unset( $assignmentsIDs, $assignments ); } else { eZDebug::writeNotice( 'No nodes to remove selected' ); } } if ( $module->isCurrentAction( 'MoveNode' ) ) { $objectID = $object->attribute( 'id' ); if ( $http->hasPostVariable( 'MoveNodeID' ) ) { $fromNodeID = $http->postVariable( 'MoveNodeID' ); //$sourceNodeID[0]; $oldAssignmentParentID = $fromNodeID; $fromNodeAssignment = eZNodeAssignment::fetch( $objectID, $version->attribute( 'version' ), $fromNodeID ); $publishParentNodeID = $fromNodeAssignment->attribute( 'parent_node' ); if ( $publishParentNodeID > 1 ) { if( $fromNodeAssignment->attribute( 'from_node_id' ) != 0 ) { $fromNodeID = $fromNodeAssignment->attribute( 'from_node_id' ); $oldAssignmentParentID = $fromNodeAssignment->attribute( 'parent_node' ); } // we don't allow moving object to itself, to its descendants or parent object(s) $objectAssignedNodes = $object->attribute( 'assigned_nodes' ); // nodes that are not allowed to select (via checkbox or radiobutton) when browsing $ignoreNodesSelectArray = array(); // nodes that are not allowed to click on $ignoreNodesClickArray = array(); foreach( $objectAssignedNodes as $curAN ) { // current node should be neither selectable, nor clickable $ignoreNodesClickArray[] = $curAN->NodeID; $ignoreNodesSelectArray[] = $curAN->NodeID; // parent node should be only clickable, but not selectable $ignoreNodesSelectArray[] = $curAN->ParentNodeID; } eZContentBrowse::browse( array( 'action_name' => 'MoveNodeAssignment', 'description_template' => 'design:content/browse_move_placement.tpl', 'keys' => array( 'class' => $class->attribute( 'id' ), 'class_id' => $class->attribute( 'identifier' ), 'classgroup' => $class->attribute( 'ingroup_id_list' ), 'section' => $object->attribute( 'section_id' ) ), 'start_node' => $fromNodeID, 'persistent_data' => array( 'FromNodeID' => $fromNodeID, 'OldAssignmentParentID' => $oldAssignmentParentID ), 'ignore_nodes_select' => $ignoreNodesSelectArray, 'ignore_nodes_click' => $ignoreNodesClickArray, 'content' => array( 'object_id' => $objectID, 'previous_node_id' => $fromNodeID, 'object_version' => $editVersion, 'object_language' => $editLanguage ), 'from_page' => "/content/edit/$objectID/$editVersion/$editLanguage" ), $module ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } } }
function onPublish($contentObjectAttribute, $contentObject, $publishedNodes) { $content = $contentObjectAttribute->content(); foreach ($content['relation_list'] as $key => $relationItem) { if ($relationItem['is_modified']) { $subObjectID = $relationItem['contentobject_id']; $subObjectVersion = $relationItem['contentobject_version']; $object = eZContentObject::fetch($subObjectID); $time = time(); $version = eZContentObjectVersion::fetchVersion($subObjectVersion, $subObjectID); $version->setAttribute('modified', $time); $version->store(); if ($relationItem['parent_node_id'] > 0) { // action 1: edit a normal object if (!eZNodeAssignment::fetch($object->attribute('id'), $object->attribute('current_version'), $relationItem['parent_node_id'], false)) { $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $relationItem['parent_node_id'], 'sort_field' => eZContentObjectTreeNode::SORT_FIELD_PUBLISHED, 'sort_order' => eZContentObjectTreeNode::SORT_ORDER_DESC, 'is_main' => 1)); $nodeAssignment->store(); } $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $object->attribute('id'), 'version' => $subObjectVersion)); $objectNodeID = $object->attribute('main_node_id'); $content['relation_list'][$key]['node_id'] = $objectNodeID; } else { // action 2: edit a nodeless object (or creating a new node // Make the previous version archived $currentVersion = $object->currentVersion(); $currentVersion->setAttribute('status', eZContentObjectVersion::STATUS_ARCHIVED); $currentVersion->setAttribute('modified', $time); $currentVersion->store(); $version->setAttribute('status', eZContentObjectVersion::STATUS_PUBLISHED); $version->store(); $object->setAttribute('status', eZContentObject::STATUS_PUBLISHED); if (!$object->attribute('published')) { $object->setAttribute('published', $time); } $object->setAttribute('modified', $time); $object->setAttribute('current_version', $subObjectVersion); $class = $object->contentClass(); $objectName = $class->contentObjectName($object, $version->attribute('version')); $object->setName($objectName, $version->attribute('version')); $object->store(); if (!eZNodeAssignment::fetch($object->attribute('id'), $object->attribute('current_version'), $contentObject->attribute('main_node_id'), false)) { $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $contentObject->attribute('main_node_id'), 'sort_field' => eZContentObjectTreeNode::SORT_FIELD_PUBLISHED, 'sort_order' => eZContentObjectTreeNode::SORT_ORDER_DESC, 'is_main' => 1)); $nodeAssignment->store(); } } $content['relation_list'][$key]['is_modified'] = false; } } $this->storeObjectAttributeContent($contentObjectAttribute, $content); $contentObjectAttribute->setContent($content); $contentObjectAttribute->store(); }
eZNodeAssignment::removeByID($nodeAssignment->attribute('id')); } } if ($hasOtherNodeType) { foreach ($otherNodeArray as $otherNode) { if (!in_array($otherNode['parent_node_id'], $noAddAssignmentList)) { $newVersion->assignToNode($otherNode['parent_node_id'], $otherNode['is_main']); } } } if ($hasLDAPNodeType) { foreach ($newLDAPNodeArray as $newLDAPNode) { if (!in_array($newLDAPNode['parent_node_id'], $noAddAssignmentList)) { $newVersion->assignToNode($newLDAPNode['parent_node_id'], $newLDAPNode['is_main']); } $assignment = eZNodeAssignment::fetch($contentObject->attribute('id'), $newVersionNr, $newLDAPNode['parent_node_id']); $assignment->setAttribute('parent_remote_id', uniqid('LDAP_')); $assignment->store(); } } if (!$hasOtherNodeType and !$hasLDAPNodeType) { if (!in_array($defaultUserPlacement, $noAddAssignmentList)) { $newVersion->assignToNode($defaultUserPlacement, 1); } } $adminUser = eZUser::fetchByName('admin'); $adminUserContentObjectID = $adminUser->attribute('contentobject_id'); eZUser::setCurrentlyLoggedInUser($adminUser, $adminUserContentObjectID); $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $userID, 'version' => $newVersionNr)); $cli->output($cli->stylize('emphasize', $existUser->attribute('login')) . " has changed group, updated."); }
/** * Removes previously selected, now unselected assignments. * * This hook is run at "post_store" time. * * @param mixed $module Is eZModule. * @param mixed $class Is eZContentClass. * @param mixed $object Is eZContentObject. * @param mixed $version Is eZContentObjectVersion. * @param mixed $contentObjectAttributes Is eZContentObjectAttribute. * @param string $editVersion Number as String. * @param string $editLanguage E.g. eng-GB. * @param mixed $fromLanguage Or false. * @param mixed &$validation Array. * * @return int eZModule::HOOK_STATUS_CANCEL_RUN */ public function removeNodeAssignments($module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, &$validation) { $http = eZHTTPTool::instance(); if (!$http->hasPostVariable('ymcNodeAssignmentsPool')) { return eZModule::HOOK_STATUS_OK; } $ymcActiveNodeAssignmentsPool = $http->postVariable('ymcActiveNodeAssignmentsPool'); $ymcNodeAssignmentsPool = $http->postVariable('ymcNodeAssignmentsPool'); if (!is_array($ymcActiveNodeAssignmentsPool)) { $ymcActiveNodeAssignmentsPool = array(); } if (!is_array($ymcNodeAssignmentsPool)) { $ymcNodeAssignmentsPool = array(); } $selected = array(); foreach ($ymcNodeAssignmentsPool as $ymcAllNodeAssignment) { if ((int) $ymcAllNodeAssignment > 0 and !in_array($ymcAllNodeAssignment, $ymcActiveNodeAssignmentsPool)) { $selected[] = (int) $ymcAllNodeAssignment; } } $objectID = $object->attribute('id'); $versionInt = $version->attribute('version'); $hasChildren = false; $assignmentsIDs = array(); $assignments = array(); // Determine if at least one node of ones we remove assignments for has children. foreach ($selected as $parentNodeID) { $assignment = eZNodeAssignment::fetch($objectID, $versionInt, $parentNodeID); if (!$assignment) { eZDebug::writeWarning("[ymcEdit] No assignment found for object {$objectID} version {$versionInt},\n parent node {$parentNodeID}"); continue; } $assignmentID = $assignment->attribute('id'); $assignmentsIDs[] = $assignmentID; $assignments[] =& $assignment; $node =& $assignment->attribute('node'); if (!$node) { continue; } if ($node->childrenCount(false) > 0) { $hasChildren = true; } unset($assignment); } if ($hasChildren) { // We need user confirmation if at least one node we want to // remove assignment for contains children. Aactual removal is // done in content/removeassignment in this case. $http->setSessionVariable('AssignmentRemoveData', array('remove_list' => $assignmentsIDs, 'object_id' => $objectID, 'edit_version' => $versionInt, 'edit_language' => $editLanguage, 'from_language' => $fromLanguage)); $module->redirectToView('removeassignment'); return eZModule::HOOK_STATUS_CANCEL_RUN; } else { // Just remove all the selected locations. $mainNodeChanged = false; $db = eZDB::instance(); $db->begin(); foreach ($assignments as $assignment) { $assignmentID = $assignment->attribute('id'); if ($assignment->attribute('is_main')) { $mainNodeChanged = true; } eZNodeAssignment::removeByID($assignmentID); } if ($mainNodeChanged) { eZNodeAssignment::setNewMainAssignment($objectID, $versionInt); } $db->commit(); unset($mainNodeChanged); } unset($assignmentsIDs, $assignments); }
function onPublish($contentObjectAttribute, $contentObject, $publishedNodes) { $content = $contentObjectAttribute->content(); foreach ($content['relation_browse'] as $key => $relationItem) { if ($relationItem['is_modified']) { $subObjectID = $relationItem['contentobject_id']; $subObjectVersion = $relationItem['contentobject_version']; $object = eZContentObject::fetch($subObjectID); if ($object) { $class = $object->contentClass(); $time = time(); // Make the previous version archived $currentVersion = $object->currentVersion(); $currentVersion->setAttribute('status', eZContentObjectVersion::STATUS_ARCHIVED); $currentVersion->setAttribute('modified', $time); $currentVersion->store(); $version = eZContentObjectVersion::fetchVersion($subObjectVersion, $subObjectID); $version->setAttribute('modified', $time); $version->setAttribute('status', eZContentObjectVersion::STATUS_PUBLISHED); $version->store(); $object->setAttribute('status', eZContentObject::STATUS_PUBLISHED); if (!$object->attribute('published')) { $object->setAttribute('published', $time); } $object->setAttribute('modified', $time); $object->setAttribute('current_version', $version->attribute('version')); $object->setAttribute('is_published', true); $objectName = $class->contentObjectName($object, $version->attribute('version')); $object->setName($objectName, $version->attribute('version')); $object->store(); } if ($relationItem['parent_node_id'] > 0) { if (!eZNodeAssignment::fetch($object->attribute('id'), $object->attribute('current_version'), $relationItem['parent_node_id'], false)) { $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $relationItem['parent_node_id'], 'sort_field' => 2, 'sort_order' => 0, 'is_main' => 1)); $nodeAssignment->store(); } $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $object->attribute('id'), 'version' => $object->attribute('current_version'))); $objectNodeID = $object->attribute('main_node_id'); $content['relation_browse'][$key]['node_id'] = $objectNodeID; } else { if (!eZNodeAssignment::fetch($object->attribute('id'), $object->attribute('current_version'), $contentObject->attribute('main_node_id'), false)) { $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $contentObject->attribute('main_node_id'), 'sort_field' => 2, 'sort_order' => 0, 'is_main' => 1)); $nodeAssignment->store(); } } $content['relation_browse'][$key]['is_modified'] = false; } } eZObjectRelationBrowseType::storeObjectAttributeContent($contentObjectAttribute, $content); $contentObjectAttribute->setContent($content); $contentObjectAttribute->store(); }