From a730f47ceb7642c4faeea7d42a5f077ac5b8f5ee Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 5 Jan 2022 11:19:33 +0200 Subject: [PATCH] sms status update --- .../Formula/Functions/ExtGroup/SmsGroup/SendType.php | 6 ++++++ application/Espo/Entities/Sms.php | 9 +++++++++ 2 files changed, 15 insertions(+) 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 */