Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion config/services/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']]
Expand Down
6 changes: 3 additions & 3 deletions docs/cookbooks/form_file_upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ 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'
context: ['input']
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'
Expand Down
6 changes: 3 additions & 3 deletions docs/cookbooks/http_api_launch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand All @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions docs/cookbooks/scheduled_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ clever_age_process:
value: King
tasks:
read:
service: '@CleverAge\DoctrineProcessBundle\Task\EntityManager\DoctrineReaderTask'
task: doctrine_reader
options:
class_name: 'App\Entity\Author'
criteria:
lastname: '{{ lastname }}' # Contextualized option, set by the schedule
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:
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/01-bundle_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/05-scheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions src/Controller/Admin/ProcessExecutionCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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);
}
}
Expand Down
45 changes: 45 additions & 0 deletions tests/Controller/Admin/ProcessExecutionCrudControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CleverAge/UiProcessBundle package.
*
* Copyright (c) Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CleverAge\UiProcessBundle\Tests\Controller\Admin;

use CleverAge\UiProcessBundle\Controller\Admin\ProcessExecutionCrudController;
use CleverAge\UiProcessBundle\Repository\ProcessExecutionRepository;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\Translation\TranslatorInterface;

#[CoversClass(ProcessExecutionCrudController::class)]
class ProcessExecutionCrudControllerTest extends TestCase
{
public function testPassingATranslatorIsDeprecated(): void
{
$deprecations = [];
set_error_handler(static function (int $level, string $message) use (&$deprecations): bool {
$deprecations[] = $message;

return true;
}, \E_USER_DEPRECATED);
try {
new ProcessExecutionCrudController($this->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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

/**
Expand Down Expand Up @@ -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();
Expand Down
Loading