Koha/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt
Jacek Ablewicz 69216d2217 Bug 11352: fix unexpected data loss issues with batch patron deletion/anonymization
Batch patron deletion/anonymization tool has some issues:

1) If 'dateformat' setting in I18N/L10N system preferences is set
to anything other then 'iso' (eg. 'metric'), bulk deletion when using
'expiration date is before' criterion is not working properly. Date
entered in this field will be efectivelly ignored (or possibly
sometimes wrongly interpreted as different date, in other format)
on the final patron deletion stage. This may result in deleting
(or moving to trash) more borrower records then intended.
2) Bulk/batch patron deletion should skip borrowers with
nonzero account balance (ones with oustanding fines or credits)
3) This tool shouldn't offer to choose as deletion criterion
those patron categories which have category_type set to 'S'
(= staff patron categories)

This patch fixes above mentioned problems. It also adds an option
to "test run" patron batch deletion, and makes this option
the default choice in "warning" stage.

Test plan:
- prepare test database with some patron records (at least 2,
the more the better) set up in such a way that they will be vulnerable
to issues 1 & 2
- confirm issues 1,2
- restore test database
- apply patch
- ensure issues 1 & 2 are no longer present - first by using new "test
run" option: for #1, record counts in "warning" stage and "final" stage
should be now the same; for #2, observe that patron records with nonzero
balance are now excluded from deletion
- redo the tests, this time choosing "delete permanently" and "move
to trash" instead of "test run"
- test #3 by changing "Category type" to "S" in some
test patron categories - after that, those categories should no
longer be choosable as deletion criteria.

Signed-off-by: Magnus Enger <digitalutvikling@gmail.com>
Tested with dateformat = dd/mm/yyyy. I tested with two expired patrons,
one with fines and one without. Before the patch a lot of unexpected
patrons were deleted along with the expected ones. After
applying the patch only the expired patron was deleted, not the
one with fines. The test run and the "real" run reported correct numbers.

The patch also makes sure no patron categories with category_type = S
are suggested for batch deletion.

Note: The ergonomics of the "Batch delete/anonymize" tool is hardly
optimal, but this patch fixes a real, data-loosing bug, so let's
deal with the ergonomics later.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2014-03-22 13:55:28 +00:00

184 lines
7.7 KiB
Text

[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Tools &rsaquo; Batch patron deletion/anonymization [% IF ( step2 ) %]&rsaquo; Confirm[% END %][% IF ( step3 ) %]&rsaquo; Finished[% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
[% INCLUDE 'calendar.inc' %]
<script type="text/javascript">
// <![CDATA[
/**
* checkForm(form)
* This function check the form is correctly filled.
*/
function checkForm(form) {
if((form.checkbox[0].checked)){
if ( (!form.date1.value) && (!form.borrower_dateexpiry.value) && (!form.borrower_categorycode.value) ){
alert(_("Please enter at least one criterion for deletion!"));
return false;
}
}
if((form.checkbox[1].checked)){
if(!(form.date2.value)){
alert(_("please enter a date !"));
return false;
}
}
return true;
}
/**
* checkForm2(form)
* This function check the form2 is correctly filled.
*/
function checkForm2(form) {
return true;
}
// ]]>
</script>
</head>
<body id="tools_cleanborrowers" class="tools">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; [% IF ( step1 ) %]Clean Patron Records[% ELSE %]<a href="/cgi-bin/koha/tools/cleanborrowers.pl">Clean patron records</a> &rsaquo; [% END %][% IF ( step2 ) %]Confirm[% END %][% IF ( step3 ) %]Finished[% END %]</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<h1>Batch patron deletion/anonymization</h1>
<div class="help">
<p>This tool allows you to delete patrons and anonymize checkout history. For deleting patrons, any combination of limits can be used.</p>
</div>
[% IF ( step1 ) %]
<!-- step 1 START -->
<div id="step1">
<form name="f1" onsubmit="return checkForm(this);" action="/cgi-bin/koha/tools/cleanborrowers.pl" method="post">
<fieldset>
<legend>Delete patrons</legend>
<h3><input id="checkborrower" type="checkbox" name="checkbox" value="borrower" /><label for="checkborrower"> Verify you want to delete patrons</label></h3>
<br />
<h5>Delete patrons who meet the following criteria:</h5>
<ul>
<li>
<label for="date1">who have not borrowed since:</label>
<input size="10" id="date1" name="filterdate1" type="text" class="datepicker" />
<span class="hint">[% INCLUDE 'date-format.inc' %]</span>
</li>
<li>
<label for="borrower_dateexpiry">whose expiration date is before:</label>
<input size="10" id="borrower_dateexpiry" name="borrower_dateexpiry" type="text" class="datepicker" />
<span class="hint">[% INCLUDE 'date-format.inc' %]</span>
</li>
<li>
<label for="borrower_categorycode">whose patron category is:</label>
<select id="borrower_categorycode" name="borrower_categorycode">
<option value="" selected="selected">Any</option>
[% FOREACH bc IN borrower_categorycodes %]
[% UNLESS ( bc.categorycode == 'S' || bc.category_type == 'S' ) %]
<option value="[% bc.categorycode %]">[% bc.description %]</option>
[% END %]
[% END %]
</select>
</li>
</ul>
</fieldset>
<fieldset>
<legend>Anonymize checkout history</legend>
<h3><input id="checkissue" type="checkbox" name="checkbox" value="issue" /><label for="checkissue"> Verify you want to anonymize patron checkout history</label></h3>
<br />
<ul>
<li>
<label for="date2">Permanently delete checkout history older than</label>
<input size="10" id="date2" name="filterdate2" type="text" class="datepicker" />
<span class="hint">[% INCLUDE 'date-format.inc' %]</span>
</li>
</ul>
<!-- hidden here -->
<input type="hidden" name="step2" value="1" />
</fieldset>
<fieldset class="action"><input type="submit" value="Next &gt;&gt;" /></fieldset>
</form>
</div>
<!-- step 1 END -->
[% END %]
[% IF ( step2 ) %]
<!-- STEP 2 START -->
<div id="step2">
<form name="f2" action="/cgi-bin/koha/tools/cleanborrowers.pl" method="post" onsubmit="return checkForm2(this);">
<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>
</ul>
<br />
[% IF ( totalToDelete ) %]
<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>
<br /><input id="trash" type="radio" name="radio" value="trash" />
<label for="trash">Move these patrons to the trash</label>
<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>
[% END %]
[% IF ( totalToAnonymize ) %]
Checkout history for [% totalToAnonymize %] patrons will be anonymized
<input type="hidden" name="do_anonym" value="[% totalToAnonymize %]" />
[% END %]
<input type="hidden" name="step3" value="1" />
<input type="hidden" name="filterdate1" value="[% filterdate1 %]" />
<input type="hidden" name="filterdate2" value="[% filterdate2 %]" />
<input type="hidden" name="borrower_dateexpiry" value="[% borrower_dateexpiry %]" />
<input type="hidden" name="borrower_categorycode" value="[% borrower_categorycode %]" />
</fieldset>
<fieldset class="action"><input type="submit" value="Finish" /> <a class="cancel" href="/cgi-bin/koha/tools/cleanborrowers.pl">Cancel</a></fieldset>
</form>
</div>
<!-- STEP 2 END -->
[% END %]
[% IF ( step3 ) %]
<!-- Step 3 START -->
<div id="step3">
[% IF ( testrun ) %]
<h4>[% TotalDel %] patrons would have been removed (if it wasn't a test run)</h4>
<h4>No patron records have been actually removed</h4>
[% ELSE %]
[% IF ( do_delete ) %]
[% IF ( trash ) %]
<h4>[% TotalDel %] patrons have been successfully moved to trash</h4>
[% ELSE %]
<h4>[% TotalDel %] patrons have been successfully deleted</h4>
[% END %]
[% ELSE %]
<h4>No patron records have been removed</h4>
[% END %]
[% END %]
[% IF ( do_anonym ) %]
<h4>All patrons with checkouts older than [% filterdate1 %] have been anonymized</h4>
[% ELSE %]
<h4>No patron records have been anonymized</h4>
[% END %]
</div>
<!-- Step 3 END -->
[% END %]
</div>
</div>
<div class="yui-b noprint">
[% INCLUDE 'tools-menu.inc' %]
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]