From 83b917323b2c62813b078888593235af01ace50e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 11 Jun 2014 08:11:48 -0400 Subject: [PATCH] Bug 10612 - Add ability to delete patrons with batch patron deletion tool This patch adds the ability to select a patron list for deletetion when using the Batch patron deletion/anonymization tool. It also adds buttons to the the patron lists table to access both the batch deletion and batch modification directly from the lists view. Test Plan: 1) Apply this patch 2) Create a list of patrons with the new Patron Lists feature 3) Try using the batch edit link form the lists table 4) Try using the batch delete link from the lists table Signed-off-by: Nicole Signed-off-by: Jonathan Druart --- .../prog/en/modules/patron_lists/lists.tt | 20 +++++++ .../prog/en/modules/tools/cleanborrowers.tt | 30 +++++++--- tools/cleanborrowers.pl | 68 +++++++++++++++------- 3 files changed, 89 insertions(+), 29 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/lists.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/lists.tt index dc1160a..a0d0f81 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/lists.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/lists.tt @@ -45,6 +45,12 @@       + [% IF CAN_user_tools_edit_patrons %] +   + [% END %] + [% IF CAN_user_tools_delete_anonymize_patrons %] +   + [% END %] @@ -68,6 +74,20 @@ Delete + [% IF CAN_user_tools_edit_patrons %] + + + Edit patrons + + + [% END %] + [% IF CAN_user_tools_delete_anonymize_patrons %] + + + Delete patrons + + + [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt index bd505fb..97d5953 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt @@ -11,7 +11,7 @@ */ function checkForm(form) { if((form.checkbox[0].checked)){ - if ( (!form.date1.value) && (!form.borrower_dateexpiry.value) && (!form.borrower_categorycode.value) ){ + if ( (!form.date1.value) && (!form.borrower_dateexpiry.value) && (!form.borrower_categorycode.value) && (!form.patron_list_id.value)){ alert(_("Please enter at least one criterion for deletion!")); return false; } @@ -87,8 +87,21 @@ [% END %] + [% IF patron_lists %] +
  • + + + If using a patron list, no other criteria will be used. +
  • + [% END %] +
    Anonymize checkout history

    @@ -117,12 +130,12 @@
    Warnings
      -
    • [% IF ( totalToDelete ) %][% totalToDelete %] [% ELSE %]0 [% END %] patrons will be deleted
    • -
    • [% IF ( totalToAnonymize ) %][% totalToAnonymize %] [% ELSE %]0 [% END %] checkout history will be anonymized
    • +
    • [% memberstodelete_list.size || 0 %] patrons will be deleted
    • +
    • [% memberstoanonymize_list.size || 0 %] patron's checkout histories will be anonymized

    - [% IF ( totalToDelete ) %] + [% IF memberstodelete_list.size %]
    What do you want to do for deleted patrons? @@ -132,12 +145,12 @@
    -
    +
    [% END %] - [% IF ( totalToAnonymize ) %] - Checkout history for [% totalToAnonymize %] patrons will be anonymized - + [% IF memberstoanonymize_list.size %] + Checkout history for [% memberstoanonymize_list.size %] patrons will be anonymized + [% END %] @@ -145,6 +158,7 @@ + Cancel
    diff --git a/tools/cleanborrowers.pl b/tools/cleanborrowers.pl index d1fc01c..35bc9d9 100755 --- a/tools/cleanborrowers.pl +++ b/tools/cleanborrowers.pl @@ -41,7 +41,9 @@ use C4::Members; # GetBorrowersWhoHavexxxBorrowed. use C4::Circulation; # AnonymiseIssueHistory. use C4::VirtualShelves (); #no import use Koha::DateUtils qw( dt_from_string output_pref ); +use Koha::Database; use Date::Calc qw/Today Add_Delta_YM/; +use Koha::List::Patron; my $cgi = new CGI; @@ -64,6 +66,7 @@ my $borrower_dateexpiry = $params->{borrower_dateexpiry} ? dt_from_string $params->{borrower_dateexpiry} : undef; +my $patron_list_id = $params->{patron_list_id}; my $borrower_categorycode = $params->{'borrower_categorycode'} || q{}; @@ -81,28 +84,35 @@ if ( $step == 2 ) { my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'}; - my $totalDel; my $membersToDelete; - if ( $checkboxes{borrower} ) { - $membersToDelete = GetBorrowersToExpunge( - _get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) - ); - _skip_borrowers_with_nonzero_balance( $membersToDelete ); - $totalDel = scalar @$membersToDelete; - + if ($patron_list_id) { + my @patron_list_patrons = + Koha::Database->new()->schema()->resultset('PatronListPatron') + ->search( { patron_list_id => $patron_list_id } ); + $membersToDelete = \@patron_list_patrons; } - my $totalAno; + else { + if ( $checkboxes{borrower} ) { + $membersToDelete = GetBorrowersToExpunge( + _get_selection_params( + $not_borrowered_since, + $borrower_dateexpiry, + $borrower_categorycode, + ) + ); + } + } + _skip_borrowers_with_nonzero_balance($membersToDelete); + my $membersToAnonymize; if ( $checkboxes{issue} ) { $membersToAnonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); - $totalAno = scalar @$membersToAnonymize; } $template->param( - totalToDelete => $totalDel, - totalToAnonymize => $totalAno, memberstodelete_list => $membersToDelete, memberstoanonymize_list => $membersToAnonymize, + patron_list_id => $patron_list_id, ); } @@ -114,18 +124,32 @@ elsif ( $step == 3 ) { # delete members if ($do_delete) { - my $membersToDelete = GetBorrowersToExpunge( - _get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) - ); - _skip_borrowers_with_nonzero_balance( $membersToDelete ); + my $membersToDelete; + if ($patron_list_id) { + my @patron_list_patrons = + Koha::Database->new()->schema()->resultset('PatronListPatron') + ->search( { patron_list_id => $patron_list_id } ); + $membersToDelete = \@patron_list_patrons; + } + else { + $membersToDelete = GetBorrowersToExpunge( + _get_selection_params( + $not_borrowered_since, $borrower_dateexpiry, + $borrower_categorycode + ) + ); + } + _skip_borrowers_with_nonzero_balance($membersToDelete); + $totalDel = scalar(@$membersToDelete); $radio = $params->{'radio'}; for ( my $i = 0 ; $i < $totalDel ; $i++ ) { $radio eq 'testrun' && last; - my $borrowernumber = $membersToDelete->[$i]->{'borrowernumber'}; - $radio eq 'trash' && MoveMemberToDeleted( $borrowernumber ); - C4::VirtualShelves::HandleDelBorrower( $borrowernumber ); - DelMember( $borrowernumber ); + my $borrowernumber = $membersToDelete->[$i]->{'borrowernumber'} + || $membersToDelete->[$i]->get_column('borrowernumber'); + $radio eq 'trash' && MoveMemberToDeleted($borrowernumber); + C4::VirtualShelves::HandleDelBorrower($borrowernumber); + DelMember($borrowernumber); } $template->param( do_delete => '1', @@ -146,6 +170,8 @@ elsif ( $step == 3 ) { trash => ( $radio eq "trash" ) ? (1) : (0), testrun => ( $radio eq "testrun" ) ? 1: 0, ); +} else { # $step == 1 + $template->param( patron_lists => [ GetPatronLists() ] ); } $template->param( @@ -164,7 +190,7 @@ sub _skip_borrowers_with_nonzero_balance { my $borrowers = shift; my $balance; @$borrowers = map { - (undef, undef, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} ); + (undef, undef, $balance) = GetMemberIssuesAndFines( $_->{borrowernumber} || $_->get_column('borrowernumber') ); ($balance != 0) ? (): ($_); } @$borrowers; } -- 2.1.0