mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
fix cs
This commit is contained in:
@@ -16,16 +16,16 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepRepository;
|
||||
use Chill\MainBundle\Templating\UI\NotificationCounterInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Workflow\Event\Event;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
final class WorkflowByUserCounter implements NotificationCounterInterface, EventSubscriberInterface
|
||||
{
|
||||
private EntityWorkflowStepRepository $workflowStepRepository;
|
||||
|
||||
private CacheItemPoolInterface $cacheItemPool;
|
||||
|
||||
private EntityWorkflowStepRepository $workflowStepRepository;
|
||||
|
||||
public function __construct(EntityWorkflowStepRepository $workflowStepRepository, CacheItemPoolInterface $cacheItemPool)
|
||||
{
|
||||
$this->workflowStepRepository = $workflowStepRepository;
|
||||
@@ -54,14 +54,21 @@ final class WorkflowByUserCounter implements NotificationCounterInterface, Event
|
||||
return $nb;
|
||||
}
|
||||
|
||||
public static function generateCacheKeyWorkflowByUser(User $user): string
|
||||
{
|
||||
return 'chill_main_workflow_by_u_' . $user->getId();
|
||||
}
|
||||
|
||||
public function getCountUnreadByUser(User $user): int
|
||||
{
|
||||
return $this->workflowStepRepository->countUnreadByUser($user);
|
||||
}
|
||||
|
||||
public static function generateCacheKeyWorkflowByUser(User $user): string
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return 'chill_main_workflow_by_u_'.$user->getId();
|
||||
return [
|
||||
'workflow.leave' => 'resetWorkflowCache',
|
||||
];
|
||||
}
|
||||
|
||||
public function resetWorkflowCache(Event $event): void
|
||||
@@ -74,11 +81,12 @@ final class WorkflowByUserCounter implements NotificationCounterInterface, Event
|
||||
$entityWorkflow = $event->getSubject();
|
||||
$step = $entityWorkflow->getCurrentStep();
|
||||
|
||||
if ($step === null) {
|
||||
if (null === $step) {
|
||||
return;
|
||||
}
|
||||
|
||||
$keys = [];
|
||||
|
||||
foreach ($step->getDestUser() as $user) {
|
||||
$keys[] = self::generateCacheKeyWorkflowByUser($user);
|
||||
}
|
||||
@@ -86,15 +94,5 @@ final class WorkflowByUserCounter implements NotificationCounterInterface, Event
|
||||
if ([] !== $keys) {
|
||||
$this->cacheItemPool->deleteItems($keys);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'workflow.leave' => 'resetWorkflowCache',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user