mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Feature: Change accompanying period info step in a cronjob
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\AccompanyingPeriod\Lifecycle;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
|
||||
/**
|
||||
* Change the step of an accompanying period
|
||||
*
|
||||
* This should be invoked through scripts (not in the in context of an http request, or an
|
||||
* action from a user).
|
||||
*/
|
||||
class AccompanyingPeriodStepChanger
|
||||
{
|
||||
private const LOG_PREFIX = '[AccompanyingPeriodStepChanger] ';
|
||||
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private LoggerInterface $logger,
|
||||
private Registry $workflowRegistry,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(AccompanyingPeriod $period, string $transition, ?string $workflowName = null): void
|
||||
{
|
||||
$workflow = $this->workflowRegistry->get($period, $workflowName);
|
||||
|
||||
if (!$workflow->can($period, $transition)) {
|
||||
$this->logger->info(self::LOG_PREFIX . 'not able to apply the transition on period', [
|
||||
'period_id' => $period->getId(),
|
||||
'transition' => $transition
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$workflow->apply($period, $transition);
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->logger->info(self::LOG_PREFIX . 'could apply a transition', [
|
||||
'period_id' => $period->getId(),
|
||||
'transition' => $transition
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user