Skip to content

Commit

Permalink
bug #28769 [FrameworkBundle] deal with explicitly enabled workflow no…
Browse files Browse the repository at this point in the history
…des (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[FrameworkBundle] deal with explicitly enabled workflow nodes

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | not yet
| Fixed tickets | #28662
| License       | MIT
| Doc PR        |

Commits
-------

017fd56 deal with explicitly enabled workflow nodes
  • Loading branch information
lyrixx committed Nov 19, 2018
2 parents 236565c + 017fd56 commit b74a086
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 1 deletion.
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\Form\Form;
use Symfony\Component\Lock\Lock;
use Symfony\Component\Lock\Store\SemaphoreStore;
Expand Down Expand Up @@ -267,10 +268,22 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
$workflows = $v;
unset($workflows['enabled']);

if (1 === \count($workflows) && isset($workflows[0]['enabled'])) {
if (1 === \count($workflows) && isset($workflows[0]['enabled']) && 1 === \count($workflows[0])) {
$workflows = array();
}

if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), array('audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_place', 'places', 'transitions')))) {
$workflows = $workflows['workflows'];
}

foreach ($workflows as $key => $workflow) {
if (isset($workflow['enabled']) && false === $workflow['enabled']) {
throw new LogicException(sprintf('Cannot disable a single workflow. Remove the configuration for the workflow "%s" instead.', $workflow['name']));
}

unset($workflows[$key]['enabled']);
}

$v = array(
'enabled' => true,
'workflows' => $workflows,
Expand Down
@@ -0,0 +1,19 @@
<?php

$container->loadFromExtension('framework', array(
'workflows' => array(
'enabled' => true,
'foo' => array(
'type' => 'workflow',
'supports' => array('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'),
'initial_place' => 'bar',
'places' => array('bar', 'baz'),
'transitions' => array(
'bar_baz' => array(
'from' => array('foo'),
'to' => array('bar'),
),
),
),
),
));
@@ -0,0 +1,19 @@
<?php

$container->loadFromExtension('framework', array(
'workflows' => array(
'enabled' => true,
'workflows' => array(
'type' => 'workflow',
'supports' => array('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'),
'initial_place' => 'bar',
'places' => array('bar', 'baz'),
'transitions' => array(
'bar_baz' => array(
'from' => array('foo'),
'to' => array('bar'),
),
),
),
),
));
@@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:workflow enabled="true" name="foo" type="workflow" initial-place="bar">
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place>bar</framework:place>
<framework:place>baz</framework:place>
<framework:transition name="bar_baz">
<framework:from>bar</framework:from>
<framework:to>baz</framework:to>
</framework:transition>
</framework:workflow>
</framework:config>
</container>
@@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:workflow enabled="true" name="workflows" type="workflow" initial-place="bar">
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place>bar</framework:place>
<framework:place>baz</framework:place>
<framework:transition name="bar_baz">
<framework:from>bar</framework:from>
<framework:to>baz</framework:to>
</framework:transition>
</framework:workflow>
</framework:config>
</container>
@@ -0,0 +1,16 @@
framework:
workflows:
enabled: true
workflows:
foo:
type: workflow
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
initial_place: bar
places:
- bar
- baz
transitions:
bar_baz:
from: [foo]
to: [bar]
@@ -0,0 +1,15 @@
framework:
workflows:
enabled: true
workflows:
type: workflow
supports:
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
initial_place: bar
places:
- bar
- baz
transitions:
bar_baz:
from: [foo]
to: [bar]
Expand Up @@ -390,6 +390,20 @@ public function testWorkflowServicesCanBeEnabled()
$this->assertTrue($container->hasDefinition('console.command.workflow_dump'));
}

public function testExplicitlyEnabledWorkflows()
{
$container = $this->createContainerFromFile('workflows_explicitly_enabled');

$this->assertTrue($container->hasDefinition('workflow.foo.definition'));
}

public function testExplicitlyEnabledWorkflowNamedWorkflows()
{
$container = $this->createContainerFromFile('workflows_explicitly_enabled_named_workflows');

$this->assertTrue($container->hasDefinition('workflow.workflows.definition'));
}

public function testEnabledPhpErrorsConfig()
{
$container = $this->createContainerFromFile('php_errors_enabled');
Expand Down

0 comments on commit b74a086

Please sign in to comment.