Bug 34632: Add step_callback support to Koha::Patrons::Import

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 <noreply@anthropic.com>
Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Pedro Amorim 2026-06-16 16:32:22 +00:00
parent 115d26ecae
commit 770e5ca6ec
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 12 additions and 4 deletions

View File

@ -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;