From f6b952ba2cdc1bbbac7ab59e4c362721eb5018a3 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sun, 19 Apr 2026 02:28:38 +0300 Subject: [PATCH] Create person role record only if valid attributes are present (#391) --- .../Model/Table/AttributeCollectorsTable.php | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index 2ddc16ebc..0ce5c1849 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -140,7 +140,6 @@ public function hydrate(int $id, \App\Model\Entity\Petition $petition): bool // Get the collection object $attributesCollection = new Collection($attributes); - /*********** PERSON ROLE ***************/ // Filter the Person Role Attributes and keep the field name $personRoleAttributes = (new Collection($supportedAttributes))->filter(function($attr, $key) { @@ -157,9 +156,11 @@ public function hydrate(int $id, \App\Model\Entity\Petition $petition): bool $cxn = $this->getConnection(); $cxn->begin(); - // Save the Person Role - $personRoleObj = TableRegistry::getTableLocator()->get('PersonRoles'); - $role = $personRoleObj->saveAttributeCollectorPetitionAttributes((int)$person->id, $fieldsForPersonRole); + // Save the Person Role only if we collected something meaningful for it, + if(!empty($fieldsForPersonRole)) { + $personRoleObj = TableRegistry::getTableLocator()->get('PersonRoles'); + $role = $personRoleObj->saveAttributeCollectorPetitionAttributes((int)$person->id, $fieldsForPersonRole); + } /********* MVEAS **************/ // Filter the MVEAS Attributes and keep the field name @@ -179,14 +180,17 @@ public function hydrate(int $id, \App\Model\Entity\Petition $petition): bool ); // MVEAs for Role - $this->handleMveaAttributes( - $person, - $role, - 'PersonRole', - $mveaAttributes, - $attributes, - $cxn - ); + // Save the MVEAs for the PersonRole only if we collected something meaningful for it, and the role was created + if(!empty($fieldsForPersonRole)) { + $this->handleMveaAttributes( + $person, + $role, + 'PersonRole', + $mveaAttributes, + $attributes, + $cxn + ); + } /****** PERSON ******/ // Keep the person attributes