diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php b/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php index 7dc36652cd..0124ecec77 100644 --- a/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php +++ b/application/Espo/Core/Formula/Functions/ExtGroup/SmsGroup/SendType.php @@ -77,12 +77,18 @@ class SendType extends BaseFunction implements try { $this->createSender()->send($sms); + + $this->entityManager->saveEntity($sms); } catch (Exception $e) { $message = $e->getMessage(); $this->log("Error while sending SMS. Message: {$message}." , 'error'); + $sms->setStatus(Sms::STATUS_FAILED); + + $this->entityManager->saveEntity($sms); + return false; } diff --git a/application/Espo/Entities/Sms.php b/application/Espo/Entities/Sms.php index 3062f64f55..c1abd3afb0 100644 --- a/application/Espo/Entities/Sms.php +++ b/application/Espo/Entities/Sms.php @@ -47,6 +47,8 @@ class Sms extends Entity implements SmsInterface public const STATUS_DRAFT = 'Draft'; + public const STATUS_FAILED = 'Failed'; + public function getDateSent(): ?DateTime { return $this->getValueObject('dateTime'); @@ -135,6 +137,13 @@ class Sms extends Entity implements SmsInterface return $this; } + public function setStatus(string $status): self + { + $this->set('status', $status); + + return $this; + } + private function getSmsRepository(): SmsRepository { /** @var SmsRepository */