Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes issue #13 with passing variables from and to sub-workflows #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/nodes/sub_workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,16 @@ public function execute( ezcWorkflowExecution $execution )
{
$subExecution = $execution->getSubExecution( $this->state );
$subExecution->workflow = $workflow;
$subExecution->resume( $execution->getVariables() );

$subVariables = [];
foreach ( $execution->getVariables() as $variableName => $data )
{
if ( isset($this->configuration['variables']['in'][$variableName]) )
{
$subVariables[$this->configuration['variables']['in'][$variableName]] = $data;
}
}
$subExecution->resume( $subVariables );
}
}

Expand All @@ -188,9 +197,10 @@ public function execute( ezcWorkflowExecution $execution )
}

// Execution of Sub Workflow has been suspended.
$reverseInVariableMap = array_flip( $this->configuration['variables']['in'] );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be flipped?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given an interactive sub-workflow node which maps x on the parent workflow to y on the sub-workflow. The workflow used as sub-workflow now waits for its variable y to be set.
If sub-workflow is waiting for y the parent workflow is also waiting for a variable. But the parent is not waiting for y but for x because of the mapping. y is not even a variable known to the parent workflow.
I hope this is somehow understandable...

foreach ( $subExecution->getWaitingFor() as $variableName => $data )
{
$execution->addWaitingFor( $this, $variableName, $data['condition'] );
$execution->addWaitingFor( $this, $reverseInVariableMap[$variableName], $data['condition'] );
}

return false;
Expand Down Expand Up @@ -298,7 +308,9 @@ protected function passVariables( ezcWorkflowExecution $from, ezcWorkflowExecuti
{
foreach ( $variables as $fromName => $toName )
{
$to->setVariable( $toName, $from->getVariable( $fromName ) );
if ( $from->hasVariable( $fromName ) ) {
$to->setVariable( $toName, $from->getVariable( $fromName ) );
}
}
}
}
Expand Down