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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Latest
------

## Changes
* [#190](https://github.com/cleverage/ui-process-bundle/issues/190) Add aliases named after their class to `ProcessExecutionManager`, `ProcessConfigurationsManager`, `ProcessExecutionRepository` and `ProcessScheduleRepository` (as the Monolog handlers): they can be autowired. Update documentation, add tests.
* [#192](https://github.com/cleverage/ui-process-bundle/issues/192) The controllers and the HTTP value resolver are defined explicitly, without autowiring nor autoconfiguration (Symfony best practices for bundles, as [cleverage/process-bundle#149](https://github.com/cleverage/process-bundle/issues/149)): same arguments, tags and calls. The `$context` binding of the controllers no longer registers the `AdminContextFactory` service for the `AdminContext $context` arguments of the EasyAdmin actions (never used: EasyAdmin resolves the context first). Add tests.
* [#187](https://github.com/cleverage/ui-process-bundle/issues/187) Composer: require PHP `^8.2` instead of `>=8.2` (PHP 9 is no longer accepted before being tested), remove the authorization of the `symfony/flex` plugin, which is not required (the CI installs it globally), as [cleverage/process-bundle#319](https://github.com/cleverage/process-bundle/issues/319).
* [#181](https://github.com/cleverage/ui-process-bundle/issues/181) Fix the deprecations revealed by the tests, which now fail on deprecations: `ProcessExecutionRepository::getLastProcessExecution()` passes the `\SortDirection` enum to `orderBy()` when doctrine/orm accepts it (3.7 or later, where a string direction is deprecated, [#152](https://github.com/cleverage/ui-process-bundle/issues/152)); `ProcessExecutionRepository::hasLogs()` counts the log records without an arbitrary join (`WITH` deprecated by doctrine/orm 3.7, same result); the date filters of the log records (`createdAt`) and of the process executions (`startDate`) use the `single_text` widget (not configuring it is deprecated by Symfony 6.4, already the default since Symfony 7.0); `User::eraseCredentials()` is marked `#[\Deprecated]`, as required by Symfony 7.3 (with Symfony 6.4 and PHP 8.4 or later, which still call it, set `security.erase_credentials: false` to avoid the deprecation).
Expand Down
4 changes: 4 additions & 0 deletions config/services/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ services:
- '@cleverage_ui_process.repository.process_execution'
tags:
- { name: kernel.reset, method: reset }
CleverAge\UiProcessBundle\Manager\ProcessExecutionManager:
alias: cleverage_ui_process.manager.process_execution

cleverage_ui_process.manager.process_configuration:
class: CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager
public: false
arguments:
- '@cleverage_process.registry.process_configuration'
CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager:
alias: cleverage_ui_process.manager.process_configuration

cleverage_ui_process.stop_checker.process_execution:
class: CleverAge\UiProcessBundle\StopChecker\ProcessExecutionStopChecker
Expand Down
4 changes: 4 additions & 0 deletions config/services/repository.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ services:
arguments:
- '@doctrine.orm.entity_manager'
- '@doctrine'
CleverAge\UiProcessBundle\Repository\ProcessExecutionRepository:
alias: cleverage_ui_process.repository.process_execution

cleverage_ui_process.repository.process_schedule:
class: CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository
public: false
arguments:
- '@doctrine.orm.entity_manager'
CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository:
alias: cleverage_ui_process.repository.process_schedule
28 changes: 28 additions & 0 deletions docs/reference/04-process_executions_and_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,34 @@ When a log record has a level greater than or equal to `report_increment_level`
execution report, e.g. `{"Warning": 12, "Error": 1}`. This gives an overview of the problems of an execution
without opening its logs.

### In your code

The services of the bundle can be autowired by their class name:

| Class | Service | Usage |
|-------------------------------------------------------------------|------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `CleverAge\UiProcessBundle\Manager\ProcessExecutionManager` | `cleverage_ui_process.manager.process_execution` | Execution of the running process: `getCurrentProcessExecution()`, `increment('<key>')` / `setReport('<key>', '<value>')` to add your own entries to its report. |
| `CleverAge\UiProcessBundle\Repository\ProcessExecutionRepository` | `cleverage_ui_process.repository.process_execution` | `getLastProcessExecution('<process code>')`: last execution of a process. |
| `CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository` | `cleverage_ui_process.repository.process_schedule` | `findEnabled()`: enabled [schedules](05-scheduler.md). |
| `CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager` | `cleverage_ui_process.manager.process_configuration` | `getPublicProcesses()`, `getPrivateProcesses()` and the resolved [UI options](02-process_ui_options.md) of a process (`getUiOptions('<process code>')`). |

```php
use CleverAge\UiProcessBundle\Manager\ProcessExecutionManager;

final class MyService
{
public function __construct(private readonly ProcessExecutionManager $processExecutionManager)
{
}

public function doSomething(): void
{
// Counted in the report of the running execution (nothing happens outside of a process)
$this->processExecutionManager->increment('imported');
}
}
```

Logs
----

Expand Down
35 changes: 35 additions & 0 deletions tests/DependencyInjection/CleverAgeUiProcessExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
use CleverAge\UiProcessBundle\DependencyInjection\CleverAgeUiProcessExtension;
use CleverAge\UiProcessBundle\DependencyInjection\Configuration;
use CleverAge\UiProcessBundle\Entity\User;
use CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager;
use CleverAge\UiProcessBundle\Manager\ProcessExecutionManager;
use CleverAge\UiProcessBundle\Message\ProcessExecuteMessage;
use CleverAge\UiProcessBundle\Monolog\Handler\DoctrineProcessHandler;
use CleverAge\UiProcessBundle\Monolog\Handler\ProcessHandler;
use CleverAge\UiProcessBundle\Notifier\NotificationTrigger;
use CleverAge\UiProcessBundle\Repository\ProcessExecutionRepository;
use CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\UsesClass;
Expand Down Expand Up @@ -159,6 +165,35 @@ public function testLoadWithDefaultConfiguration(): void
);
}

/**
* @return iterable<string, array{class-string, string}>
*/
public static function provideAutowiringAliases(): iterable
{
yield 'process execution manager' => [ProcessExecutionManager::class, 'cleverage_ui_process.manager.process_execution'];
yield 'process configurations manager' => [ProcessConfigurationsManager::class, 'cleverage_ui_process.manager.process_configuration'];
yield 'process execution repository' => [ProcessExecutionRepository::class, 'cleverage_ui_process.repository.process_execution'];
yield 'process schedule repository' => [ProcessScheduleRepository::class, 'cleverage_ui_process.repository.process_schedule'];
yield 'process handler' => [ProcessHandler::class, 'cleverage_ui_process.monolog_handler.process'];
yield 'doctrine process handler' => [DoctrineProcessHandler::class, 'cleverage_ui_process.monolog_handler.doctrine_process'];
}

/**
* @param class-string $class
*/
#[DataProvider('provideAutowiringAliases')]
public function testServiceCanBeAutowired(string $class, string $id): void
{
$container = $this->createContainer('prod');
(new CleverAgeUiProcessExtension())->load([], $container);

// Private alias named after the class of the service
$alias = $container->getAlias($class);
self::assertSame($id, (string) $alias);
self::assertFalse($alias->isPublic());
self::assertSame($class, $container->getDefinition($id)->getClass());
}

/**
* @return iterable<string, array{string, mixed}>
*/
Expand Down
Loading