Lines 49-69
sub new {
Link Here
|
49 |
my $type = ref($class) || $class; |
49 |
my $type = ref($class) || $class; |
50 |
my $self; |
50 |
my $self; |
51 |
|
51 |
|
|
|
52 |
# Return early if patron_id is undefined, empty, or whitespace-only |
53 |
if ( !defined $patron_id |
54 |
|| ( !ref($patron_id) && ( $patron_id eq '' || $patron_id =~ /^\s*$/ ) ) ) |
55 |
{ |
56 |
siplog( "LOG_DEBUG", "new ILS::Patron: empty or undefined patron_id" ); |
57 |
return; |
58 |
} |
59 |
|
52 |
my $patron; |
60 |
my $patron; |
53 |
if ( ref $patron_id eq "HASH" ) { |
61 |
if ( ref $patron_id eq "HASH" ) { |
54 |
if ( $patron_id->{borrowernumber} ) { |
62 |
|
55 |
$patron = Koha::Patrons->find( $patron_id->{borrowernumber} ); |
63 |
# Validate hash has at least one defined, non-empty value |
56 |
} elsif ( $patron_id->{cardnumber} ) { |
64 |
my $has_valid_key = 0; |
57 |
$patron = Koha::Patrons->find( { cardnumber => $patron_id->{cardnumber} } ); |
65 |
if ( defined $patron_id->{borrowernumber} && $patron_id->{borrowernumber} ne '' ) { |
58 |
} elsif ( $patron_id->{userid} ) { |
66 |
$patron = Koha::Patrons->find( $patron_id->{borrowernumber} ); |
59 |
$patron = Koha::Patrons->find( { userid => $patron_id->{userid} } ); |
67 |
$has_valid_key = 1; |
|
|
68 |
} elsif ( defined $patron_id->{cardnumber} && $patron_id->{cardnumber} ne '' ) { |
69 |
$patron = Koha::Patrons->find( { cardnumber => $patron_id->{cardnumber} } ); |
70 |
$has_valid_key = 1; |
71 |
} elsif ( defined $patron_id->{userid} && $patron_id->{userid} ne '' ) { |
72 |
$patron = Koha::Patrons->find( { userid => $patron_id->{userid} } ); |
73 |
$has_valid_key = 1; |
74 |
} |
75 |
|
76 |
# Return early if hashref has no valid search keys |
77 |
unless ($has_valid_key) { |
78 |
siplog( "LOG_DEBUG", "new ILS::Patron: hashref contains no valid search keys" ); |
79 |
return; |
60 |
} |
80 |
} |
61 |
} else { |
81 |
} else { |
62 |
$patron = Koha::Patrons->find_by_identifier($patron_id); |
82 |
$patron = Koha::Patrons->find_by_identifier($patron_id); |
63 |
} |
83 |
} |
64 |
|
84 |
|
65 |
unless ($patron) { |
85 |
unless ($patron) { |
66 |
siplog( "LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id ); |
86 |
|
|
|
87 |
# Format patron_id safely for logging |
88 |
my $patron_id_str = ref($patron_id) eq 'HASH' ? 'hashref' : $patron_id; |
89 |
siplog( "LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id_str ); |
67 |
return; |
90 |
return; |
68 |
} |
91 |
} |
69 |
$kp = $patron->unblessed; |
92 |
$kp = $patron->unblessed; |
70 |
- |
|
|