From 9e6f8b00ba216f62e2b337bdba97e7ecc020f7c9 Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Tue, 4 Mar 2025 15:13:19 +0000 Subject: [PATCH] Bug 21272: (follow-up) tidy code --- C4/ImportBatch.pm | 10 ++++++---- t/db_dependent/ImportBatch.t | 23 +++++++++++++++++------ tools/manage-marc-import.pl | 4 ++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index fba7446ea4..3138bb17b2 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -21,7 +21,7 @@ use strict; use warnings; use C4::Context; -use C4::Koha qw( GetNormalizedISBN ); +use C4::Koha qw( GetNormalizedISBN ); use C4::Biblio qw( AddBiblio DelBiblio @@ -30,7 +30,7 @@ use C4::Biblio qw( ModBiblio TransformMarcToKoha ); -use C4::Items qw( AddItemFromMarc ModItemFromMarc ); +use C4::Items qw( AddItemFromMarc ModItemFromMarc ); use C4::Charset qw( MarcToUTF8Record SetUTF8Flag StripNonXmlChars ); use C4::AuthoritiesMarc qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority GetAuthorizedHeading ); @@ -1281,7 +1281,7 @@ Returns an array of imported item branches. =cut sub GetImportItemsBranches { - my ( $batch_id ) = @_; + my ($batch_id) = @_; my $dbh = C4::Context->dbh; my $query = "SELECT import_items_id, import_items.marcxml, encoding @@ -1297,8 +1297,10 @@ sub GetImportItemsBranches { my @branch; my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); + foreach my $row (@$results) { - my $item_marc = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); + my $item_marc = + MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); push @branch, $item_marc->subfield( $homebranchfield, $homebranchsubfield ); push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield ); } diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t index 4718677d60..ab62187b63 100755 --- a/t/db_dependent/ImportBatch.t +++ b/t/db_dependent/ImportBatch.t @@ -274,8 +274,11 @@ subtest "_batchCommitItems" => sub { 'Error correctly set when import item has duplicate barcode and action always_add' ); - $import_item = $builder->build_object({ class => 'Koha::Import::Record::Items', value => { - marcxml => q{ + $import_item = $builder->build_object( + { + class => 'Koha::Import::Record::Items', + value => { + marcxml => q{ sub { }, - }}); + } + } + ); ( $num_items_added, $num_items_replaced, $num_items_errored ) = - C4::ImportBatch::_batchCommitItems( $import_item->import_record_id, 32, 'always_add',64 ); + C4::ImportBatch::_batchCommitItems( $import_item->import_record_id, 32, 'always_add', 64 ); is( $num_items_errored, 1, "Item with wrong branchcode fails when action always_add" ); $import_item->discard_changes(); - is( $import_item->status, 'error', "Import item marked as error when wrong branchcode detected and action always_add"); - is( $import_item->import_error, 'Branch code WBRC missing', 'Error correctly set when import item has a wrong branchcode detected and action always_add' ); + is( + $import_item->status, 'error', + "Import item marked as error when wrong branchcode detected and action always_add" + ); + is( + $import_item->import_error, 'Branch code WBRC missing', + 'Error correctly set when import item has a wrong branchcode detected and action always_add' + ); }; subtest "RecordsFromMarcPlugin" => sub { diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl index 110e5bfb33..cfc56f9ebd 100755 --- a/tools/manage-marc-import.pl +++ b/tools/manage-marc-import.pl @@ -28,7 +28,7 @@ use Try::Tiny; # Koha modules used use C4::Context; use C4::Koha; -use C4::Auth qw( get_template_and_user ); +use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::ImportBatch qw( CleanBatch DeleteBatch GetImportBatch GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction SetImportBatchOverlayAction SetImportBatchNoMatchAction SetImportBatchItemAction BatchFindDuplicates SetImportBatchMatcher GetItemNumbersFromImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches BatchCommitRecords BatchRevertRecords GetImportItemsBranches GetBadBranchesImportItems ); @@ -96,7 +96,7 @@ if ( $op eq "" ) { import_batches_list( $template, $offset, $results_per_page ); } else { my @import_items_branches = GetImportItemsBranches($import_batch_id); - my @import_items = GetBadBranchesImportItems($import_batch_id); + my @import_items = GetBadBranchesImportItems($import_batch_id); my @bad_item_titles; my @missing_branches; foreach my $item (@import_items) { -- 2.34.1