diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index 6c9ee2f8c..08776fcba 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -343,7 +343,7 @@ class WorkflowController extends AbstractController $this->entityManager->flush(); - if ($onHoldStep) { + if (null !== $onHoldStep) { $this->entityManager->remove($onHoldStep); } diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowOnHoldController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowOnHoldController.php index 36c419e79..75c9fd380 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowOnHoldController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowOnHoldController.php @@ -1,16 +1,26 @@ getCurrentStep(); $currentUser = $this->security->getUser(); + if (!$currentUser instanceof User) { + throw new AccessDeniedHttpException('only user can put a workflow on hold'); + } + $workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName()); $enabledTransitions = $workflow->getEnabledTransitions($entityWorkflow); - if (!count($enabledTransitions) > 0) { + if (0 === count($enabledTransitions)) { throw $this->createAccessDeniedException('You are not allowed to apply any transitions to this workflow, therefore you cannot toggle the hold status.'); } @@ -64,5 +78,4 @@ class WorkflowOnHoldController extends AbstractController return $this->redirectToRoute('chill_main_workflow_show', ['id' => $entityWorkflow->getId()]); } - } diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStepHold.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStepHold.php index 47ae0f954..3f4aeb669 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStepHold.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStepHold.php @@ -26,21 +26,13 @@ class EntityWorkflowStepHold implements TrackCreationInterface #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)] - private ?int $id; + private ?int $id = null; - #[ORM\ManyToOne(targetEntity: EntityWorkflowStep::class)] - #[ORM\JoinColumn(nullable: false)] - private EntityWorkflowStep $step; - - #[ORM\ManyToOne(targetEntity: User::class)] - #[ORM\JoinColumn(nullable: false)] - private User $byUser; - - public function __construct(EntityWorkflowStep $step, User $byUser) - { - $this->step = $step; - $this->byUser = $byUser; - } + public function __construct(#[ORM\ManyToOne(targetEntity: EntityWorkflowStep::class)] + #[ORM\JoinColumn(nullable: false)] + private EntityWorkflowStep $step, #[ORM\ManyToOne(targetEntity: User::class)] + #[ORM\JoinColumn(nullable: false)] + private User $byUser) {} public function getId(): ?int { diff --git a/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowStepHoldRepository.php b/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowStepHoldRepository.php index 4b6cc7d1c..7ef877181 100644 --- a/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowStepHoldRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowStepHoldRepository.php @@ -19,12 +19,10 @@ use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NoResultException; use Doctrine\Persistence\ManagerRegistry; -use Symfony\Component\Workflow\Workflow; /** * @template-extends ServiceEntityRepository */ - class EntityWorkflowStepHoldRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) @@ -92,7 +90,7 @@ class EntityWorkflowStepHoldRepository extends ServiceEntityRepository ->setParameter('user', $user) ->getQuery() ->getSingleResult(); - } catch (NoResultException $e) { + } catch (NoResultException) { return null; } } diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowOnHoldControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowOnHoldControllerTest.php index 8c06e9f90..f4788c2ec 100644 --- a/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowOnHoldControllerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowOnHoldControllerTest.php @@ -1,5 +1,14 @@