Forums / Developer / Moving Objects via PHP & Cron / Comment40881
Pål J Didriksen
Monday 11 July 2005 7:46:30 am
At last I managed to get it working... :)
My code now looks like this, and from the first couple of tests, it seems to be working:
$to_node_id=237; // Fetch subtree of objects that should be moved $params = array(); $childNodes =& eZContentObjectTreeNode::subTree( $params, $parentNodeID ); // Loop through each object foreach( $childNodes as $child ) { $thisNode = $child -> MainNodeID; $userID = $child -> ContentObjectID; // Fetch the user object $object =& eZContentObject::fetch( $userID ); // Fetch the current version $version =& eZContentObjectVersion::fetchVersion( $object->attribute('current_version'), $userID ); // Unpublish this version $version->unpublish(); // Add new assignment, and make it main $version->assignToNode($to_node_id, 1); // Remove old assignment eZContentObjectTreeNode::remove( $thisNode ); // Re-publish version again $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $userID, 'version' => $object->attribute('current_version') ) ); }
Found the tip to unpublish the object before changing the assignment here:http://ez.no/community/forum/developer/add_location_to_user_with_template_programming_solved
I also changed the code for removing the old assignment to <i> eZContentObjectTreeNode::remove( $thisNode );</i>
Now I'm happy again! ;)