From 6f4460901bd6857c46a557ca7b03b4506cee1a08 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 13 Jul 2018 12:42:08 -0300 Subject: [PATCH] Bug 20443: Remove DeleteBorrowerAttributes This subroutine was only used once, easy to replace. SetBorrowerAttributes must replace the attributes for the ones logged-in user is allowed to edit, that's why we filter by the library limits Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Members/Attributes.pm | 40 ++++++--------------------------------- Koha/Patron/Attributes.pm | 2 +- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/C4/Members/Attributes.pm b/C4/Members/Attributes.pm index 96fb139410..d52584096c 100644 --- a/C4/Members/Attributes.pm +++ b/C4/Members/Attributes.pm @@ -128,7 +128,12 @@ sub SetBorrowerAttributes { my $dbh = C4::Context->dbh; - DeleteBorrowerAttributes( $borrowernumber, $no_branch_limit ); + my $attributes = Koha::Patrons->find($borrowernumber)->get_extended_attributes; + + unless ( $no_branch_limit ) { + $attributes = $attributes->filter_by_branch_limitations; + } + $attributes->delete; my $sth = $dbh->prepare("INSERT INTO borrower_attributes (borrowernumber, code, attribute) VALUES (?, ?, ?)"); @@ -142,39 +147,6 @@ sub SetBorrowerAttributes { return 1; # borrower attributes successfully set } -=head2 DeleteBorrowerAttributes - - DeleteBorrowerAttributes($borrowernumber); - -Delete borrower attributes for the patron identified by C<$borrowernumber>. - -=cut - -sub DeleteBorrowerAttributes { - my $borrowernumber = shift; - my $no_branch_limit = @_ ? shift : 0; - my $branch_limit = $no_branch_limit - ? 0 - : C4::Context->userenv ? C4::Context->userenv->{"branch"} : 0; - - my $dbh = C4::Context->dbh; - my $query = q{ - DELETE borrower_attributes FROM borrower_attributes - }; - - $query .= $branch_limit - ? q{ - LEFT JOIN borrower_attribute_types_branches ON bat_code = code - WHERE ( b_branchcode = ? OR b_branchcode IS NULL ) - AND borrowernumber = ? - } - : q{ - WHERE borrowernumber = ? - }; - - $dbh->do( $query, undef, $branch_limit ? $branch_limit : (), $borrowernumber ); -} - =head2 DeleteBorrowerAttribute DeleteBorrowerAttribute($borrowernumber, $attribute); diff --git a/Koha/Patron/Attributes.pm b/Koha/Patron/Attributes.pm index f7289a0be0..47ba594f74 100644 --- a/Koha/Patron/Attributes.pm +++ b/Koha/Patron/Attributes.pm @@ -41,7 +41,7 @@ my $attributes = Koha::Patron::Attributes->search( $params ); sub search { my ( $self, $params, $attributes ) = @_; - unless ( exists $attributes->{order_by} ) { $attributes->{order_by} = ['code', 'attribute'] } + unless ( exists $attributes->{order_by} ) { $attributes->{order_by} = ['me.code', 'attribute'] } return $self->SUPER::search( $params, $attributes ); } -- 2.39.5