From d55f183b9ff4cf1355fd13b967c023a8c6040e1b Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 29 Sep 2021 13:08:02 +1300 Subject: [PATCH] Bug 35061: Preserve categorycode when importing patrons This patch should preserve category codes when importing patrons using misc/import_patrons.pl Use case: /usr/share/koha/bin/import_patrons.pl --file patrons.csv --matchpoint userid --default branchcode=C --overwrite --preserve-categorycode --verbose --confirm To test, use a file with a column categorycode. Confirm that new patrons added from the spreadsheet by the file are added to the database with the correct category code. Confirm existing patrons that are overwritten receive the categorycode from the spreadsheet. Sponsored-by: Auckland University of Technology --- Koha/Patrons/Import.pm | 5 +++++ misc/import_patrons.pl | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index 5c8dc6b8763..8d65c7b3631 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -80,6 +80,7 @@ sub import_patrons { my $update_dateexpiry = $params->{update_dateexpiry}; my $update_dateexpiry_from_today = $params->{update_dateexpiry_from_today}; my $update_dateexpiry_from_existing = $params->{update_dateexpiry_from_existing}; + my $preserve_categorycode = $params->{preserve_categorycode}; my $extended = C4::Context->preference('ExtendedPatronAttributes'); my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences'); @@ -294,6 +295,10 @@ sub import_patrons { $borrower{$col} = $member->{$col} if $col eq 'dateexpiry' && !$columns[ $csvkeycol{$col} ]; + if ( $col eq 'categorycode' && $preserve_categorycode && $member->{$col} ) { + $borrower{$col} = $member->{$col}; + } + unless ( exists( $csvkeycol{$col} ) || $defaults->{$col} ) { $borrower{$col} = $member->{$col} if ( $member->{$col} ); } diff --git a/misc/import_patrons.pl b/misc/import_patrons.pl index 5d702d8f6fe..15534796fe0 100755 --- a/misc/import_patrons.pl +++ b/misc/import_patrons.pl @@ -34,6 +34,7 @@ my $overwrite_passwords; my $welcome_new = 0; my %defaults; my $ext_preserve = 0; +my $preserve_categorycode = 0; my $confirm; my $verbose = 0; my $help; @@ -59,6 +60,7 @@ GetOptions( 'pf|preserve-field=s' => \@preserve_fields, 'v|verbose+' => \$verbose, 'h|help|?' => \$help, + 'pc|preserve-categorycode' => \$preserve_categorycode, ) or pod2usage(2); pod2usage(1) if $help; @@ -89,6 +91,7 @@ my $return = $Import->import_patrons( update_dateexpiry_from_existing => $update_dateexpiry_from_existing, send_welcome => $welcome_new, dry_run => !$confirm, + preserve_categorycode => $preserve_categorycode, } ); @@ -200,6 +203,10 @@ Cannot by used in conjunction with --expiration-from-existing If a matching patron is found, extend the expiration date of their account using the patron's current expiration date as the base Cannot by used in conjunction with --expiration-from-today +=item B<-pc|--preserve-categorycode> + +Retain patron categorycode for existing patrons being overwritten + =item B<-v|--verbose> Be verbose -- 2.39.2