From 0b9539c30c2350d6e96e57990816fa9632882f6e Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Tue, 3 Nov 2026 11:39:41 +0100 Subject: [PATCH] #414 - Deprecate listing a task several times in the outputs or the error outputs of a task Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + UPGRADE.md | 6 ++++ docs/reference/02-task_definition.md | 4 ++- src/Registry/ProcessConfigurationRegistry.php | 31 +++++++++++++++++ .../ProcessConfigurationRegistryTest.php | 34 +++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c7e59c4..90ca2ca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ## Changes +* [#414](https://github.com/cleverage/process-bundle/issues/414) Listing a task several times in the `outputs` or the `error_outputs` of a task is deprecated: it is executed once per occurrence, an exception will be thrown in v6.0 (see `UPGRADE.md`). Update documentation, add tests. * [#406](https://github.com/cleverage/process-bundle/issues/406) Documentation: non-interactive install with Symfony Flex (`allow-contrib`, the recipe being in `recipes-contrib`), `$kernel` constructor parameter renamed in 5.4 in `UPGRADE.md` (breaks the named arguments), prerequisites of the functional test of `06-testing.md` (`KERNEL_CLASS`, test database with the UI bundle). * [#392](https://github.com/cleverage/process-bundle/issues/392) Documentation: reset of the process configurations between two messages of a worker (`kernel.reset`, #355), permissions of the JSON buffer of `process_launcher`, `ProcessManager` subclasses in `UPGRADE.md` (v5.5), broken link in the CHANGELOG. diff --git a/UPGRADE.md b/UPGRADE.md index 38ae8ad9..fdc94472 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -17,6 +17,12 @@ If you used the former name (with underscores) of such a code, it still works bu `process_executor` tasks, the task references (`outputs`, `error_outputs`, `entry_point`, `end_point`), the transformer references and the applications storing process codes (e.g. the schedules of the UI bundle). +### Duplicate task references + +Listing a task several times in the `outputs` or the `error_outputs` of a task (e.g. `outputs: [next, next]`) is +deprecated since 5.7 (`Since cleverage/process-bundle 5.7: Listing the task "next" several times in the "outputs"...`): +the task is executed once per occurrence, and an exception will be thrown in 6.0. List it once. + ## v5.6 Two deprecations, and some behaviours change: check the points below. diff --git a/docs/reference/02-task_definition.md b/docs/reference/02-task_definition.md index d53f6a3d..7343ca03 100644 --- a/docs/reference/02-task_definition.md +++ b/docs/reference/02-task_definition.md @@ -49,7 +49,9 @@ added at runtime) is fetched from the service container, which requires a public **options**: optional list of parameters to pass to the task. String values can contain `{{ key }}` placeholders that are replaced by the process [contextual values](../01-quick_start.md#contextual-values). -**outputs**: optional list of following tasks, receiving the output of this task. It can be a simple string. +**outputs**: optional list of following tasks, receiving the output of this task. It can be a simple string. A task +listed several times is executed once per occurrence: this is deprecated since 5.7, and will throw an exception in 6.0 +(also for `error_outputs`). **error_outputs**: optional list of following tasks, receiving the error output of this task (by default its input when an error occurs). It can be a simple string. See [errors and skips](../04-advanced_workflow.md#errors-and-skips). diff --git a/src/Registry/ProcessConfigurationRegistry.php b/src/Registry/ProcessConfigurationRegistry.php index 612e08ef..eaaea634 100644 --- a/src/Registry/ProcessConfigurationRegistry.php +++ b/src/Registry/ProcessConfigurationRegistry.php @@ -252,6 +252,7 @@ protected function resolveConfiguration(string $processCode): void // Check the task references, the links below would fail with a message naming neither the process nor the task $this->checkTaskReferences($processCode, $rawProcessConfiguration, $taskConfigurations, $errorOutputsKeys); + $this->checkDuplicateTaskReferences($processCode, $taskConfigurations, $errorOutputsKeys); // Set links between tasks foreach ($taskConfigurations as $taskConfig) { @@ -322,6 +323,36 @@ protected function checkTaskReferences( } } + /** + * A task listed several times in the outputs of a task is executed once per occurrence (deprecated). + * + * @param TaskConfiguration[] $taskConfigurations indexed by task code + * @param array $errorOutputsKeys "errors" for the tasks using this deprecated key + */ + private function checkDuplicateTaskReferences(string $processCode, array $taskConfigurations, array $errorOutputsKeys): void + { + foreach ($taskConfigurations as $taskCode => $taskConfig) { + $references = [ + 'outputs' => $taskConfig->getOutputs(), + $errorOutputsKeys[$taskCode] ?? 'error_outputs' => $taskConfig->getErrorOutputs(), + ]; + foreach ($references as $key => $codes) { + foreach (array_unique(array_diff_assoc($codes, array_unique($codes))) as $duplicateCode) { + // @deprecated since 5.7, an exception will be thrown in v6.0 + trigger_deprecation( + 'cleverage/process-bundle', + '5.7', + 'Listing the task "%s" several times in the "%s" of the task "%s" of the process "%s" is deprecated: it is executed once per occurrence. In v6.0, an exception will be thrown.', + $duplicateCode, + $key, + $taskCode, + $processCode, + ); + } + } + } + } + protected function markErrorBranch(TaskConfiguration $taskConfig, bool $isErrorBranch = true): void { if ($taskConfig->isInErrorBranch() !== $isErrorBranch) { diff --git a/tests/Registry/ProcessConfigurationRegistryTest.php b/tests/Registry/ProcessConfigurationRegistryTest.php index c0c7e84f..a0584d0f 100644 --- a/tests/Registry/ProcessConfigurationRegistryTest.php +++ b/tests/Registry/ProcessConfigurationRegistryTest.php @@ -282,4 +282,38 @@ public function testTheFormerNamesAreDeprecated(): void 'Since cleverage/process-bundle 5.7: Referencing the task "next-task" of the process "demo.x-y" by the name "next_task" in "outputs", with underscores instead of dashes, is deprecated: use its code "next-task". The dashes of the codes were replaced by underscores before 5.7, the former name will not be found in v6.0.', ], $deprecations); } + + /** + * A task listed several times in the outputs is executed once per occurrence: deprecated, it will throw in v6.0. + */ + public function testDuplicateTaskReferencesAreDeprecated(): void + { + $registry = new ProcessConfigurationRegistry([ + 'test.process' => $this->rawProcess([ + 'first' => ['outputs' => ['next', 'other', 'next', 'next'], 'error_outputs' => ['error', 'error']], + 'next' => [], + 'other' => [], + 'error' => [], + ]), + ], 'stop'); + $deprecations = []; + set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool { + $deprecations[] = $errstr; + + return true; + }, \E_USER_DEPRECATED); + try { + $processConfiguration = $registry->getProcessConfiguration('test.process'); + } finally { + restore_error_handler(); + } + + // Unchanged behaviour until v6.0 + self::assertCount(4, $processConfiguration->getTaskConfiguration('first')->getNextTasksConfigurations()); + self::assertCount(2, $processConfiguration->getTaskConfiguration('first')->getErrorTasksConfigurations()); + self::assertSame([ + 'Since cleverage/process-bundle 5.7: Listing the task "next" several times in the "outputs" of the task "first" of the process "test.process" is deprecated: it is executed once per occurrence. In v6.0, an exception will be thrown.', + 'Since cleverage/process-bundle 5.7: Listing the task "error" several times in the "error_outputs" of the task "first" of the process "test.process" is deprecated: it is executed once per occurrence. In v6.0, an exception will be thrown.', + ], $deprecations); + } }