Workflow help

Author Message

nicholas king

Tuesday 22 February 2011 1:36:07 am

Hello Guys, has anyone got any links pointers to setting up workflows, specifically to move content after it is published. I have found one really good article

http://share.ez.no/learn/ez-publish/creating-a-simple-custom-workflow-event

but am after a bit more documentation.

Thanks

Nicholas

nicholas king

Wednesday 23 February 2011 5:05:42 am

<?php
class MoveMediaType extends eZWorkflowEventType {<span> 
</span>const WORKFLOW_TYPE_STRING = "movemedia";<span> 
</span>public function __construct() {<span>  
</span><span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;"> </span>parent::__construct ( MoveMediaType::WORKFLOW_TYPE_STRING, 'Move Files into the media library' );
}<span> </span><span> 
</span>public function execute($process, $event) {<span>  
</span><span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;"> </span>$parameters = $process->attribute ( 'parameter_list' );
<span> </span>/*  YOUR CODE GOES HERE */<span>  </span><span>  
</span><span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;"> </span>$objectID = $parameters ['object_id'];<span>  
</span><span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;"> </span>$object = eZContentObject::fetch ( $objectID );<span>  
</span><span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;"> </span>$node = $object->attribute ( 'main_node' );
<span> </span>$selectedNodeID = 43;
<span> </span><span> 
</span><span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;"> </span>if( eZOperationHandler::operationIsAvailable( 'content_move' ) )
<span> </span>{<span>   
</span><span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;">  </span>$operationResult = eZOperationHandler::execute( 'content',
<span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;">  </span>'move', array( 'node_id' => $nodeToMove['node_id'],
<span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;">  </span>'object_id' => $nodeToMove['object_id'],
<span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;">  </span>'new_parent_node_id' => $selectedNodeID ),
<span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;">  </span>null,true );
<span> </span>}else{
<span> <span class="Apple-tab-span" style="white-space:pre" mce_style="white-space: pre;"> </span></span>eZContentOperationCollection::moveNode( $nodeToMove['node_id'], $nodeToMove['object_id'],$selectedNodeID );
<span> </span>}<span> 


<span class="Apple-tab-span" style="white-space:pre"> </span>return eZWorkflowType::STATUS_ACCEPTED;<span> </span>

}
}
eZWorkflowEventType::registerEventType ( MoveMediaType::WORKFLOW_TYPE_STRING, 'movemediatype' );
?>

Hello I currently have this as my workflow code, but am struggling to get the event to fire! any help appreciated.

nicholas king

Wednesday 23 February 2011 5:07:00 am

<?php
class MoveMediaType extends eZWorkflowEventType { const WORKFLOW_TYPE_STRING = "movemedia"; public function __construct() { parent::__construct ( MoveMediaType::WORKFLOW_TYPE_STRING, 'Move Files into the media library' ); } public function execute($process, $event) { $parameters = $process->attribute ( 'parameter_list' ); /* YOUR CODE GOES HERE */ $objectID = $parameters ['object_id']; $object = eZContentObject::fetch ( $objectID ); $node = $object->attribute ( 'main_node' ); $selectedNodeID = 43; if( eZOperationHandler::operationIsAvailable( 'content_move' ) ) { $operationResult = eZOperationHandler::execute( 'content', 'move', array( 'node_id' => $nodeToMove['node_id'], 'object_id' => $nodeToMove['object_id'], 'new_parent_node_id' => $selectedNodeID ), null, true ); } else { eZContentOperationCollection::moveNode( $nodeToMove['node_id'], $nodeToMove['object_id'], $selectedNodeID ); } return eZWorkflowType::STATUS_ACCEPTED; }}eZWorkflowEventType::registerEventType ( MoveMediaType::WORKFLOW_TYPE_STRING, 'movemediatype' );?><?php
class MoveMediaType extends eZWorkflowEventType { const WORKFLOW_TYPE_STRING = "movemedia"; public function __construct() { parent::__construct ( MoveMediaType::WORKFLOW_TYPE_STRING, 'Move Files into the media library' ); } public function execute($process, $event) { $parameters = $process->attribute ( 'parameter_list' ); /* YOUR CODE GOES HERE */ $objectID = $parameters ['object_id']; $object = eZContentObject::fetch ( $objectID ); $node = $object->attribute ( 'main_node' ); $selectedNodeID = 43; if( eZOperationHandler::operationIsAvailable( 'content_move' ) ) { $operationResult = eZOperationHandler::execute( 'content', 'move', array( 'node_id' => $nodeToMove['node_id'], 'object_id' => $nodeToMove['object_id'], 'new_parent_node_id' => $selectedNodeID ), null, true ); } else { eZContentOperationCollection::moveNode( $nodeToMove['node_id'], $nodeToMove['object_id'], $selectedNodeID ); } return eZWorkflowType::STATUS_ACCEPTED; }}eZWorkflowEventType::registerEventType ( MoveMediaType::WORKFLOW_TYPE_STRING, 'movemediatype' );?>

nicholas king

Wednesday 23 February 2011 9:25:52 am

solution to move a content node with a workflow:-

<?php
class MoveMediaType extends eZWorkflowEventType { const WORKFLOW_TYPE_STRING = "movemedia"; public function __construct() { parent::__construct ( MoveMediaType::WORKFLOW_TYPE_STRING, 'Move Files into the media library' ); }
public function execute($process, $event) { $parameters = $process->attribute ( 'parameter_list' ); /* YOUR CODE GOES HERE */
$objectID = $parameters ['object_id']; $object = eZContentObject::fetch ( $objectID ); $node_id = $object->attribute('main_node_id'); $selectedNodeID = 43; if ( eZOperationHandler::operationIsAvailable( 'content_move' ) ) { eZContentOperationCollection::moveNode($node_id , $objectID, $selectedNodeID ); } else { print("ERROR"); } return eZWorkflowType::STATUS_ACCEPTED; }}eZWorkflowEventType::registerEventType ( MoveMediaType::WORKFLOW_TYPE_STRING, 'movemediatype' );?>

nicholas king

Wednesday 23 February 2011 9:40:29 am

i am now looking to add a redirect in on completion if anyone has any idea how to do this please comment

Gaetano Giunta

Wednesday 23 February 2011 9:54:24 am

might make a candidate for inclusion in the ezworkflowcollection extension. wanna participate?

Principal Consultant International Business
Member of the Community Project Board

nicholas king

Wednesday 23 February 2011 11:46:16 pm

Hello Gaetano,

feel free to take any of the code that is written and include it into your extension.

i will repost here any enhancements that i make.

Thanks

Nicholas

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