Skip to content

EspoCRM – Open Source CRM Application

do not set person name unless all fields are present

Yuri Kuznetsov5e7a089cb043
diff --git a/application/Espo/Core/Entities/Person.php b/application/Espo/Core/Entities/Person.php
index 50825340f1..daeeef6832 100644
--- a/application/Espo/Core/Entities/Person.php
+++ b/application/Espo/Core/Entities/Person.php
@@ -71,6 +71,10 @@ class Person extends Entity
{
$this->setInContainer('lastName', $value);
+ if (!$this->helper->hasAllPersonNameAttributes($this, 'name')) {
+ return;
+ }
+
$name = $this->helper->formatPersonName($this, 'name');
$this->setInContainer(Field::NAME, $name);
@@ -84,6 +88,10 @@ class Person extends Entity
{
$this->setInContainer('firstName', $value);
+ if (!$this->helper->hasAllPersonNameAttributes($this, 'name')) {
+ return;
+ }
+
$name = $this->helper->formatPersonName($this, 'name');
$this->setInContainer(Field::NAME, $name);
@@ -97,6 +105,10 @@ class Person extends Entity
{
$this->setInContainer('middleName', $value);
+ if (!$this->helper->hasAllPersonNameAttributes($this, 'name')) {
+ return;
+ }
+
$name = $this->helper->formatPersonName($this, 'name');
$this->setInContainer(Field::NAME, $name);
diff --git a/application/Espo/Core/ORM/Helper.php b/application/Espo/Core/ORM/Helper.php
index 7bd0e068cf..0b0cb5f721 100644
--- a/application/Espo/Core/ORM/Helper.php
+++ b/application/Espo/Core/ORM/Helper.php
@@ -41,6 +41,41 @@ class Helper
public function __construct(private Config $config)
{}
+ /**
+ * @internal
+ */
+ public function hasAllPersonNameAttributes(Entity $entity, string $field): bool
+ {
+ $format = $this->config->get('personNameFormat');
+
+ $firstName = 'first' . ucfirst($field);
+ $lastName = 'last' . ucfirst($field);
+ $middleName = 'middle' . ucfirst($field);
+
+ $attributes = [
+ $firstName,
+ $lastName,
+ ];
+
+ if (
+ $format === self::FORMAT_LAST_FIRST_MIDDLE ||
+ $format === self::FORMAT_FIRST_MIDDLE_LAST
+ ) {
+ $attributes[] = $middleName;
+ }
+
+ foreach ($attributes as $attribute) {
+ if (!$entity->has($attribute)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * @internal
+ */
public function formatPersonName(Entity $entity, string $field): ?string
{
$format = $this->config->get('personNameFormat');