email update filter fix
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user