From 71ac9f95494d7fcfa35cdec6a884582b38f41cc3 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 24 Sep 2024 10:01:38 +0300 Subject: [PATCH] lookupPersonByLogin vs lookupPersonForLogin fix --- .../Lib/Traits/EnrollmentControllerTrait.php | 7 ++++- app/src/Model/Table/IdentifiersTable.php | 26 ------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/app/src/Lib/Traits/EnrollmentControllerTrait.php b/app/src/Lib/Traits/EnrollmentControllerTrait.php index 6e0b4a6d6..5941528b4 100644 --- a/app/src/Lib/Traits/EnrollmentControllerTrait.php +++ b/app/src/Lib/Traits/EnrollmentControllerTrait.php @@ -29,6 +29,7 @@ namespace App\Lib\Traits; +use Cake\Datasource\Exception\RecordNotFoundException; use Cake\ORM\TableRegistry; use \App\Lib\Enum\EnrollmentActorEnum; use \App\Model\Entity\Petition; @@ -64,7 +65,11 @@ protected function getCurrentActor(?int $petitionId=null): array { $Identifiers = TableRegistry::getTableLocator()->get('Identifiers'); - $ret['person_id'] = $Identifiers->lookupPersonForLogin($ret['identifier'], $this->getCOID()); + try { + $ret['person_id'] = $Identifiers->lookupPersonByLogin($this->getCOID(), $ret['identifier']); + } catch(RecordNotFoundException $e) { + $ret['person_id'] = null; + } if(!empty($ret['person_id'])) { $ret['type'] = 'person'; diff --git a/app/src/Model/Table/IdentifiersTable.php b/app/src/Model/Table/IdentifiersTable.php index 6092c69a1..3d6312cb0 100644 --- a/app/src/Model/Table/IdentifiersTable.php +++ b/app/src/Model/Table/IdentifiersTable.php @@ -242,32 +242,6 @@ public function lookupPersonByLogin(int $coId, string $identifier): int { return $id->person_id; } - - /** - * Lookup a Person ID from a login identifier. Only active Identifiers can - * be used for lookups. - * - * @since COmanage Registry v5.0.0 - * @param string $identifier Identifier - * @param int $coId CO ID - * @return int Person ID or null - */ - - public function lookupPersonForLogin(string $identifier, int $coId): ?int { - $id = $this->find() - ->where([ - 'Identifiers.identifier' => $identifier, - 'Identifiers.status' => SuspendableStatusEnum::Active, - 'Identifiers.login' => true, - 'Identifiers.person_id IS NOT NULL' - ]) - ->matching('People', function ($q) use ($coId) { - return $q->where(['People.co_id' => $coId]); - }) - ->firstOrFail(); - - return $id->person_id ?? null; - } /** * Perform a keyword search.