Bugzilla – Attachment 47478 Details for
Bug 10612
Add ability to delete patrons with batch patron deletion tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10612 - Add ability to delete patrons with batch patron deletion tool
Bug-10612---Add-ability-to-delete-patrons-with-bat.patch (text/plain), 14.86 KB, created by
Nick Clemens (kidclamp)
on 2016-01-29 20:36:42 UTC
(
hide
)
Description:
Bug 10612 - Add ability to delete patrons with batch patron deletion tool
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2016-01-29 20:36:42 UTC
Size:
14.86 KB
patch
obsolete
>From 0d8a6a7aa06b9939d36b9224d4d24df7323390e4 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >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. > >This is a squash of previous patches but now adds a patron_list_id >parameter to C4::Members::GetBorrowersToExpunge and uses that routine to >fetch patrons from a list. > >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 >5) Verify previous functionality has not changed >--- > C4/Members.pm | 14 +++++ > .../prog/en/modules/patron_lists/lists.tt | 24 +++++++- > .../prog/en/modules/tools/cleanborrowers.tt | 30 +++++++--- > tools/cleanborrowers.pl | 69 ++++++++++++++-------- > 4 files changed, 101 insertions(+), 36 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index 4ba1f19..b3af388 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -40,6 +40,7 @@ use Koha::Borrower::Debarments qw(IsDebarred); > use Text::Unaccent qw( unac_string ); > use Koha::AuthUtils qw(hash_password); > use Koha::Database; >+use Koha::List::Patron; > > use Module::Load::Conditional qw( can_load ); > if ( ! can_load( modules => { 'Koha::NorwegianPatronDB' => undef } ) ) { >@@ -1977,6 +1978,7 @@ sub GetHideLostItemsPreference { > not_borrowered_since => $not_borrowered_since, > expired_before => $expired_before, > category_code => $category_code, >+ patron_list_id => $patron_list_id, > branchcode => $branchcode > ); > >@@ -1985,8 +1987,20 @@ sub GetHideLostItemsPreference { > =cut > > sub GetBorrowersToExpunge { >+ > my $params = shift; > >+ if ( $params->{'patron_list_id'} ) { >+ my $patron_list_id = $params->{'patron_list_id'}; >+ my @patron_list = GetPatronLists( {patron_list_id=>$patron_list_id}); >+ my @patron_list_patrons = $patron_list[0]->patron_list_patrons(); >+ my $issues; >+ @patron_list_patrons = map { >+ (undef, $issues, undef) = GetMemberIssuesAndFines( $_->{borrowernumber} || $_->get_column('borrowernumber') ); >+ ($issues != 0) ? (): ($_); >+ } @patron_list_patrons; >+ return \@patron_list_patrons; >+ } > my $filterdate = $params->{'not_borrowered_since'}; > my $filterexpiry = $params->{'expired_before'}; > my $filtercategory = $params->{'category_code'}; >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 c16d6d1..804ec9f 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 >@@ -47,6 +47,12 @@ > <th> </th> > <th> </th> > <th> </th> >+ [% IF CAN_user_tools_edit_patrons %] >+ <th> </th> >+ [% END %] >+ [% IF CAN_user_tools_delete_anonymize_patrons %] >+ <th> </th> >+ [% END %] > </tr> > </thead> > >@@ -57,7 +63,7 @@ > <td>[% l.patron_list_patrons_rs.count || 0 %]</td> > <td> > <a class="btn btn-mini" href="list.pl?patron_list_id=[% l.patron_list_id %]"> >- <i class="fa fa-plus-sign"></i> Add patrons <i class="fa fa-user"></i> >+ <i class="fa fa-plus"></i> Add patrons</i> > </a> > </td> > <td> >@@ -72,9 +78,23 @@ > </td> > <td> > <a class="btn btn-mini" href="#" onclick='GB_showCenter(_("Print patron cards from list"), "/cgi-bin/koha/patroncards/print.pl?patronlist_id=[% l.patron_list_id %]", 400, 800);return false;'> >- <i class="icon-print"></i> Print patron cards >+ <i class="fa fa-print"></i> Print patron cards > </a> > </td> >+ [% IF CAN_user_tools_edit_patrons %] >+ <td> >+ <a class="btn btn-mini" href="/cgi-bin/koha/tools/modborrowers.pl?patron_list_id=[% l.patron_list_id %]&op=show"> >+ <i class="fa fa-edit"></i> Edit patrons</i> >+ </a> >+ </td> >+ [% END %] >+ [% IF CAN_user_tools_delete_anonymize_patrons %] >+ <td> >+ <a class="btn btn-mini" href="/cgi-bin/koha/tools/cleanborrowers.pl?step=2&patron_list_id=[% l.patron_list_id %]"> >+ <i class="fa fa-trash"></i> Delete patrons</i> >+ </a> >+ </td> >+ [% END %] > </tr> > [% END %] > </tbody> >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 388da10..ee13a72 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt >@@ -12,7 +12,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; > } >@@ -88,8 +88,21 @@ > [% END %] > </select> > </li> >+ [% IF patron_lists %] >+ <li> >+ <label for="patron_list_id"><strong>Or</strong> use a patron list: </label> >+ <select id="patron_list_id" name="patron_list_id"> >+ <option value=""></option> >+ [% FOREACH pl IN patron_lists %] >+ <option value="[% pl.patron_list_id %]">[% pl.name %]</option> >+ [% END %] >+ </select> >+ <span class="hint">If using a patron list, no other criteria will be used.</span> >+ </li> >+ [% END %] > </ul> > </fieldset> >+ > <fieldset> > <legend>Anonymize checkout history</legend> > [% UNLESS Koha.Preference('AnonymousPatron') %] >@@ -121,12 +134,12 @@ > <fieldset> > <legend>Warnings</legend> > <ul> >- <li>[% IF ( totalToDelete ) %][% totalToDelete %] [% ELSE %]0 [% END %] patrons will be deleted</li> >- <li>[% IF ( totalToAnonymize ) %][% totalToAnonymize %] [% ELSE %]0 [% END %] checkout history will be anonymized</li> >+ <li>[% patrons_to_delete.size || 0 %] patrons will be deleted</li> >+ <li>[% patrons_to_anonymize.size || 0 %] patron's checkout histories will be anonymized</li> > </ul> > > <br /> >- [% IF ( totalToDelete ) %] >+ [% IF patrons_to_delete.size %] > <fieldset><legend>What do you want to do for deleted patrons?</legend> > <input id="delete" type="radio" name="radio" value="delete" /> > <label for="delete">Permanently delete these patrons</label> >@@ -136,12 +149,12 @@ > > <br /><input id="testrun" type="radio" name="radio" value="testrun" checked="checked" /> > <label for="testrun">Do not remove any patrons (test run)</label> >- <input type="hidden" name="do_delete" value="[% totalToDelete %]" /></fieldset> >+ <input type="hidden" name="do_delete" value="[% patrons_to_delete.size %]" /></fieldset> > > [% END %] >- [% IF ( totalToAnonymize ) %] >- Checkout history for [% totalToAnonymize %] patrons will be anonymized >- <input type="hidden" name="do_anonym" value="[% totalToAnonymize %]" /> >+ [% IF patrons_to_anonymize.size %] >+ Checkout history for [% patrons_to_anonymize.size %] patrons will be anonymized >+ <input type="hidden" name="do_anonym" value="[% patrons_to_anonymize.size %]" /> > [% END %] > > <input type="hidden" name="step" value="3" /> >@@ -149,6 +162,7 @@ > <input type="hidden" name="last_issue_date" value="[% last_issue_date | $KohaDates %]" /> > <input type="hidden" name="borrower_dateexpiry" value="[% borrower_dateexpiry | $KohaDates %]" /> > <input type="hidden" name="borrower_categorycode" value="[% borrower_categorycode %]" /> >+ <input type="hidden" name="patron_list_id" value="[% patron_list_id %]" /> > </fieldset> > <fieldset class="action"><input type="submit" value="Finish" /> <a class="cancel" href="/cgi-bin/koha/tools/cleanborrowers.pl">Cancel</a></fieldset> > </form> >diff --git a/tools/cleanborrowers.pl b/tools/cleanborrowers.pl >index 7888b99..5bfbf7d 100755 >--- a/tools/cleanborrowers.pl >+++ b/tools/cleanborrowers.pl >@@ -40,7 +40,9 @@ use C4::Output; > use C4::Members; # GetBorrowersWhoHavexxxBorrowed. > use C4::Circulation; # AnonymiseIssueHistory. > 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; > >@@ -63,6 +65,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{}; > >@@ -80,28 +83,28 @@ if ( $step == 2 ) { > > my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'}; > >- my $totalDel; >- my $membersToDelete; >+ my $patrons_to_delete; > if ( $checkboxes{borrower} ) { >- $membersToDelete = GetBorrowersToExpunge( >- _get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) >+ $patrons_to_delete = GetBorrowersToExpunge( >+ _get_selection_params( >+ $not_borrowered_since, >+ $borrower_dateexpiry, >+ $borrower_categorycode, >+ $patron_list_id, >+ ) > ); >- _skip_borrowers_with_nonzero_balance( $membersToDelete ); >- $totalDel = scalar @$membersToDelete; >+ } >+ _skip_borrowers_with_nonzero_balance($patrons_to_delete); > >- } >- my $totalAno; >- my $membersToAnonymize; >+ my $members_to_anonymize; > if ( $checkboxes{issue} ) { >- $membersToAnonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); >- $totalAno = scalar @$membersToAnonymize; >+ $members_to_anonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); > } > > $template->param( >- totalToDelete => $totalDel, >- totalToAnonymize => $totalAno, >- memberstodelete_list => $membersToDelete, >- memberstoanonymize_list => $membersToAnonymize, >+ patrons_to_delete => $patrons_to_delete, >+ patrons_to_anonymize => $members_to_anonymize, >+ patron_list_id => $patron_list_id, > ); > } > >@@ -113,18 +116,23 @@ 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 ); >- $totalDel = scalar(@$membersToDelete); >+ my $patrons_to_delete = GetBorrowersToExpunge( >+ _get_selection_params( >+ $not_borrowered_since, $borrower_dateexpiry, >+ $borrower_categorycode, $patron_list_id >+ ) >+ ); >+ _skip_borrowers_with_nonzero_balance($patrons_to_delete); >+ >+ $totalDel = scalar(@$patrons_to_delete); > $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::Members::HandleDelBorrower( $borrowernumber ); >- DelMember( $borrowernumber ); >+ my $borrowernumber = $patrons_to_delete->[$i]->{'borrowernumber'} >+ || $patrons_to_delete->[$i]->get_column('borrowernumber'); >+ $radio eq 'trash' && MoveMemberToDeleted($borrowernumber); >+ C4::Members::HandleDelBorrower($borrowernumber); >+ DelMember($borrowernumber); > } > $template->param( > do_delete => '1', >@@ -145,6 +153,14 @@ elsif ( $step == 3 ) { > trash => ( $radio eq "trash" ) ? (1) : (0), > testrun => ( $radio eq "testrun" ) ? 1: 0, > ); >+} else { # $step == 1 >+ my @all_lists = GetPatronLists(); >+ my @non_empty_lists; >+ foreach my $list (@all_lists){ >+ my @patrons = $list->patron_list_patrons(); >+ if( scalar @patrons ) { push(@non_empty_lists,$list) } >+ } >+ $template->param( patron_lists => [ @non_empty_lists ] ); > } > > $template->param( >@@ -163,13 +179,13 @@ 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; > } > > sub _get_selection_params { >- my ($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) = @_; >+ my ($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode, $patron_list_id) = @_; > > my $params = {}; > $params->{not_borrowered_since} = output_pref({ >@@ -183,6 +199,7 @@ sub _get_selection_params { > dateonly => 1 > }) if $borrower_dateexpiry; > $params->{category_code} = $borrower_categorycode if $borrower_categorycode; >+ $params->{patron_list_id} = $patron_list_id if $patron_list_id; > > return $params; > }; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10612
:
19766
|
19767
|
21081
|
21444
|
21445
|
21446
|
22837
|
22838
|
28779
|
28780
|
36311
|
36313
|
36314
|
36315
|
41289
|
41363
|
41364
|
41365
|
46239
|
46279
|
46280
|
46834
|
47153
|
47224
|
47225
|
47226
|
47255
|
47259
|
47393
|
47394
|
47395
|
47396
|
47478
|
48833
|
48881
|
48888
|
48890
|
48891
|
48892
|
49596
|
49597
|
49607
|
49694
|
49740
|
49741
|
49766
|
49767
|
49768
|
49769
|
49770