diff --git a/app/src/Model/Table/PipelinesTable.php b/app/src/Model/Table/PipelinesTable.php index 69a4f680f..229c2c48e 100644 --- a/app/src/Model/Table/PipelinesTable.php +++ b/app/src/Model/Table/PipelinesTable.php @@ -652,21 +652,26 @@ public function execute( // Perform some record keeping if a new Reference Identifier was assigned if(!empty($newReferenceId) && ($newReferenceId !== $origReferenceId)) { - // Attach the Reference Identifier to the Person. Where we're creating a - // new Person, there won't be much else on the Person record at this point, - // but that will change quickly at step (4). - - $Identifiers = TableRegistry::getTableLocator()->get('Identifiers'); - - $rid = $Identifiers->newEntity([ - 'identifier' => $newReferenceId, - 'person_id' => $person->id, - 'type_id' => $Identifiers->Types->getTypeId($eis->co_id, 'Identifiers.type', 'reference'), - 'login' => false, - 'status' => SuspendableStatusEnum::Active - ]); - - $Identifiers->saveOrFail($rid); + if($personInfo['status'] == 'created') { + // Attach the Reference Identifier to the Person. Where we're creating a + // new Person, there won't be much else on the Person record at this point, + // but that will change quickly at step (4). + + $Identifiers = TableRegistry::getTableLocator()->get('Identifiers'); + + $rid = $Identifiers->newEntity([ + 'identifier' => $newReferenceId, + 'person_id' => $person->id, + 'type_id' => $Identifiers->Types->getTypeId($eis->co_id, 'Identifiers.type', 'reference'), + 'login' => false, + 'status' => SuspendableStatusEnum::Active + ]); + + $Identifiers->saveOrFail($rid); + } + // else we've matched an existing Person, so by definition the Reference Identifier + // is already on the Person record (and if we try to resave it we'll violate + // AR-Identifier-2). // We can now also record Reference ID history