Skip to content

Commit

Permalink
Bug 16909: Koha::Patrons - Remove checkuniquemember
Browse files Browse the repository at this point in the history
C4::Members::checkuniquemember was not really nicely written, was only
used once and was not covered by tests.
I think it does not make sense to keep such complexity and have this
code in the subroutine/method.
Looking at this patch it seems that what this subroutine did can be done
easily in the pl script in few lines.

Test plan:
1/ Create 2 organisations with the same "surname": you should get a
warning.
2/ Create 2 patrons (non-organisation) with the same
surname/firstname/date of birth, you should get a warning

Signed-off-by: Marc Véron <veron@veron.ch>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
  • Loading branch information
joubu authored and kylemhall committed Jul 15, 2016
1 parent dc78583 commit 1c61729
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 52 deletions.
39 changes: 0 additions & 39 deletions C4/Members.pm
Expand Up @@ -1111,45 +1111,6 @@ sub GetBorNotifyAcctRecord {
return ( $total, \@acctlines, $numlines );
}

=head2 checkuniquemember (OUEST-PROVENCE)
($result,$categorycode) = &checkuniquemember($collectivity,$surname,$firstname,$dateofbirth);
Checks that a member exists or not in the database.
C<&result> is nonzero (=exist) or 0 (=does not exist)
C<&categorycode> is from categorycode table
C<&collectivity> is 1 (= we add a collectivity) or 0 (= we add a physical member)
C<&surname> is the surname
C<&firstname> is the firstname (only if collectivity=0)
C<&dateofbirth> is the date of birth in ISO format (only if collectivity=0)
=cut

# FIXME: This function is not legitimate. Multiple patrons might have the same first/last name and birthdate.
# This is especially true since first name is not even a required field.

sub checkuniquemember {
my ( $collectivity, $surname, $firstname, $dateofbirth ) = @_;
my $dbh = C4::Context->dbh;
my $request = ($collectivity) ?
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? " :
($dateofbirth) ?
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=? and dateofbirth=?" :
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
my $sth = $dbh->prepare($request);
if ($collectivity) {
$sth->execute( uc($surname) );
} elsif($dateofbirth){
$sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
}else{
$sth->execute( uc($surname), ucfirst($firstname));
}
my @data = $sth->fetchrow;
( $data[0] ) and return $data[0], $data[1];
return 0;
}

sub checkcardnumber {
my ( $cardnumber, $borrowernumber ) = @_;

Expand Down
22 changes: 9 additions & 13 deletions members/memberentry.pl
Expand Up @@ -220,22 +220,18 @@ BEGIN
}
}

#############test for member being unique #############
# Test uniqueness of surname, firstname and dateofbirth
if ( ( $op eq 'insert' ) and !$nodouble ) {
my $category_type_send;
if ( $category_type eq 'I' ) {
$category_type_send = $category_type;
my $conditions;
$conditions->{surname} = $newdata{surname} if $newdata{surname};
if ( $category_type ne 'I' ) {
$conditions->{firstname} = $newdata{firstname} if $newdata{firstname};
$conditions->{dateofbirth} = $newdata{dateofbirth} if $newdata{dateofbirth};
}
my $check_category; # recover the category code of the doublon suspect borrowers
# ($result,$categorycode) = checkuniquemember($collectivity,$surname,$firstname,$dateofbirth)
( $check_member, $check_category ) = checkuniquemember(
$category_type_send,
( $newdata{surname} ? $newdata{surname} : $data{surname} ),
( $newdata{firstname} ? $newdata{firstname} : $data{firstname} ),
( $newdata{dateofbirth} ? $newdata{dateofbirth} : $data{dateofbirth} )
);
if ( !$check_member ) {
my $patrons = Koha::Patrons->search($conditions);
if ( $patrons->count > 0) {
$nodouble = 1;
$check_member = $patrons->next->borrowernumber;
}
}

Expand Down

0 comments on commit 1c61729

Please sign in to comment.