From 0e8b67e1edc01fe38861d1c953de17810350d709 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Fri, 5 Mar 2021 14:35:32 +0100 Subject: [PATCH] Bug 14957: fix context for batchmod and batchimport Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- C4/ImportBatch.pm | 12 +++++++++++- Koha/BackgroundJob/BatchUpdateBiblio.pm | 17 +++++------------ tools/batch_record_modification.pl | 9 +++++++-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index daa6b7ba74..b6735c697d 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -602,6 +602,10 @@ sub BatchCommitRecords { WHERE import_batch_id = ?"); $sth->execute($batch_id); my $marcflavour = C4::Context->preference('marcflavour'); + + my $userenv = C4::Context->userenv; + my $logged_in_patron = Koha::Patrons->find( $userenv->{number} ); + my $rec_num = 0; while (my $rowref = $sth->fetchrow_hashref) { $record_type = $rowref->{'record_type'}; @@ -675,7 +679,13 @@ sub BatchCommitRecords { } $oldxml = $old_marc->as_xml($marc_type); - ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode, {context => {source => 'batchimport'}}); + ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode, { + context => { + source => 'batchimport', + categorycode => $logged_in_patron->categorycode, + userid => $logged_in_patron->userid + }, + }); $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead if ($item_result eq 'create_new' || $item_result eq 'replace') { diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm index 028f269a0f..dae46682c1 100644 --- a/Koha/BackgroundJob/BatchUpdateBiblio.pm +++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm @@ -91,13 +91,9 @@ sub process { my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record ); my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber ); - C4::Biblio::ModBiblio( $record, $biblionumber, $frameworkcode, - { - source => $args->{source}, - categorycode => $args->{categorycode}, - userid => $args->{userid}, - } - ); + C4::Biblio::ModBiblio( $record, $biblionumber, $frameworkcode, { + context => $args->{context}, + }); }; if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well push @messages, { @@ -140,12 +136,9 @@ sub enqueue { return unless exists $args->{mmtid}; return unless exists $args->{record_ids}; - my $mmtid = $args->{mmtid}; - my @record_ids = @{ $args->{record_ids} }; - $self->SUPER::enqueue({ - job_size => scalar @record_ids, - job_args => {mmtid => $mmtid, record_ids => \@record_ids,} + job_size => scalar @{$args->{record_ids}}, + job_args => $args, }); } diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl index 6c0b225885..7a939a1c98 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -157,15 +157,20 @@ if ( $op eq 'form' ) { my @record_ids = $input->multi_param('record_id'); try { + my $patron = Koha::Patrons->find( $loggedinuser ); my $params = { mmtid => $mmtid, record_ids => \@record_ids, + context => { + source => 'batchmod', + categorycode => $patron->categorycode, + userid => $patron->userid + } }; - my $patron = Koha::Patrons->find( $loggedinuser ); my $job_id = $recordtype eq 'biblio' - ? Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue($params, { source => 'batchmod', categorycode => $patron->categorycode, userid => $patron->userid }) + ? Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue($params) : Koha::BackgroundJob::BatchUpdateAuthority->new->enqueue($params); $template->param( -- 2.39.5