mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 11:33:49 +00:00
Merge remote-tracking branch 'origin/master' into rector/rules-up-to-php80
Conflicts: src/Bundle/ChillActivityBundle/Controller/ActivityController.php src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php src/Bundle/ChillActivityBundle/Menu/PersonMenuBuilder.php src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php src/Bundle/ChillCalendarBundle/Command/MapAndSubscribeUserCalendarCommand.php src/Bundle/ChillCalendarBundle/RemoteCalendar/Connector/MSGraph/MSGraphUserRepository.php src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php src/Bundle/ChillEventBundle/Search/EventSearch.php src/Bundle/ChillMainBundle/Controller/ExportController.php src/Bundle/ChillMainBundle/Controller/PermissionsGroupController.php src/Bundle/ChillMainBundle/Cron/CronManager.php src/Bundle/ChillMainBundle/Entity/CronJobExecution.php src/Bundle/ChillMainBundle/Export/ExportManager.php src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php src/Bundle/ChillMainBundle/Repository/NotificationRepository.php src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperFactory.php src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php src/Bundle/ChillPersonBundle/Controller/SocialWorkSocialActionApiController.php src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/AgeAggregator.php src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodVoter.php src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php src/Bundle/ChillReportBundle/DataFixtures/ORM/LoadReports.php src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php
This commit is contained in:
@@ -39,7 +39,10 @@ class UserRefEventSubscriber implements EventSubscriberInterface
|
||||
|
||||
public function onStateEntered(EnteredEvent $enteredEvent): void
|
||||
{
|
||||
if ($enteredEvent->getMarking()->has(AccompanyingPeriod::STEP_CONFIRMED)) {
|
||||
if (
|
||||
$enteredEvent->getMarking()->has(AccompanyingPeriod::STEP_CONFIRMED)
|
||||
and $enteredEvent->getTransition()->getName() === 'confirm'
|
||||
) {
|
||||
$this->onPeriodConfirmed($enteredEvent->getSubject());
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,48 @@
|
||||
<?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\MainBundle\Cron\CronJobInterface;
|
||||
use Chill\MainBundle\Entity\CronJobExecution;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
|
||||
readonly class AccompanyingPeriodStepChangeCronjob implements CronJobInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ClockInterface $clock,
|
||||
private AccompanyingPeriodStepChangeRequestor $requestor,
|
||||
) {
|
||||
}
|
||||
|
||||
public function canRun(?CronJobExecution $cronJobExecution): bool
|
||||
{
|
||||
$now = $this->clock->now();
|
||||
|
||||
if (null !== $cronJobExecution && $now->sub(new \DateInterval('P1D')) < $cronJobExecution->getLastStart()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array((int) $now->format('H'), [1, 2, 3, 4, 5, 6], true);
|
||||
}
|
||||
|
||||
public function getKey(): string
|
||||
{
|
||||
return 'accompanying-period-step-change';
|
||||
}
|
||||
|
||||
public function run(array $lastExecutionData): null|array
|
||||
{
|
||||
($this->requestor)();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
<?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\Repository\AccompanyingPeriodRepository;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
#[AsMessageHandler]
|
||||
class AccompanyingPeriodStepChangeMessageHandler implements MessageHandlerInterface
|
||||
{
|
||||
private const LOG_PREFIX = '[accompanying period step change message handler] ';
|
||||
|
||||
public function __construct(
|
||||
private AccompanyingPeriodRepository $accompanyingPeriodRepository,
|
||||
private AccompanyingPeriodStepChanger $changer,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(AccompanyingPeriodStepChangeRequestMessage $message): void
|
||||
{
|
||||
if (null === $period = $this->accompanyingPeriodRepository->find($message->getPeriodId())) {
|
||||
throw new \RuntimeException(self::LOG_PREFIX . 'Could not find period with this id: '. $message->getPeriodId());
|
||||
}
|
||||
|
||||
($this->changer)($period, $message->getTransition());
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Message which will request a change in the step of accompanying period
|
||||
*/
|
||||
class AccompanyingPeriodStepChangeRequestMessage
|
||||
{
|
||||
private int $periodId;
|
||||
|
||||
public function __construct(
|
||||
AccompanyingPeriod|int $period,
|
||||
private string $transition,
|
||||
) {
|
||||
if (is_int($period)) {
|
||||
$this->periodId = $period;
|
||||
} else {
|
||||
if (null !== $id = $period->getId()) {
|
||||
$this->periodId = $id;
|
||||
}
|
||||
|
||||
throw new \LogicException("This AccompanyingPeriod does not have and id yet");
|
||||
}
|
||||
}
|
||||
|
||||
public function getPeriodId(): int
|
||||
{
|
||||
return $this->periodId;
|
||||
}
|
||||
|
||||
public function getTransition(): string
|
||||
{
|
||||
return $this->transition;
|
||||
}
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
<?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 Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodInfoRepositoryInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
/**
|
||||
* Gather all the accompanying period which needs a change in step
|
||||
*/
|
||||
class AccompanyingPeriodStepChangeRequestor
|
||||
{
|
||||
private \DateInterval $intervalForShortInactive;
|
||||
|
||||
private \DateInterval $intervalForLongInactive;
|
||||
|
||||
private bool $isMarkInactive;
|
||||
|
||||
public function __construct(
|
||||
private AccompanyingPeriodInfoRepositoryInterface $accompanyingPeriodInfoRepository,
|
||||
private LoggerInterface $logger,
|
||||
private MessageBusInterface $messageBus,
|
||||
ParameterBagInterface $parameterBag,
|
||||
) {
|
||||
$config = $parameterBag->get('chill_person')['accompanying_period_lifecycle_delays'];
|
||||
$this->isMarkInactive = $config['mark_inactive'];
|
||||
$this->intervalForShortInactive = new \DateInterval($config['mark_inactive_short_after']);
|
||||
$this->intervalForLongInactive = new \DateInterval($config['mark_inactive_long_after']);
|
||||
}
|
||||
|
||||
public function __invoke(): void
|
||||
{
|
||||
if (!$this->isMarkInactive) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the oldest ones first
|
||||
foreach (
|
||||
$olders = $this->accompanyingPeriodInfoRepository->findAccompanyingPeriodIdInactiveAfter(
|
||||
$this->intervalForLongInactive,
|
||||
[AccompanyingPeriod::STEP_CONFIRMED, AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT]
|
||||
) as $accompanyingPeriodId
|
||||
) {
|
||||
$this->logger->debug('request mark period as inactive_short', ['period' => $accompanyingPeriodId]);
|
||||
$this->messageBus->dispatch(new AccompanyingPeriodStepChangeRequestMessage($accompanyingPeriodId, 'mark_inactive_long'));
|
||||
}
|
||||
|
||||
// the newest
|
||||
foreach (
|
||||
$this->accompanyingPeriodInfoRepository->findAccompanyingPeriodIdInactiveAfter(
|
||||
$this->intervalForShortInactive,
|
||||
[AccompanyingPeriod::STEP_CONFIRMED]
|
||||
) as $accompanyingPeriodId
|
||||
) {
|
||||
if (in_array($accompanyingPeriodId, $olders, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->logger->debug('request mark period as inactive_long', ['period' => $accompanyingPeriodId]);
|
||||
$this->messageBus->dispatch(new AccompanyingPeriodStepChangeRequestMessage($accompanyingPeriodId, 'mark_inactive_short'));
|
||||
}
|
||||
|
||||
// a new event has been created => remove inactive long, or short
|
||||
foreach (
|
||||
$this->accompanyingPeriodInfoRepository->findAccompanyingPeriodIdActiveSince(
|
||||
$this->intervalForShortInactive,
|
||||
[AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT, AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG]
|
||||
) as $accompanyingPeriodId
|
||||
) {
|
||||
$this->logger->debug('request mark period as active', ['period' => $accompanyingPeriodId]);
|
||||
$this->messageBus->dispatch(new AccompanyingPeriodStepChangeRequestMessage($accompanyingPeriodId, 'mark_active'));
|
||||
}
|
||||
}
|
||||
}
|
@@ -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