EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
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.phpindex 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.phpindex 7bd0e068cf..0b0cb5f721 100644--- a/application/Espo/Core/ORM/Helper.php+++ b/application/Espo/Core/ORM/Helper.php@@ -41,6 +41,41 @@ class Helperpublic 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');