Skip to content

Commit

Permalink
lookupPersonByLogin vs lookupPersonForLogin fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis authored and arlen committed Sep 24, 2024
1 parent 42ee120 commit 23bac8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
7 changes: 6 additions & 1 deletion app/src/Lib/Traits/EnrollmentControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down
26 changes: 0 additions & 26 deletions app/src/Model/Table/IdentifiersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 23bac8d

Please sign in to comment.