diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index 29a954d8..942080db 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -33,7 +33,6 @@ use App\Lib\Enum\StatusEnum; use App\Model\Entity\Person; use App\Model\Entity\PersonRole; -use App\Model\Entity\Petition; use Cake\Collection\Collection; use Cake\Database\Connection; use Cake\Database\Expression\QueryExpression; @@ -47,6 +46,7 @@ class AttributeCollectorsTable extends Table { use \App\Lib\Traits\AutoViewVarsTrait; use \App\Lib\Traits\CoLinkTrait; + use \App\Lib\Traits\LabeledLogTrait; use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; diff --git a/app/src/Controller/PetitionsController.php b/app/src/Controller/PetitionsController.php index 9ebb4c4f..d6360cf8 100644 --- a/app/src/Controller/PetitionsController.php +++ b/app/src/Controller/PetitionsController.php @@ -149,10 +149,23 @@ public function finalize(string $id) { $op = 'finalize'; } + $resumeUrl = [ + 'plugin' => null, + 'controller' => 'petitions', + 'action' => 'resume', + (int)$id + ]; + try { if($op == 'finalize') { // Step 1 - $this->Petitions->finalizePlugins((int)$id); + try { + $this->Petitions->finalizePlugins((int)$id); + } catch (\Exception $e) { + $this->Flash->error($e->getMessage()); + // Get me back to the resume page + return $this->redirect($resumeUrl); + } // Next operation is assign $baseUrl['?']['op'] = 'assign'; diff --git a/app/src/Model/Table/NamesTable.php b/app/src/Model/Table/NamesTable.php index 32659839..dfd93d6f 100644 --- a/app/src/Model/Table/NamesTable.php +++ b/app/src/Model/Table/NamesTable.php @@ -253,33 +253,6 @@ public function primaryName(int $id, string $recordType='person') { } } - /** - * Check if the Person has a primary name - * - * @param int $id Record ID - * @param string $recordType Type of record to find primary name for, 'person' or 'external_identity' - * @return bool Name Entity - * @since COmanage Registry v5.1.0 - */ - - public function hasPrimaryName(int $id, string $recordType='person'): bool - { - if($recordType == 'person') { - // Return the Primary Name - - return $this->find() - ->where(['person_id' => $id, - 'primary_name' => true]) - ->count() > 0; - } else { - // Return the first name, whatever it is - - return $this->find() - ->where(['external_identity_id' => $id]) - ->count() > 0; - } - } - /** * Application Rule to determine if there is at least one Name associated * with the Person. @@ -478,13 +451,10 @@ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, { $name = [ 'person_id' => $personId, + // Set this to true and delegate the confirmation to the localAfterSave callback + 'primary_name' => true ]; - // Save the primary name - if(!$this->hasPrimaryName($personId)) { - $name['primary_name'] = true; - } - foreach($fields as $fld) { $name[$fld->column_name] = $fld->value; $name['type_id'] = $fld->enrollment_attribute->attribute_type; @@ -494,4 +464,4 @@ public function saveAttributes(int $personId, ?int $roleId, string $parentModel, $this->saveOrFail($this->newEntity($name)); return true; } -} \ No newline at end of file +} diff --git a/app/src/Model/Table/PetitionsTable.php b/app/src/Model/Table/PetitionsTable.php index 9540f2df..0a9c2d72 100644 --- a/app/src/Model/Table/PetitionsTable.php +++ b/app/src/Model/Table/PetitionsTable.php @@ -298,9 +298,10 @@ public function finalize(int $id) { /** * Perform Plugin finalization for a Petition. - * + * + * @param int $id Petition ID + * @throws \Exception * @since COmanage Registry v5.1.0 - * @param int $id Petition ID */ public function finalizePlugins(int $id) { @@ -376,7 +377,9 @@ public function finalizePlugins(int $id) { } } catch(\Exception $e) { - $this->llog('error', "Plugin " . $step->plugin . " error during finalization of petition " . $petition->id . ": " . $e->getMessage()); + $msg = "Plugin " . $step->plugin . " error during finalization of petition " . $petition->id ; + $this->llog('error', $msg . ": " . $e->getMessage()); + throw new \RuntimeException($msg); } } }