Thursday 16 November 2006 5:20:47 am
Using the new custom edit handler (http://serwatka.net/en/blog/ez_publish_3_8_new_custom_edit_handler), I managed to solve a problem while designing our new CMS.
function publish( $contentObjectID, $contentObjectVersion )
{
//To check whether the node was already assigned or not
$isAssigned = false;
// fetch object
$object =& eZContentObject::fetch( $contentObjectID );
// get content class object
$contentClass =& $object->attribute('content_class');
// check if currently published object is Article
if ( $contentClass->attribute('id') == 16 )
{
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
// prepare new object data
$parentNodeID = 69;
//check if this Node is already assigned to the destination node
$assignedNodes = $object->attribute('assigned_nodes');
foreach ($assignedNodes as $assignedNode){
if( $parentNodeID == $assignedNode->ParentNodeID ){
$isAssigned = true;
break;
}
}
if( !$isAssigned ){
$nodeAssignment =& eZNodeAssignment::create(
array(
'contentobject_id' => $object->attribute('id'),
'contentobject_version' => $contentObjectVersion,
'parent_node' => $parentNodeID,
'is_main' => 0
)
);
//print_r($nodeAssignment);
$nodeAssignment->store();
$operationResult = eZOperationHandler::execute( 'content', 'publish',
array(
'object_id' => $object->attribute( 'id' ),
'version' => $contentObjectVersion,
)
);
}
}
}
The important thing to notice, is that I'm checking if the node is already assigned. If this check wasn't placed the the system would go in an infinite loop
|