You can achieve this using the existing after-publishing trigger bound to a multiplexer workflow. Then the multiplexer would upon publishing of a 'user' object call a custom workflow which in turns calls a custom workflow event with this:
function execute( $process, $event )
{
$parameters = $process->attribute( 'parameter_list' );
// Retreive object info from the parameters
$objectID = $parameters['object_id'];
$object = eZContentObject::fetch( $objectID );
$nodeID = $object->attribute( 'main_node_id' );
$parentNodeID = $object->attribute( 'main_parent_node_id' );
$datamap = $object->dataMap();
// the user account being created
$userAccount = $datamap['user_account']->content();
$userLogin = $userAccount->attribute('login');
$params = array();
// Node ID of the parent folder where to create the user personal folder
// Best is to store that in an INI file
$params['parent_node_id'] = 637;
$params['class_identifier'] = 'folder';
// The creator id is set to the user id
$params['creator_id'] = $objectID;
// attributes for the created folder
$attributesData = array();
// Set the name of the folder to the name of the user
$attributesData['name'] = $object->attribute('name');
// Set the short name to the user login
$attributesData['short_name'] = $userLogin;
$params['attributes'] = $attributesData;
$db = eZDB::instance();
$db->begin();
$folderObject = eZContentFunctions::createAndPublishObject( $params );
// In the user class, you can add a new attribute of datatype Enhanced Object Relation:
// http://projects.ez.no/enhanced_objectrelation/
// This can help to locate the user's personal folder
$userFolderAttribute = $datamap['related_diagram_repository'];
// Resetting default relation
$fromObjectID =(int) $object->attribute('id');
$contentClassAttributeID =(int) $userFolderAttribute->ContentClassAttributeID;
$contentObjectVersion =(int) $object->attribute('version') + 1;
$db->query( "DELETE FROM ezcontentobject_link WHERE from_contentobject_id='$fromObjectID' AND from_contentobject_version='$contentObjectVersion' AND contentclassattribute_id='$contentClassAttributeID'" );
// Set relation to the user's Folder
$object->addContentObjectRelation($folderObject->attribute('id'), (int)$object->attribute('version'), $userFolderAttribute->ContentClassAttributeID);
$db->commit();
return eZWorkflowType::STATUS_ACCEPTED;
}
I've tried with personalfolder (I have done it one year ago and it worked) but it does not seem to work. I think that it is a problem with the "patch" files that I must copy to kernel/users. I don't reach to undertand what I'm doing wrong.
For the second option, how I link the workflow code to the trigger, I'm really new in eZ and I don't reach the way to do it like you told Quoc Huy Nguyen Dinh. Please, I will really apreciate I you would you show me the steps, one by one, to do what you said.
I'm pretty busy these days so won't be able to fully help you with this, but I wrote a tutorial on how to create workflows, so please have a read at it and learn workflows as they are a pretty important eZ Publish feature. If you still have issues, I will try to give more help later.
Ups, sorry, my name is Albert, if tried yet this tutorial but I'm going crazy, I don't know if I'm doing well all the steps, I don't reach the solution, I think I have a problem understanding the order of workflow creation.
I continue to try. Thanks anyway.
I really apreciate your comments.
You must be logged in to post messages in this topic!