Skip to content

Commit 722068c

Browse files
author
vlad
committed
fix bug while canceling sending of message
1 parent 3a087e1 commit 722068c

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/Doctrine/StateMachineExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait StateMachineExtension
1515
private function isValidChangeState(array $stateMachine, $currentState, $newState)
1616
{
1717
if (isset($stateMachine[$currentState])) {
18-
if (isset($stateMachine[$currentState][$newState])) {
18+
if (key_exists($newState, $stateMachine[$currentState])) {
1919
return true;
2020
}
2121
} else {

src/Domain/Message/MessageManager.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ public function cancelSending(Message $message): MessageScheduledEvent
9090
$this->entityManager->beginTransaction();
9191

9292
if (!$message->isValidNewStatus(Message::STATUS_CANCELED)) {
93-
throw new LogicException('Status is not valid');
93+
throw new LogicException(sprintf(
94+
'Status of the message is not valid. Current "%s", need "%s"',
95+
$message->getStatus(),
96+
Message::STATUS_CANCELED
97+
));
9498
}
9599

96100
$message->setStatus(Message::STATUS_CANCELED);
@@ -105,7 +109,7 @@ public function cancelSending(Message $message): MessageScheduledEvent
105109

106110
} catch (LogicException $e) {
107111
$this->entityManager->rollback();
108-
$m = sprintf('Logic was violated %s', $e->getMessage());
112+
$m = sprintf('Logic was violated. %s', $e->getMessage());
109113
$this->logger->warning($m, ['exception' => $e, 'method' => __METHOD__, 'entityId' => $message->getId()]);
110114
throw new MessageManagerException($m);
111115

src/Service/TaskService/TaskService.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ public function cancel(string $taskType, int $entityId): TaskCanceledEvent
9696
throw new EntityNotFoundException('Task does not exist');
9797
}
9898

99-
if ($task->isValidNewStatus(Task::STATUS_CANCELED)) {
100-
throw new LogicException('Status is not valid');
99+
if (!$task->isValidNewStatus(Task::STATUS_CANCELED)) {
100+
throw new LogicException(sprintf(
101+
'Status of the task is not valid. Current "%s", need "%s"',
102+
$task->getStatus(),
103+
Task::STATUS_CANCELED
104+
));
101105
}
102106

103107
$task->setStatus(Task::STATUS_CANCELED);
@@ -139,8 +143,12 @@ public function onTaskExecuteEvent(TaskExecuteEvent $event): void
139143
return;
140144
}
141145

142-
if ($task->isValidNewStatus(Task::STATUS_COMPLETED)) {
143-
throw new LogicException('Status is not valid');
146+
if (!$task->isValidNewStatus(Task::STATUS_COMPLETED)) {
147+
throw new LogicException(sprintf(
148+
'Status of the task is not valid. Current "%s", need "%s"',
149+
$task->getStatus(),
150+
Task::STATUS_COMPLETED
151+
));
144152
}
145153

146154
$task->setStatus(Task::STATUS_COMPLETED);

0 commit comments

Comments
 (0)