From a730f47ceb7642c4faeea7d42a5f077ac5b8f5ee Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 5 Jan 2022 11:19:33 +0200 Subject: [PATCH 1/2] 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 */ From d725cce8a7baa4f4dae90877e6fb9734caa78412 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 5 Jan 2022 17:14:21 +0200 Subject: [PATCH 2/2] fix email to case attachments copy --- application/Espo/Controllers/Email.php | 4 +++- application/Espo/Services/Email.php | 18 +++++++++++++++--- client/src/views/email/detail.js | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/application/Espo/Controllers/Email.php b/application/Espo/Controllers/Email.php index 47892074b4..6aa940c6da 100644 --- a/application/Espo/Controllers/Email.php +++ b/application/Espo/Controllers/Email.php @@ -52,8 +52,10 @@ class Email extends Record } $id = $data->id; + $parentType = $data->parentType ?? null; + $field = $data->field ?? null; - return $this->getEmailService()->getCopiedAttachments($id); + return $this->getEmailService()->getCopiedAttachments($id, $parentType, null, $field); } /** diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index d0c4d053f0..6504ecbba9 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -767,8 +767,13 @@ class Email extends Record implements return $fromAddress; } - public function getCopiedAttachments(string $id, ?string $parentType = null, ?string $parentId = null): stdClass - { + public function getCopiedAttachments( + string $id, + ?string $parentType = null, + ?string $parentId = null, + ?string $field = null + ): stdClass { + $ids = []; $names = (object) []; @@ -806,8 +811,15 @@ class Email extends Record implements $attachment->set('sourceId', $source->getSourceId()); $attachment->set('storage', $source->get('storage')); - if (!empty($parentType) && !empty($parentId)) { + if ($field) { + $attachment->set('field', $field); + } + + if ($parentType) { $attachment->set('parentType', $parentType); + } + + if ($parentType && $parentType) { $attachment->set('parentId', $parentId); } diff --git a/client/src/views/email/detail.js b/client/src/views/email/detail.js index 4a30aec24c..b1cc513ace 100644 --- a/client/src/views/email/detail.js +++ b/client/src/views/email/detail.js @@ -255,6 +255,8 @@ define('views/email/detail', ['views/detail', 'email-helper'], function (Dep, Em this.ajaxPostRequest('Email/action/getCopiedAttachments', { id: this.model.id, + parentType: 'Case', + field: 'attachments', }).then(data => { attributes.attachmentsIds = data.ids; attributes.attachmentsNames = data.names;