Created
January 17, 2013 16:54
-
-
Save pauletienney/4557479 to your computer and use it in GitHub Desktop.
eZ Publish 4 : copy an object and put it in a new node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function copyObjectToNewLocation($object, $newParentNodeId) { | |
$db = eZDB::instance(); | |
$db->begin(); | |
$newObject = $object->copy(false); | |
$newObject->setAttribute( 'section_id', 0 ); | |
$newObject->store(); | |
$curVersion = $newObject->attribute( 'current_version' ); | |
$curVersionObject = $newObject->attribute( 'current' ); | |
$newObjAssignments = $curVersionObject->attribute( 'node_assignments' ); | |
unset( $curVersionObject ); | |
foreach( $newObjAssignments as $assignment ) | |
{ | |
$assignment->purge(); | |
} | |
$nodeAssignment = eZNodeAssignment::create( array( | |
'contentobject_id' => $newObject->attribute( 'id' ), | |
'contentobject_version' => $curVersion, | |
'parent_node' => $newParentNodeId, | |
'is_main' => 1 | |
) ); | |
eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $newObject->attribute( 'id' ), | |
'version' => $curVersion ) ); | |
// Update "is_invisible" attribute for the newly created node. | |
$newNode = $newObject->attribute( 'main_node' ); | |
eZContentObjectTreeNode::updateNodeVisibility( $newNode, $newParentNode ); | |
$db->commit(); | |
return $newObject; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment