From 8528d4bce30ff0434d28f1b6048f8d0181f75dac Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 15 Sep 2022 13:35:37 +0000 Subject: [PATCH] Bug 31569: Remove GetImportRecordsRange from import stage This patch removes the use of GetimportRecordsRange from the importing step To test: 0 - Apply patch 1 - Stage a marc file for import 2 - Add to basket from a staged file 3 - Select titles to import (don't select all) 4 - Fill out necessary fields, be sure to select itemtype on items tab 5 - Import 6 - Confirm titles successfully added to basket 7 - Confirm staged import not marked as imported 8 - Add to basket from same file 9 - Select rest of titles 10 - Import 11 - Confirm staged file now marked imported Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Katrin Fischer --- acqui/addorderiso2709.pl | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 0a85ca6c9a..712c63fc24 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -135,7 +135,9 @@ if ($op eq ""){ # retrieve the file you want to import my $import_batch_id = $cgiparams->{'import_batch_id'}; - my $biblios = GetImportRecordsRange($import_batch_id); + my $import_records = Koha::Import::Records->search({ + import_batch_id => $import_batch_id, + }); my $duplinbatch; my $imported = 0; my @import_record_id_selected = $input->multi_param("import_record_id"); @@ -149,14 +151,13 @@ if ($op eq ""){ my $matcher_id = $input->param('matcher_id'); my $active_currency = Koha::Acquisition::Currencies->get_active; my $biblio_count = 0; - for my $biblio (@$biblios){ + while( my $import_record = $import_records->next ){ $biblio_count++; my $duplifound = 0; # Check if this import_record_id was selected - next if not grep { $_ eq $$biblio{import_record_id} } @import_record_id_selected; - my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); - my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; - my $match = GetImportRecordMatches( $biblio->{'import_record_id'}, 1 ); + next if not grep { $_ eq $import_record->import_record_id } @import_record_id_selected; + my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information"; + my $match = GetImportRecordMatches( $import_record->import_record_id, 1 ); my $biblionumber=$#$match > -1?$match->[0]->{'biblionumber'}:0; my $c_quantity = shift( @quantities ) || GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour') ) || 1; my $c_budget_id = shift( @budgets_id ) || $input->param('all_budget_id') || $budget_id; @@ -196,12 +197,12 @@ if ($op eq ""){ } } ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' ); - SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); + $import_record->status('imported')->store; } else { - SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); + $import_record->status('imported')->store; } - SetMatchedBiblionumber( $biblio->{import_record_id}, $biblionumber ); + $import_record->import_biblio->matched_biblionumber($biblionumber)->store; # Add items from MarcItemFieldsToOrder my @homebranches = $input->multi_param('homebranch_' . $biblio_count); @@ -358,7 +359,7 @@ if ($op eq ""){ $order->add_item( $itemnumber ); } } else { - SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); + $import_record->status( 'imported' )->store; } } $imported++; @@ -366,8 +367,8 @@ if ($op eq ""){ # If all bibliographic records from the batch have been imported we modifying the status of the batch accordingly SetImportBatchStatus( $import_batch_id, 'imported' ) - if @{ GetImportRecordsRange( $import_batch_id, undef, undef, 'imported' )} - == @{ GetImportRecordsRange( $import_batch_id )}; + if Koha::Import::Records->search({import_batch_id => $import_batch_id, status => 'imported' })->count + == Koha::Import::Records->search({import_batch_id => $import_batch_id})->count; # go to basket page if ( $imported ) { -- 2.30.2