Skip to content

EspoCRM – Open Source CRM Application

email update filter fix

Yuri Kuznetsov9404c1d1655a
diff --git a/application/Espo/Classes/FieldProcessing/Email/UserColumnsLoader.php b/application/Espo/Classes/FieldProcessing/Email/UserColumnsLoader.php
index f285e35eac..2682e80775 100644
--- a/application/Espo/Classes/FieldProcessing/Email/UserColumnsLoader.php
+++ b/application/Espo/Classes/FieldProcessing/Email/UserColumnsLoader.php
@@ -73,12 +73,18 @@ class UserColumnsLoader implements Loader
return;
}
- $entity->set([
+ $values = [
Email::USERS_COLUMN_IS_READ => $emailUser->get(Email::USERS_COLUMN_IS_READ),
Email::USERS_COLUMN_IS_IMPORTANT => $emailUser->get(Email::USERS_COLUMN_IS_IMPORTANT),
Email::USERS_COLUMN_IN_TRASH => $emailUser->get(Email::USERS_COLUMN_IN_TRASH),
Email::USERS_COLUMN_IN_ARCHIVE => $emailUser->get(Email::USERS_COLUMN_IN_ARCHIVE),
'isUsersSent' => $entity->getSentBy()?->getId() === $this->user->getId(),
- ]);
+ ];
+
+ $entity->setMultiple($values);
+
+ foreach ($values as $key => $value) {
+ $entity->setFetched($key, $value);
+ }
}
}
diff --git a/application/Espo/Classes/RecordHooks/Email/BeforeUpdate.php b/application/Espo/Classes/RecordHooks/Email/BeforeUpdate.php
index 8af5b4ee73..b522922afc 100644
--- a/application/Espo/Classes/RecordHooks/Email/BeforeUpdate.php
+++ b/application/Espo/Classes/RecordHooks/Email/BeforeUpdate.php
@@ -31,8 +31,10 @@ namespace Espo\Classes\RecordHooks\Email;
use Espo\Core\Mail\EmailSender;
use Espo\Core\Name\Field;
+use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Record\Hook\SaveHook;
use Espo\Core\Utils\FieldUtil;
+use Espo\Core\Utils\Metadata;
use Espo\Core\Utils\SystemUser;
use Espo\Entities\Email;
use Espo\Entities\User;
@@ -54,7 +56,8 @@ class BeforeUpdate implements SaveHook
public function __construct(
private User $user,
private EntityManager $entityManager,
- private FieldUtil $fieldUtil
+ private FieldUtil $fieldUtil,
+ private Metadata $metadata,
) {}
public function process(Entity $entity): void
@@ -125,18 +128,24 @@ class BeforeUpdate implements SaveHook
private function clearEntityForUpdate(Email $email): void
{
- $fieldDefsList = $this->entityManager
+ $entityDefs = $this->entityManager
->getDefs()
- ->getEntity(Email::ENTITY_TYPE)
- ->getFieldList();
+ ->getEntity(Email::ENTITY_TYPE);
- foreach ($fieldDefsList as $fieldDefs) {
+ foreach ($entityDefs->getFieldList() as $fieldDefs) {
$field = $fieldDefs->getName();
if ($fieldDefs->getParam('isCustom')) {
continue;
}
+ if (
+ $fieldDefs->getType() === FieldType::LINK_MULTIPLE &&
+ $this->metadata->get("entityDefs.Email.links.$field.isCustom")
+ ) {
+ continue;
+ }
+
if (in_array($field, $this->allowedForUpdateFieldList)) {
continue;
}
@@ -144,7 +153,9 @@ class BeforeUpdate implements SaveHook
$attributeList = $this->fieldUtil->getAttributeList(Email::ENTITY_TYPE, $field);
foreach ($attributeList as $attribute) {
- $email->clear($attribute);
+ if ($email->isAttributeChanged($attribute) && $email->isAttributeWritten($attribute)) {
+ $email->set($attribute, $email->getFetched($attribute));
+ }
}
}
}
diff --git a/application/Espo/Core/ORM/Entity.php b/application/Espo/Core/ORM/Entity.php
index 878fd05a92..99dfd9260f 100644
--- a/application/Espo/Core/ORM/Entity.php
+++ b/application/Espo/Core/ORM/Entity.php
@@ -95,7 +95,7 @@ class Entity extends BaseEntity
throw new LogicException("No entity-manager.");
}
- $toSetFetched = !$this->isNew() && !$this->hasFetched($idAttribute);
+ $toSetFetched = !$this->isNew() && !$this->isAttributeChanged($idAttribute);
if (!$parentId || !$parentType) {
/** @noinspection PhpRedundantOptionalArgumentInspection */
diff --git a/application/Espo/Entities/Email.php b/application/Espo/Entities/Email.php
index da2d043e9b..c84e11a872 100644
--- a/application/Espo/Entities/Email.php
+++ b/application/Espo/Entities/Email.php
@@ -126,6 +126,24 @@ class Email extends Entity
return parent::has($attribute);
}
+ public function getFetched(string $attribute): mixed
+ {
+ if ($attribute === 'subject') {
+ return $this->getFetched(Field::NAME);
+ }
+
+ return parent::getFetched($attribute);
+ }
+
+ public function isAttributeChanged(string $name): bool
+ {
+ if ($name === 'subject') {
+ $name = Field::NAME;
+ }
+
+ return parent::isAttributeChanged($name);
+ }
+
/** @noinspection PhpUnused */
protected function _setSubject(?string $value): void
{
diff --git a/application/Espo/Repositories/Email.php b/application/Espo/Repositories/Email.php
index 86b76d52d5..22790534ee 100644
--- a/application/Espo/Repositories/Email.php
+++ b/application/Espo/Repositories/Email.php
@@ -186,13 +186,21 @@ class Email extends Database implements
return;
}
+ $setFetched = !$entity->isAttributeChanged($type . 'EmailAddressesNames');
+
$addresses = [];
foreach (get_object_vars($names) as $address) {
$addresses[] = $address;
}
- $entity->set($type, implode(';', $addresses));
+ $value = implode(';', $addresses);
+
+ $entity->set($type, $value);
+
+ if ($setFetched) {
+ $entity->setFetched($type, $value);
+ }
}
/**
@@ -289,6 +297,10 @@ class Email extends Database implements
$entity->set('nameHash', $nameHash);
$entity->set('typeHash', $typeHash);
$entity->set('idHash', $idHash);
+
+ $entity->setFetched('nameHash', $nameHash);
+ $entity->setFetched('typeHash', $typeHash);
+ $entity->setFetched('idHash', $idHash);
}
/**