Skip to content

Commit

Permalink
Fix EZP-29600: eZ Flow pool table not updated on node swap (#81)
Browse files Browse the repository at this point in the history
(cherry picked from commit 70a8964)
  • Loading branch information
peterkeung authored and andrerom committed Sep 19, 2018
1 parent 5f0e056 commit 5fcfaca
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function __construct()

function execute( $process, $event )
{
$db = eZDB::instance();
$db->begin();
$parameters = $process->attribute( 'parameter_list' );

$oldNodeID = $parameters['node_id'];
Expand All @@ -62,7 +64,68 @@ function execute( $process, $event )
$newNodeBlock->setAttribute( 'node_id', $oldNodeID );
$newNodeBlock->store();
}

// Get the object IDs to update the pool items
$oldNode = eZContentObjectTreeNode::fetch( $oldNodeID );
$oldNodeObjectID = $oldNode->attribute( 'contentobject_id' );
$newNode = eZContentObjectTreeNode::fetch( $newNodeID );
$newNodeObjectID = $newNode->attribute( 'contentobject_id' );

// Update with the new object IDs
// Object IDs are keys, so we have to watch out for the case where the swapped nodes are part of the same block, in which case we need to swap the node IDs instead
$swappedBlockIDs = array();
$oldNodePoolItems = eZFlowPoolItem::fetchObjectList( eZFlowPoolItem::definition(), null, array( 'node_id' => $oldNodeID ) );
$newNodePoolItems = eZFlowPoolItem::fetchObjectList( eZFlowPoolItem::definition(), null, array( 'node_id' => $newNodeID ) );

// Loop over fetched pool items for old node
foreach( $oldNodePoolItems as $oldNodePoolItem )
{
// Check if the swapped node is part of the same block
$swappedNodePoolItem = eZFlowPoolItem::fetchObjectList( eZFlowPoolItem::definition(), null, array( 'node_id' => $newNodeID, 'block_id' => $oldNodePoolItem->attribute( 'block_id' ) ) );
if( empty( $swappedNodePoolItem ) )
{
$updateParameters = array(
'definition' => eZFlowPoolItem::definition(),
'update_fields' => array( 'object_id' => $oldNodeObjectID ),
'conditions' => array(
'object_id' => $oldNodePoolItem->attribute( 'object_id' ),
'block_id' => $oldNodePoolItem->attribute( 'block_id' )
)
);
eZFlowPoolItem::updateObjectList( $updateParameters );
}
else
{
// Swap node IDs
$oldNodePoolItem->setAttribute( 'node_id', $newNodeID );
$oldNodePoolItem->store();
$swappedNodePoolItem[0]->setAttribute( 'node_id', $oldNodeID );
$swappedNodePoolItem[0]->store();
// Do not process this block ID again
$swappedBlockIDs[] = $oldNodePoolItem->attribute( 'block_id' );
}
}

// Loop over fetched pool items for new node
foreach( $newNodePoolItems as $newNodePoolItem )
{
// Don't process this block if both nodes IDs were already updated
if( in_array( $newNodePoolItem->attribute( 'block_id' ), $swappedBlockIDs ) )
{
continue;
}
$updateParameters = array(
'definition' => eZFlowPoolItem::definition(),
'update_fields' => array( 'object_id' => $newNodeObjectID ),
'conditions' => array(
'object_id' => $newNodePoolItem->attribute( 'object_id' ),
'block_id' => $newNodePoolItem->attribute( 'block_id' )
)
);
eZFlowPoolItem::updateObjectList( $updateParameters );
}

$db->commit();
return eZWorkflowType::STATUS_ACCEPTED;
}
}
Expand Down

0 comments on commit 5fcfaca

Please sign in to comment.