Skip to content

Commit

Permalink
Fix, partially, the AttributeCollectors finalize function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Feb 4, 2025
1 parent 7bbcd25 commit 28c2b3f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

namespace CoreEnroller\Model\Table;

use App\Model\Entity\Petition;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
Expand Down Expand Up @@ -117,21 +118,32 @@ public function initialize(array $config): void {

/**
* Perform steps necessary to finalize the Petition.
*
* @since COmanage Registry v5.0.0
* @param int $id Attribute Collector ID
* @param int $petitionId Petition ID
*
* @param int $id Attribute Collector ID
* @param Petition $petition
* @return bool true on success
* @since COmanage Registry v5.1.0
*/

public function finalize(int $id, int $petitionId) {
// XXX convert Petition Attributes to operational Attributes
// keep in mind this can be called multiple times if the plugin is
// instantiated more than once in the Enrollment Flow ($id will be different)
// any errors should be logged or otherwise managed, returning false
// or throwing an error will NOT prevent the petition from finalizing
public function finalize(int $id, \App\Model\Entity\Petition $petition) {
$cfg = $this->get($id);

if(empty($petition->enrollee_person_id)) {
throw new \InvalidArgumentException(__d('error', 'Petitions.enrollee.notfound', [$petition->id]));
}

$People = TableRegistry::getTableLocator()->get('People');

$person = $People->get($petition->enrollee_person_id);

$attributes = $this->EnrollmentAttributes
->PetitionAttributes
->find()
->where(['petition_id' => $petition->id])
->firstOrFail();

debug("in AttributeCollector finalize");
// XXX Should i save the primary name?
// XXX Should i save the email?
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function finalize(int $id, \App\Model\Entity\Petition $petition) {
// At this point there is a Person record allocated and stored in the Petition,
// but it doesn't have any attributes on it, including a Primary Name.
// We assume we're the only attribute collector, so we'll force a Primary Name
// based on the Basic Attribtues, and create a skeletal role.
// based on the Basic Attributes, and create a skeletal role.

if(empty($petition->enrollee_person_id)) {
throw new \InvalidArgumentException(__d('error', 'Petitions.enrollee.notfound', [$petition->id]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
// Each default value is mutually exclusive to the rest. We do not have to worry about a conflict.
$options['default'] = match(true) {
isset($attr->default_value) => $attr->default_value,
// XXX The $attr->default_value_env_name for the name attribute is tricky. Since the name has many values.
// Check the EnvSource plugin
isset($attr->default_value_env_name)
&& getenv($attr->default_value_env_name) !== false => getenv($attr->default_value_env_name),
isset($attr->default_value_datetime) => $attr->default_value_datetime,
Expand Down

0 comments on commit 28c2b3f

Please sign in to comment.