Forums / Developer / Workflow removeSubtrees & addLocation

Workflow removeSubtrees & addLocation

Author Message

Dirk Bensel

Friday 21 August 2009 9:03:13 am

Hi everbody!

I have extended my user class with an optionfield User_group.
If an Editor wants to create a user, he just have to select the group in the frontend-form.

I use the createmultiplelocationrule event - Before publish.
The user is published in the default user_group 12 and in the selected location.
Works fine!

But now i run into trouble.
If an editor wants to change the selected group of an user, the old location has to be removed and the new location has to be assigned.

...
$db = eZDB::instance();
$db->begin();	

$nodes = $object->attribute('assigned_nodes');
$mainNodeId = $object->attribute('main_node_id');

 //remove all nodes that are not main 
foreach ($nodes as $node)
{
  $nodeid = $node->attribute('node_id');
  if ( $nodeid != $mainNodeId )
  {
  $deleteIDArray[] = $nodeid;
  }
}
$removeSubtrees = eZContentObjectTreeNode::removeSubtrees( $deleteIDArray, false );

//it works
...
$object->addLocation( $destID, false );
//it works, but only on first creation not on changing
$db->commit();
...

After publishing the user-object, the new locations are not assigned.
After editing the user again, doing no changes, the user location are assigned correct.

Any hint?

---
ROCK ON
Dirk

André R.

Saturday 22 August 2009 4:00:09 am

Have a look in: http://pubsvn.ez.no/nextgen/stable/4.1/kernel/content/ezcontentoperationcollection.php

Especially ::removeAssignment(), you can probably use that as is. (there is a ::addAssignment also).

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Dirk Bensel

Tuesday 25 August 2009 8:13:04 am

Got it!
(using ezp 4.0.6)

I changed the TriggerType in the addLoactionEventWorkflow to AfterPublish and build a removeLocationEventWorkflow with TriggerType BeforePublish.

---
ROCK ON
Dirk