source email id fix

This commit is contained in:
Yurii
2024-12-13 11:09:01 +02:00
parent 01c234970c
commit 660482f042
5 changed files with 30 additions and 18 deletions
@@ -29,6 +29,7 @@
namespace Espo\Modules\Crm\Classes\FieldProcessing\Meeting;
use Espo\Entities\Email;
use Espo\Modules\Crm\Entities\Meeting;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
@@ -55,7 +56,7 @@ class SourceEmailSaver implements Saver
return;
}
$email = $entity->getSourceEmail();
$email = $this->getEmail($entity);
if (!$email) {
return;
@@ -79,4 +80,15 @@ class SourceEmailSaver implements Saver
$this->entityManager->saveEntity($email);
}
private function getEmail(Meeting $entity): ?Email
{
$emailId = $entity->get('sourceEmailId');
if (!$emailId) {
return null;
}
return $this->entityManager->getRDBRepositoryByClass(Email::class)->getById($emailId);
}
}
@@ -187,10 +187,4 @@ class Meeting extends Entity
{
return $this->set('uid', $uid);
}
public function getSourceEmail(): ?Email
{
/** @var ?Email */
return $this->relations->getOne('sourceEmail');
}
}
@@ -32,8 +32,10 @@ namespace Espo\Modules\Crm\Hooks\Meeting;
use Espo\Core\Hook\Hook\BeforeSave;
use Espo\Core\Mail\Event\EventFactory;
use Espo\Core\Utils\Util;
use Espo\Entities\Email;
use Espo\Modules\Crm\Entities\Meeting;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Repository\Option\SaveOptions;
use ICal\ICal;
@@ -42,7 +44,7 @@ use ICal\ICal;
*/
class Uid implements BeforeSave
{
public function __construct() {}
public function __construct(private EntityManager $entityManager) {}
public function beforeSave(Entity $entity, SaveOptions $options): void
{
@@ -68,7 +70,7 @@ class Uid implements BeforeSave
private function getIcsUid(Meeting $entity): ?string
{
$email = $entity->getSourceEmail();
$email = $this->getEmail($entity);
if (!$email) {
return null;
@@ -88,4 +90,15 @@ class Uid implements BeforeSave
return $espoEvent->getUid();
}
private function getEmail(Meeting $entity): ?Email
{
$emailId = $entity->get('sourceEmailId');
if (!$emailId) {
return null;
}
return $this->entityManager->getRDBRepositoryByClass(Email::class)->getById($emailId);
}
}
@@ -19,9 +19,7 @@
"sourceEmail": "Source Email",
"uid": "UID"
},
"links": {
"sourceEmail": "Source Email"
},
"links": {},
"options": {
"status": {
"Planned": "Planned",
@@ -301,7 +301,7 @@
"layoutFiltersDisabled": true,
"exportDisabled": true,
"importDisabled": true,
"entity": "TargetList",
"entity": "Email",
"directAccessDisabled": true
},
"createdAt": {
@@ -411,11 +411,6 @@
"parent": {
"type": "belongsToParent",
"foreign": "meetings"
},
"sourceEmail": {
"type": "belongsTo",
"entity": "Email",
"noJoin": true
}
},
"collection": {