Skip to content

Commit

Permalink
Create person role record only if valid attributes are present (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis authored Apr 18, 2026
1 parent 9ffc7ca commit f6b952b
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f6b952b

Please sign in to comment.