From d1dea478f70a23ede5d518ad350b748efaf8a7e4 Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 17 Aug 2015 10:54:03 +0300 Subject: [PATCH] fix email notifications --- application/Espo/Core/Mail/Importer.php | 1 + application/Espo/Notificators/Email.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/application/Espo/Core/Mail/Importer.php b/application/Espo/Core/Mail/Importer.php index 643c109c45..b44c1dbd7c 100644 --- a/application/Espo/Core/Mail/Importer.php +++ b/application/Espo/Core/Mail/Importer.php @@ -99,6 +99,7 @@ class Importer $usersIds = $duplicate->get('usersIds'); $usersIds[] = $userId; $duplicate->set('usersIds', $usersIds); + $this->getEntityManager()->saveEntity($duplicate); if (!empty($teamsIds)) { diff --git a/application/Espo/Notificators/Email.php b/application/Espo/Notificators/Email.php index 6321b2cfbd..0369c9d2a6 100644 --- a/application/Espo/Notificators/Email.php +++ b/application/Espo/Notificators/Email.php @@ -43,13 +43,17 @@ class Email extends \Espo\Core\Notificators\Base public function process(Entity $entity) { - if ($entity->get('status') != 'Archived' && $entity->get('status') != 'Sent') { + if ($entity->get('status') !== 'Archived' && $entity->get('status') !== 'Sent') { return; } - $previousUserIdList = $entity->getFetched('usersIds'); - if (!is_array($previousUserIdList)) { + if ($entity->get('status') === 'Sent') { $previousUserIdList = []; + } else { + $previousUserIdList = $entity->getFetched('usersIds'); + if (!is_array($previousUserIdList)) { + $previousUserIdList = []; + } } $emailUserIdList = $entity->get('usersIds'); @@ -70,6 +74,10 @@ class Email extends \Espo\Core\Notificators\Base 'emailName' => $entity->get('name'), ); + if (!$entity->has('from')) { + $this->getEntityManager()->getRepository('Email')->loadFromField($entity); + } + $from = $entity->get('from'); if ($from) { $person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddress($from, null, ['User', 'Contact', 'Lead']);