File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -14,11 +14,25 @@ enum MessageStatus: string
1414 case Suspended = 'suspended ' ;
1515 case Requeued = 'requeued ' ;
1616
17- public function isFinal (): bool
17+ /**
18+ * Allowed transitions for each state
19+ *
20+ * @return MessageStatus[]
21+ */
22+ public function allowedTransitions (): array
1823 {
1924 return match ($ this ) {
20- self ::Sent, self ::Suspended => true ,
21- default => false ,
25+ self ::Draft, self ::Suspended => [self ::Submitted],
26+ self ::Submitted => [self ::Prepared, self ::InProcess],
27+ self ::Prepared => [self ::InProcess],
28+ self ::InProcess => [self ::Sent, self ::Suspended],
29+ self ::Requeued => [self ::InProcess, self ::Suspended],
30+ self ::Sent => [],
2231 };
2332 }
33+
34+ public function canTransitionTo (self $ next ): bool
35+ {
36+ return in_array ($ next , $ this ->allowedTransitions (), true );
37+ }
2438}
Original file line number Diff line number Diff line change 44
55namespace PhpList \Core \Domain \Messaging \Service \Manager ;
66
7+ use InvalidArgumentException ;
78use PhpList \Core \Domain \Identity \Model \Administrator ;
89use PhpList \Core \Domain \Messaging \Model \Dto \MessageContext ;
910use PhpList \Core \Domain \Messaging \Model \Dto \MessageDtoInterface ;
@@ -45,6 +46,10 @@ public function updateMessage(
4546
4647 public function updateStatus (Message $ message , Message \MessageStatus $ status ): Message
4748 {
49+ if (!$ message ->getMetadata ()->getStatus ()->canTransitionTo ($ status )) {
50+ throw new InvalidArgumentException ('Invalid status transition ' );
51+ }
52+
4853 $ message ->getMetadata ()->setStatus ($ status );
4954 $ this ->messageRepository ->save ($ message );
5055
You can’t perform that action at this time.
0 commit comments