From b35665ba9dd1f209b500cc160a36d3b4dde1bb74 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 22 Nov 2013 09:15:31 -0500 Subject: [PATCH] Bug 11287: make patron import tool take new restrictions system into account The import patrons tool will add restrictions in the previous style ( directly to the borrowers table ). This will actually work, but will result in the restriction being un-removable, and will be overwritten by any new restrictions. Test Plan: 1) Apply this patch 2) Import new patrons with debarrments, note the debarment is created correctly 3) Import existing patrons with overwrite enabled, note that any new debarrment is added, and any existing debarrment is ignored Signed-off-by: Chris Cormack Signed-off-by: Jonathan Druart Signed-off-by: Galen Charlton --- Koha/Borrower/Debarments.pm | 2 +- tools/import_borrowers.pl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Koha/Borrower/Debarments.pm b/Koha/Borrower/Debarments.pm index 599020897c..2c91af2453 100644 --- a/Koha/Borrower/Debarments.pm +++ b/Koha/Borrower/Debarments.pm @@ -44,7 +44,7 @@ Koha::Borrower::Debarments - Module for managing borrower debarments =head2 GetDebarments -my $arrayref = GetDebarments( $borrowernumber, { key => $value } ); +my $arrayref = GetDebarments({ borrowernumber => $borrowernumber [, key => $value ] ); =cut diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl index 4445db5a18..3623684152 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -46,6 +46,7 @@ use C4::Members; use C4::Members::Attributes qw(:all); use C4::Members::AttributeTypes; use C4::Members::Messaging; +use Koha::Borrower::Debarments; use Text::CSV; # Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals: @@ -269,6 +270,26 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { $template->param('lastinvalid'=>$borrower{'surname'}.' / '.$borrowernumber); next LINE; } + if ( $borrower{debarred} ) { + # Check to see if this debarment already exists + my $debarrments = GetDebarments( + { + borrowernumber => $borrowernumber, + expiration => $borrower{debarred}, + comment => $borrower{debarredcomment} + } + ); + # If it doesn't, then add it! + unless (@$debarrments) { + AddDebarment( + { + borrowernumber => $borrowernumber, + expiration => $borrower{debarred}, + comment => $borrower{debarredcomment} + } + ); + } + } if ($extended) { if ($ext_preserve) { my $old_attributes = GetBorrowerAttributes($borrowernumber); @@ -285,13 +306,26 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { $borrower{'cardnumber'} = fixup_cardnumber(undef); } if ($borrowernumber = AddMember(%borrower)) { + + if ( $borrower{debarred} ) { + AddDebarment( + { + borrowernumber => $borrowernumber, + expiration => $borrower{debarred}, + comment => $borrower{debarredcomment} + } + ); + } + if ($extended) { SetBorrowerAttributes($borrowernumber, $patron_attributes); } + if ($set_messaging_prefs) { C4::Members::Messaging::SetMessagingPreferencesFromDefaults({ borrowernumber => $borrowernumber, categorycode => $borrower{categorycode} }); } + $imported++; $template->param('lastimported'=>$borrower{'surname'}.' / '.$borrowernumber); } else { -- 2.39.5