diff --git a/CHANGELOG.md b/CHANGELOG.md index a1a6d38..2f8b685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ Latest ------ +### Changes +* [#216](https://github.com/cleverage/ui-process-bundle/issues/216) Cookbooks with task codes, application `upload_directory` parameter left alone, deprecation notice for the unused `$translator` argument, scheduler log levels. + ## Changes * [#220](https://github.com/cleverage/ui-process-bundle/issues/220) A process stopped on purpose by a `StopTask` (e.g. not going on when the source file does not exist) is recorded with the `stopped` status, and notified as `stopped`, instead of `finish`. Requires the process bundle version providing `ProcessEvent::isProcessStopped()` (cleverage/process-bundle#337); with an older version, the execution keeps the `finish` status. Update documentation, add tests. * [#207](https://github.com/cleverage/ui-process-bundle/issues/207) The `main` firewall configured by the bundle (`security.configure_firewall`) limits the login attempts (Symfony `login_throttling`, default settings: 5 failed attempts per minute for a username and an IP address, 25 for an IP address); the settings can be changed in the application firewall. Require `symfony/rate-limiter`. Update documentation and tests. diff --git a/UPGRADE.md b/UPGRADE.md index 81eae1b..9d2fffb 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -53,6 +53,12 @@ removed in 4.0: update your templates (e.g. overridden templates of the bundle). | `resolve_ui_options()` | `cleverage_ui_process_resolve_ui_options()` | | `md5` (filter) | `cleverage_ui_process_md5` (filter) | +### Process executions controller + +The `$translator` argument of `ProcessExecutionCrudController::__construct()` is deprecated (it is not used since 3.3, +the duration format being defined in the `admin/field/duration.html.twig` template): passing it triggers a deprecation, +it will be removed in 4.0. Only an application that redefines this controller service is concerned. + ### Process bundle 5.4 `cleverage/process-bundle` `^5.4` is required: follow its diff --git a/config/services/controller.yaml b/config/services/controller.yaml index f16388e..6f4937f 100644 --- a/config/services/controller.yaml +++ b/config/services/controller.yaml @@ -62,7 +62,6 @@ services: arguments: $processExecutionRepository: '@cleverage_ui_process.repository.process_execution' $logDirectory: '%kernel.logs_dir%' - $translator: '@translator' # $staleAfter: set by the extension (process_execution.stale_after) calls: - [setContainer, ['@Psr\Container\ContainerInterface']] diff --git a/docs/cookbooks/form_file_upload.md b/docs/cookbooks/form_file_upload.md index d5df0eb..124245a 100644 --- a/docs/cookbooks/form_file_upload.md +++ b/docs/cookbooks/form_file_upload.md @@ -38,7 +38,7 @@ clever_age_process: message: 'delimiter context must be , or ;. {{ value }} given.' tasks: log_file: - service: '@CleverAge\ProcessBundle\Task\Reporting\LoggerTask' + task: logger options: level: info message: 'Read file' @@ -46,13 +46,13 @@ clever_age_process: outputs: [read] read: - service: '@CleverAge\ProcessBundle\Task\File\Csv\InputCsvReaderTask' + task: input_csv_reader options: delimiter: '{{ delimiter }}' # Contextualized option, set from the launch form outputs: [log_line] log_line: - service: '@CleverAge\ProcessBundle\Task\Reporting\LoggerTask' + task: logger options: level: info message: 'Read line' diff --git a/docs/cookbooks/http_api_launch.md b/docs/cookbooks/http_api_launch.md index 0d16d96..fe1ce55 100644 --- a/docs/cookbooks/http_api_launch.md +++ b/docs/cookbooks/http_api_launch.md @@ -18,7 +18,7 @@ clever_age_process: target: Logs tasks: request: - service: '@CleverAge\RestProcessBundle\Task\RequestTask' + task: rest_request options: client: apicarto_ign url: '/codes-postaux/communes/{codePostal}' @@ -27,14 +27,14 @@ clever_age_process: outputs: [decode] decode: - service: '@CleverAge\ProcessBundle\Task\TransformerTask' + task: transformer options: transformers: json_decode: ~ # Generic transformer defined in the application outputs: [log] log: - service: '@CleverAge\ProcessBundle\Task\Reporting\LoggerTask' + task: logger options: level: info message: 'Communes fetched' diff --git a/docs/cookbooks/scheduled_process.md b/docs/cookbooks/scheduled_process.md index 7579182..3b25607 100644 --- a/docs/cookbooks/scheduled_process.md +++ b/docs/cookbooks/scheduled_process.md @@ -22,7 +22,7 @@ clever_age_process: value: King tasks: read: - service: '@CleverAge\DoctrineProcessBundle\Task\EntityManager\DoctrineReaderTask' + task: doctrine_reader options: class_name: 'App\Entity\Author' criteria: @@ -30,13 +30,13 @@ clever_age_process: outputs: [log, remove] log: - service: '@CleverAge\ProcessBundle\Task\Reporting\LoggerTask' + task: logger options: level: warning # Counted in the execution report message: 'Removing author' remove: - service: '@CleverAge\DoctrineProcessBundle\Task\EntityManager\DoctrineRemoverTask' + task: doctrine_remover ``` Then, in the UI, open "Process > Scheduler" and create a schedule: diff --git a/docs/reference/01-bundle_configuration.md b/docs/reference/01-bundle_configuration.md index c7c2bfa..f1072d8 100644 --- a/docs/reference/01-bundle_configuration.md +++ b/docs/reference/01-bundle_configuration.md @@ -98,7 +98,7 @@ Container parameters |-----------------------------------------|-------------------------------------------|-------------| | `cleverage_ui_process.upload_directory` | `%kernel.project_dir%/var/storage/uploads` | Directory where files uploaded from the launch form or the [HTTP API](06-http_api.md) are stored before being passed as process input. | | `cleverage_ui_process.delete_uploaded_files` | `true` | Delete the uploaded file once the process has been executed (successfully or not), by the Messenger handler or by the HTTP API when the process is not queued. Only the files of `cleverage_ui_process.upload_directory` are deleted. Set it to `false` to keep them, e.g. when a process stores the path of its input. | -| `upload_directory` | `%cleverage_ui_process.upload_directory%` | Deprecated since 3.3, removed in 4.0: use `cleverage_ui_process.upload_directory`. When your application still sets it, its value is used (unless `cleverage_ui_process.upload_directory` is also set), with a deprecation. | +| `upload_directory` | `%cleverage_ui_process.upload_directory%` | Deprecated since 3.3, removed in 4.0: use `cleverage_ui_process.upload_directory`. When your application still sets it, its value is used, with a deprecation. If your application has its own `upload_directory` parameter (e.g. for another bundle), also set `cleverage_ui_process.upload_directory`: the bundle then leaves `upload_directory` alone, without deprecation. | It can be overridden in your application: diff --git a/docs/reference/05-scheduler.md b/docs/reference/05-scheduler.md index a2481e7..aa419e6 100644 --- a/docs/reference/05-scheduler.md +++ b/docs/reference/05-scheduler.md @@ -25,7 +25,7 @@ How it works - The bundle registers a schedule provider named `cron` (`CleverAge\UiProcessBundle\Scheduler\CronScheduler`), so Symfony creates the `scheduler_cron` transport. It builds a recurring message for each valid and enabled - `ProcessSchedule`. Invalid schedules are skipped and logged (`info` level, `scheduler` channel). + `ProcessSchedule`. Invalid schedules are skipped and logged (`info` level, `scheduler` channel); a schedule that cannot be added (e.g. a duplicate, an expression refused by the Scheduler component) is logged at the `critical` level. - When a schedule is due, the `scheduler_cron` worker receives a `CronProcessMessage`. It reads the schedule again from the database: if it has been disabled or deleted since, the process is not run (logged, `info` level, `scheduler` channel). Otherwise, it dispatches a `ProcessExecuteMessage` (with the current schedule input and diff --git a/src/Controller/Admin/ProcessExecutionCrudController.php b/src/Controller/Admin/ProcessExecutionCrudController.php index 1cabe83..a065a6f 100644 --- a/src/Controller/Admin/ProcessExecutionCrudController.php +++ b/src/Controller/Admin/ProcessExecutionCrudController.php @@ -46,17 +46,20 @@ class ProcessExecutionCrudController extends AbstractCrudController { /** - * @param TranslatorInterface $translator deprecated, no longer used (the duration format is defined in the - * admin/field/duration.html.twig template), will be removed in 4.0 - * @param int $staleAfter seconds without heartbeat after which a started execution is considered - * as not responding + * @param TranslatorInterface|null $translator deprecated since 3.3, no longer used (the duration format is defined in + * the admin/field/duration.html.twig template), will be removed in 4.0 + * @param int $staleAfter seconds without heartbeat after which a started execution is + * considered as not responding */ - public function __construct(// @phpstan-ignore constructor.unusedParameter ($translator deprecated, kept for BC) + public function __construct( private readonly ProcessExecutionRepository $processExecutionRepository, private readonly string $logDirectory, - TranslatorInterface $translator, + ?TranslatorInterface $translator = null, private readonly int $staleAfter = 900, ) { + if ($translator instanceof TranslatorInterface) { + trigger_deprecation('cleverage/ui-process-bundle', '3.3', 'Passing a translator to "%s::__construct()" is deprecated, it is not used. The argument will be removed in 4.0.', self::class); + } } public static function getEntityFqcn(): string diff --git a/src/DependencyInjection/Compiler/UploadDirectoryParameterPass.php b/src/DependencyInjection/Compiler/UploadDirectoryParameterPass.php index 406b8e7..ae6d183 100644 --- a/src/DependencyInjection/Compiler/UploadDirectoryParameterPass.php +++ b/src/DependencyInjection/Compiler/UploadDirectoryParameterPass.php @@ -18,8 +18,9 @@ /** * The "upload_directory" parameter is deprecated since 3.3 for "cleverage_ui_process.upload_directory": when the - * application still overrides it, its value is used (unless the new parameter is also set), with a deprecation. - * Reading it is deprecated too. + * application still overrides it, its value is used, with a deprecation. Reading it is deprecated too. When the + * application also sets "cleverage_ui_process.upload_directory", its "upload_directory" parameter is its own (e.g. for + * another bundle): it is left alone, without deprecation. * * @internal */ @@ -40,9 +41,13 @@ public function process(ContainerBuilder $container): void } $value = $parameters[self::DEPRECATED_PARAMETER]; + if (self::DEPRECATED_DEFAULT_VALUE !== $value && self::DEFAULT_VALUE !== ($parameters[self::PARAMETER] ?? null)) { + // Both parameters are set: "upload_directory" is a parameter of the application, unrelated to the bundle + return; + } if (self::DEPRECATED_DEFAULT_VALUE !== $value) { trigger_deprecation('cleverage/ui-process-bundle', '3.3', 'Setting the "%s" parameter is deprecated, set "%s" instead. It will be ignored in 4.0.', self::DEPRECATED_PARAMETER, self::PARAMETER); - if (\is_string($value) && self::DEFAULT_VALUE === ($parameters[self::PARAMETER] ?? null)) { + if (\is_string($value)) { $container->setParameter(self::PARAMETER, $value); } } diff --git a/tests/Controller/Admin/ProcessExecutionCrudControllerTest.php b/tests/Controller/Admin/ProcessExecutionCrudControllerTest.php new file mode 100644 index 0000000..7ef77ae --- /dev/null +++ b/tests/Controller/Admin/ProcessExecutionCrudControllerTest.php @@ -0,0 +1,45 @@ +createStub(ProcessExecutionRepository::class), '/logs', $this->createStub(TranslatorInterface::class)); + new ProcessExecutionCrudController($this->createStub(ProcessExecutionRepository::class), '/logs'); + } finally { + restore_error_handler(); + } + + self::assertSame( + ['Since cleverage/ui-process-bundle 3.3: Passing a translator to "'.ProcessExecutionCrudController::class.'::__construct()" is deprecated, it is not used. The argument will be removed in 4.0.'], + $deprecations + ); + } +} diff --git a/tests/DependencyInjection/Compiler/UploadDirectoryParameterPassTest.php b/tests/DependencyInjection/Compiler/UploadDirectoryParameterPassTest.php index d9c80d4..df86e65 100644 --- a/tests/DependencyInjection/Compiler/UploadDirectoryParameterPassTest.php +++ b/tests/DependencyInjection/Compiler/UploadDirectoryParameterPassTest.php @@ -33,11 +33,6 @@ public static function provideParameters(): iterable yield 'defaults' => [[], '/app/var/storage/uploads', []]; yield 'new parameter set' => [['cleverage_ui_process.upload_directory' => '/app/var/imports'], '/app/var/imports', []]; yield 'deprecated parameter set' => [['upload_directory' => '/app/var/legacy'], '/app/var/legacy', [self::SETTING_DEPRECATION]]; - yield 'both set: the new one wins' => [ - ['upload_directory' => '/app/var/legacy', 'cleverage_ui_process.upload_directory' => '/app/var/imports'], - '/app/var/imports', - [self::SETTING_DEPRECATION], - ]; } /** @@ -70,6 +65,23 @@ public function testProcess(array $applicationParameters, string $expectedDirect self::assertSame([self::READING_DEPRECATION], $deprecations); } + public function testAnApplicationParameterIsLeftAloneWhenBothAreSet(): void + { + $container = new ContainerBuilder(); + $container->setParameter(UploadDirectoryParameterPass::PARAMETER, '/app/var/imports'); + // e.g. a parameter of another bundle + $container->setParameter(UploadDirectoryParameterPass::DEPRECATED_PARAMETER, '/app/var/other'); + + $deprecations = $this->collectDeprecations(static function () use ($container): void { + (new UploadDirectoryParameterPass())->process($container); + $container->getParameter(UploadDirectoryParameterPass::DEPRECATED_PARAMETER); + }); + + self::assertSame([], $deprecations); + self::assertSame('/app/var/imports', $container->getParameter(UploadDirectoryParameterPass::PARAMETER)); + self::assertSame('/app/var/other', $container->getParameter(UploadDirectoryParameterPass::DEPRECATED_PARAMETER)); + } + public function testWithoutDeprecatedParameter(): void { $container = new ContainerBuilder();