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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 11:28:54
Script start
Timing: Jan 18 2025 11:28:54
Module start 'layout'
Timing: Jan 18 2025 11:28:54
Module start 'content'
Timing: Jan 18 2025 11:28:55
Module end 'content'
Timing: Jan 18 2025 11:28:55
Script end

Main resources:

Total runtime0.8705 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0074 587.9375152.6250
Module start 'layout' 0.00740.0033 740.562539.4453
Module start 'content' 0.01070.8583 780.0078553.8672
Module end 'content' 0.86900.0015 1,333.875012.1563
Script end 0.8704  1,346.0313 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.4088160.0002
Check MTime0.00170.1926160.0001
Mysql Total
Database connection0.00070.082010.0007
Mysqli_queries0.817393.8943570.0143
Looping result0.00100.1100550.0000
Template Total0.833595.820.4168
Template load0.00210.246920.0011
Template processing0.831495.506120.4157
Template load and register function0.00010.013910.0001
states
state_id_array0.00120.142210.0012
state_identifier_array0.00220.252420.0011
Override
Cache load0.00180.2051250.0001
Sytem overhead
Fetch class attribute can translate value0.00060.064820.0003
Fetch class attribute name0.00090.105350.0002
XML
Image XML parsing0.00140.155920.0007
class_abstraction
Instantiating content class attribute0.00000.001360.0000
General
dbfile0.00120.1428240.0001
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs