From 3443db832c83cd5d5f5b806e10dec15a1f8ebcae Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 9 Nov 2024 10:54:26 +0200 Subject: [PATCH] email do not set sent by if draft --- application/Espo/Entities/Email.php | 5 +++++ application/Espo/Repositories/Email.php | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/application/Espo/Entities/Email.php b/application/Espo/Entities/Email.php index 85e5354390..65ca1dba60 100644 --- a/application/Espo/Entities/Email.php +++ b/application/Espo/Entities/Email.php @@ -717,6 +717,11 @@ class Email extends Entity return $this->getValueObject('sentBy'); } + public function setSentBy(Link|User|null $sentBy): self + { + return $this->setRelatedLinkOrEntity('sentBy', $sentBy); + } + public function getGroupFolder(): ?Link { /** @var ?Link */ diff --git a/application/Espo/Repositories/Email.php b/application/Espo/Repositories/Email.php index 5b141b6b33..b998274e10 100644 --- a/application/Espo/Repositories/Email.php +++ b/application/Espo/Repositories/Email.php @@ -333,6 +333,7 @@ class Email extends Database implements $this->addUserByEmailAddressId($entity, $ids[0], true); if (!$entity->getSentBy()) { + /** @var UserEntity $user */ $user = $this->getEmailAddressRepository() ->getEntityByAddressId( $entity->get('fromEmailAddressId'), @@ -340,7 +341,8 @@ class Email extends Database implements true ); - if ($user) { + if ($user && $entity->getStatus() !== EmailEntity::STATUS_DRAFT) { + $entity->setSentBy($user); $entity->set('sentById', $user->getId()); } }