diff --git a/Koha/Auth/Client/OAuth.pm b/Koha/Auth/Client/OAuth.pm index b6c90220a9..618b76162a 100644 --- a/Koha/Auth/Client/OAuth.pm +++ b/Koha/Auth/Client/OAuth.pm @@ -72,13 +72,7 @@ sub _get_data_and_patron { if defined $claim->{$pkey}; } - my $value = $mapped_data->{$matchpoint}; - - my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } ); - - if ( defined $value and $matchpoint_rs->count ) { - $patron = $matchpoint_rs->next; - } + $patron = $self->_find_patron_by_matchpoint( $matchpoint, $mapped_data->{$matchpoint} ); } if ( defined $config->{userinfo_url} ) { @@ -101,13 +95,7 @@ sub _get_data_and_patron { } unless ($patron) { - my $value = $mapped_data->{$matchpoint}; - - my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } ); - - if ( defined $value and $matchpoint_rs->count ) { - $patron = $matchpoint_rs->next; - } + $patron = $self->_find_patron_by_matchpoint( $matchpoint, $mapped_data->{$matchpoint} ); } } @@ -115,4 +103,23 @@ sub _get_data_and_patron { return ( $mapped_data, $patron ); } +=head3 _find_patron_by_matchpoint + + my $patron = $client->_find_patron_by_matchpoint( $matchpoint, $value ); + +Internal method to find a patron by the given matchpoint and value. +Returns the patron object if found, undef otherwise. + +=cut + +sub _find_patron_by_matchpoint { + my ( $self, $matchpoint, $value ) = @_; + + return unless defined $value; + + my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } ); + + return $matchpoint_rs->count ? $matchpoint_rs->next : undef; +} + 1;