Forums / Developer / Adding user to a new location
Milad P
Tuesday 25 July 2006 6:00:09 am
I found a new problem when upgrading from 3.6.5 to 3.8.1. I try to add a new location for a user with this code which has worked fine with earlier ez versions. I don't get any error messages or anything and it doesn't add the new location.
Any suggestions?
/Milad
// User exists (either before or has just been created). Need to add the new location for the user // 1. Determine the userID of the user. // 2. Fetch the user object // 3. Do $object->createNodeAssignment($groupNodeID, false); (last parameter = isMainNode) // fetch some data into an array of associative arrays $userID = $rows[0]["contentobject_id"]; // echo $userID; // Need to unpublish the user to be able to add it to the new location. include_once('kernel/classes/ezcontentobject.php'); $object =& eZContentObject::fetch( $userID ); $version =& eZContentObjectVersion::fetchVersion( $object->attribute('current_version'), $userID ); $version->unpublish(); // Add the location to the user $object->createNodeAssignment($groupID, false); // Finally, publish the user again. include_once( 'lib/ezutils/classes/ezoperationhandler.php' ); $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $userID, 'version' => $object->attribute('current_version') ) );
Kristof Coomans
Tuesday 25 July 2006 9:50:49 am
Hi Milad
Take a look at http://pubsvn.ez.no/wiki/en/ez/adding_additional_locations_for_an_object. The code mentioned there comes right out of the kernel of eZ 3.8.
independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org