From 770e5ca6ec3653736de0eb2949a92e83e562a833 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Tue, 16 Jun 2026 16:32:22 +0000 Subject: [PATCH] Bug 34632: Add step_callback support to Koha::Patrons::Import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds an optional step_callback coderef parameter to import_patrons(). When provided it is called after every row — whether the row succeeds, is skipped as a duplicate, or is rejected as invalid — so callers can track progress. Also removes the 25-error cap that was there to protect browser response size; that constraint no longer applies when results are stored in a background job's data field. Co-Authored-By: Claude Sonnet 4.6 Signed-off-by: Brendan Lawlor Signed-off-by: Lisette Scheer Signed-off-by: Pedro Amorim --- Koha/Patrons/Import.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index 2d475e8c59..0be7734d3c 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -85,6 +85,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 $step_callback = $params->{step_callback}; my $extended = C4::Context->preference('ExtendedPatronAttributes'); my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences'); @@ -172,9 +173,8 @@ LINE: while ( my $borrowerline = <$handle> ) { $_->{surname} = $borrower{surname} || 'UNDEF'; } $invalid++; - ( 25 > scalar @errors ) and push @errors, { missing_criticals => \@missing_criticals }; - - # The first 25 errors are enough. Keeping track of 30,000+ would destroy performance. + push @errors, { missing_criticals => \@missing_criticals }; + $step_callback->() if $step_callback; next LINE; } @@ -239,6 +239,7 @@ LINE: while ( my $borrowerline = <$handle> ) { cardnumber => $borrower{cardnumber} }; $invalid++; + $step_callback->() if $step_callback; next; } @@ -257,6 +258,7 @@ LINE: while ( my $borrowerline = <$handle> ) { { push @errors, { duplicate_userid => 1, userid => $borrower{userid} }; $invalid++; + $step_callback->() if $step_callback; next LINE; } @@ -288,6 +290,7 @@ LINE: while ( my $borrowerline = <$handle> ) { value => $borrower{'surname'} . ' / ' . $borrowernumber } ); + $step_callback->() if $step_callback; next LINE; } $borrower{'borrowernumber'} = $borrowernumber; @@ -508,7 +511,10 @@ LINE: while ( my $borrowerline = <$handle> ) { }; } - next LINE unless $success; + unless ($success) { + $step_callback->() if $step_callback; + next LINE; + } # Send WELCOME welcome email is the user is new and we're set to send mail if ( $send_welcome && $is_new ) { @@ -575,6 +581,8 @@ LINE: while ( my $borrowerline = <$handle> ) { )->store(); } } + + $step_callback->() if $step_callback; } $schema->storage->txn_rollback if $dry_run;