This commit is contained in:
Yuri Kuznetsov
2025-06-25 10:42:31 +03:00
parent bedf805456
commit 09b94de327
12 changed files with 84 additions and 35 deletions
@@ -29,6 +29,7 @@
namespace Espo\Core\FieldProcessing\EmailAddress;
use Espo\Core\Name\Link;
use Espo\Core\ORM\Repository\Option\SaveOption;
use Espo\Core\ORM\Type\FieldType;
use Espo\Entities\EmailAddress;
@@ -50,6 +51,8 @@ class Saver implements SaverInterface
private const ATTR_EMAIL_ADDRESS_IS_OPTED_OUT = 'emailAddressIsOptedOut';
private const ATTR_EMAIL_ADDRESS_IS_INVALID = 'emailAddressIsInvalid';
private const LINK_EMAIL_ADDRESSES = Link::EMAIL_ADDRESSES;
public function __construct(
private EntityManager $entityManager,
private ApplicationState $applicationState,
@@ -421,7 +424,7 @@ class Saver implements SaverInterface
if ($emailAddressOld) {
$this->entityManager
->getRelation($entity, 'emailAddresses')
->getRelation($entity, self::LINK_EMAIL_ADDRESSES)
->unrelate($emailAddressOld, [SaveOption::SKIP_HOOKS => true]);
}
}
@@ -493,13 +496,13 @@ class Saver implements SaverInterface
if ($emailAddressOld) {
$entityRepository
->getRelation($entity, 'emailAddresses')
->getRelation($entity, self::LINK_EMAIL_ADDRESSES)
->unrelate($emailAddressOld, [SaveOption::SKIP_HOOKS => true]);
}
}
$entityRepository
->getRelation($entity, 'emailAddresses')
->getRelation($entity, self::LINK_EMAIL_ADDRESSES)
->relate($emailAddressNew, null, [SaveOption::SKIP_HOOKS => true]);
if ($entity->has(self::ATTR_EMAIL_ADDRESS_IS_OPTED_OUT)) {