Bugzilla – Attachment 135232 Details for
Bug 30813
Refactor TransformMarcToKoha to remove TransformMarcToKohaOneField
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30813: Update TransformMarcToKoha to accept a hashref
Bug-30813-Update-TransformMarcToKoha-to-accept-a-h.patch (text/plain), 15.47 KB, created by
Nick Clemens (kidclamp)
on 2022-05-20 10:24:06 UTC
(
hide
)
Description:
Bug 30813: Update TransformMarcToKoha to accept a hashref
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2022-05-20 10:24:06 UTC
Size:
15.47 KB
patch
obsolete
>From 1cd06c0938f2fe22fb2b861cdc38006a07d18ae0 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 19 May 2022 19:53:16 +0000 >Subject: [PATCH] Bug 30813: Update TransformMarcToKoha to accept a hashref > >This patch updates all the calls to pass a hasref rather than an array > >It also removes the no longer used framework parameter > >To test: >prove -v t/Biblio.t t/db_dependent/Biblio/TransformMarcToKoha.t >--- > C4/Biblio.pm | 13 ++++++------ > C4/Items.pm | 8 ++++---- > C4/Search.pm | 8 ++++---- > .../value_builder/marc21_linking_section.pl | 2 +- > .../value_builder/unimarc_field_4XX.pl | 2 +- > circ/circulation.pl | 2 +- > labels/label-item-search.pl | 2 +- > misc/batchRebuildBiblioTables.pl | 2 +- > opac/opac-ISBDdetail.pl | 2 +- > opac/opac-MARCdetail.pl | 2 +- > serials/subscription-bib-search.pl | 2 +- > t/db_dependent/Biblio/TransformMarcToKoha.t | 20 +++++++------------ > 12 files changed, 30 insertions(+), 35 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index d1c5d76cee..24eef00a08 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -220,7 +220,7 @@ sub AddBiblio { > > # transform the data into koha-table style data > SetUTF8Flag($record); >- my $olddata = TransformMarcToKoha( $record, $frameworkcode, 'no_items' ); >+ my $olddata = TransformMarcToKoha({ record => $record, limit_table => 'no_items' }); > > my $biblio = Koha::Biblio->new( > { >@@ -417,7 +417,7 @@ sub ModBiblio { > _koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber ); > > # load the koha-table data object >- my $oldbiblio = TransformMarcToKoha( $record, $frameworkcode ); >+ my $oldbiblio = TransformMarcToKoha({ record => $record }); > > # update MARC subfield that stores biblioitems.cn_sort > _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode ); >@@ -2292,7 +2292,7 @@ sub TransformHtmlToMarc { > > =head2 TransformMarcToKoha > >- $result = TransformMarcToKoha( $record, undef, $limit ) >+ $result = TransformMarcToKoha({ record => $record, limit_table => $limit }) > > Extract data from a MARC bib record into a hashref representing > Koha biblio, biblioitems, and items fields. >@@ -2303,9 +2303,10 @@ hash_ref. > =cut > > sub TransformMarcToKoha { >- my ( $record, $frameworkcode, $limit_table ) = @_; >- # FIXME Parameter $frameworkcode is obsolete and will be removed >- $limit_table //= q{}; >+ my ( $params ) = @_; >+ >+ my $record = $params->{record}; >+ my $limit_table = $params->{limit_table} // q{}; > > my $result = {}; > if (!defined $record) { >diff --git a/C4/Items.pm b/C4/Items.pm >index 9808fadd1f..03305eba33 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -166,7 +166,7 @@ sub AddItemFromMarc { > my $localitemmarc = MARC::Record->new; > $localitemmarc->append_fields( $source_item_marc->field($itemtag) ); > >- my $item_values = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); >+ my $item_values = C4::Biblio::TransformMarcToKoha({ record => $localitemmarc, limit_table => 'items' }); > my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); > $item_values->{more_subfields_xml} = _get_unlinked_subfields_xml($unlinked_item_subfields); > $item_values->{biblionumber} = $biblionumber; >@@ -244,7 +244,7 @@ sub AddItemBatchFromMarc { > $temp_item_marc->append_fields($item_field); > > # add biblionumber and biblioitemnumber >- my $item = TransformMarcToKoha( $temp_item_marc, $frameworkcode, 'items' ); >+ my $item = TransformMarcToKoha({ record => $temp_item_marc, limit_table => 'items' }); > my $unlinked_item_subfields = _get_unlinked_item_subfields($temp_item_marc, $frameworkcode); > $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields); > $item->{'biblionumber'} = $biblionumber; >@@ -301,7 +301,7 @@ sub ModItemFromMarc { > my $localitemmarc = MARC::Record->new; > $localitemmarc->append_fields( $item_marc->field($itemtag) ); > my $item_object = Koha::Items->find($itemnumber); >- my $item = TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); >+ my $item = TransformMarcToKoha({ record => $localitemmarc, limit_table => 'items' }); > > # When importing items we blank this column, we need to set it to the existing value > # to prevent it being blanked by set_or_blank >@@ -409,7 +409,7 @@ sub ModDateLastSeen { > > =head2 CheckItemPreSave > >- my $item_ref = TransformMarcToKoha($marc, 'items'); >+ my $item_ref = TransformMarcToKoha({ record => $marc, limit_table => 'items' }); > # do stuff > my %errors = CheckItemPreSave($item_ref); > if (exists $errors{'duplicate_barcode'}) { >diff --git a/C4/Search.pm b/C4/Search.pm >index 5842b0e6cc..6e850e1e6c 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -85,7 +85,7 @@ This function attempts to find duplicate records using a hard-coded, fairly simp > sub FindDuplicate { > my ($record) = @_; > my $dbh = C4::Context->dbh; >- my $result = TransformMarcToKoha( $record, '' ); >+ my $result = TransformMarcToKoha({ record => $record }); > my $sth; > my $query; > >@@ -128,7 +128,7 @@ sub FindDuplicate { > $possible_duplicate_record > ); > >- my $result = TransformMarcToKoha( $marcrecord, '' ); >+ my $result = TransformMarcToKoha({ record => $marcrecord }); > > # FIXME :: why 2 $biblionumber ? > if ($result) { >@@ -185,7 +185,7 @@ my @results; > > for my $r ( @{$marcresults} ) { > my $marcrecord = MARC::File::USMARC::decode($r); >- my $biblio = TransformMarcToKoha($marcrecord,q{}); >+ my $biblio = TransformMarcToKoha({ record => $marcrecord }); > > #build the iarray of hashs for the template. > push @results, { >@@ -1718,7 +1718,7 @@ sub searchResults { > : GetFrameworkCode($marcrecord->subfield($bibliotag,$bibliosubf)); > > SetUTF8Flag($marcrecord); >- my $oldbiblio = TransformMarcToKoha( $marcrecord, $fw, 'no_items' ); >+ my $oldbiblio = TransformMarcToKoha({ record => $marcrecord, limit_table => 'no_items' }); > $oldbiblio->{result_number} = $i + 1; > > $oldbiblio->{normalized_upc} = GetNormalizedUPC( $marcrecord,$marcflavour); >diff --git a/cataloguing/value_builder/marc21_linking_section.pl b/cataloguing/value_builder/marc21_linking_section.pl >index 35072c1993..7a7478642e 100755 >--- a/cataloguing/value_builder/marc21_linking_section.pl >+++ b/cataloguing/value_builder/marc21_linking_section.pl >@@ -202,7 +202,7 @@ my $launcher = sub { > my @field_data = ($search); > for ( my $i = 0 ; $i < $total && $i < $resultsperpage ; $i++ ) { > my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] ); >- my $rechash = TransformMarcToKoha( $record ); >+ my $rechash = TransformMarcToKoha({ record => $record }); > my $pos; > my $countitems = $rechash->{itembumber} ? 1 : 0; > while ( index( $rechash->{itemnumber}, '|', $pos ) > 0 ) { >diff --git a/cataloguing/value_builder/unimarc_field_4XX.pl b/cataloguing/value_builder/unimarc_field_4XX.pl >index 0437660680..2d027101fe 100755 >--- a/cataloguing/value_builder/unimarc_field_4XX.pl >+++ b/cataloguing/value_builder/unimarc_field_4XX.pl >@@ -374,7 +374,7 @@ sub plugin { > { > my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] ); > next unless $record; >- my $rechash = TransformMarcToKoha( $record ); >+ my $rechash = TransformMarcToKoha({ record => $record }); > if ( my $f = $record->field('200') ) { > $rechash->{fulltitle} = > join(', ', map { $_->[1] } grep { $_->[0] =~ /[aehi]/ } $f->subfields() ); >diff --git a/circ/circulation.pl b/circ/circulation.pl >index 6aaf831ba6..f0a6bd57a6 100755 >--- a/circ/circulation.pl >+++ b/circ/circulation.pl >@@ -345,7 +345,7 @@ if (@$barcodes) { > my @barcodes; > foreach my $hit ( @{$results} ) { > my $chosen = # Maybe easier to retrieve the itemnumber from $hit? >- TransformMarcToKoha( C4::Search::new_record_from_zebra('biblioserver',$hit) ); >+ TransformMarcToKoha({ record => C4::Search::new_record_from_zebra('biblioserver',$hit) }); > > # offer all barcodes individually > if ( $chosen->{barcode} ) { >diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl >index b07be0aa47..a41960e0ec 100755 >--- a/labels/label-item-search.pl >+++ b/labels/label-item-search.pl >@@ -109,7 +109,7 @@ if ($show_results) { > #DEBUG Notes: Decode the MARC record from each resulting MARC record... > my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcresults->[$i] ); > #DEBUG Notes: Transform it to Koha form... >- my $biblio = TransformMarcToKoha( $marcrecord, '' ); >+ my $biblio = TransformMarcToKoha({ record => $marcrecord }); > #DEBUG Notes: Stuff the bib into @biblio_data... > push (@results_set, $biblio); > my $biblionumber = $biblio->{'biblionumber'}; >diff --git a/misc/batchRebuildBiblioTables.pl b/misc/batchRebuildBiblioTables.pl >index cb936c0c92..5b3ce00334 100755 >--- a/misc/batchRebuildBiblioTables.pl >+++ b/misc/batchRebuildBiblioTables.pl >@@ -66,7 +66,7 @@ while (my ($biblionumber, $frameworkcode) = $sth->fetchrow) { > next; > } > >- my $biblio = TransformMarcToKoha($record); >+ my $biblio = TransformMarcToKoha({ record => $record }); > C4::Biblio::_koha_modify_biblio($dbh, $biblio, $frameworkcode); > C4::Biblio::_koha_modify_biblioitem_nonmarc($dbh, $biblio); > >diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl >index 9335ea4ccd..2d2355bb79 100755 >--- a/opac/opac-ISBDdetail.pl >+++ b/opac/opac-ISBDdetail.pl >@@ -142,7 +142,7 @@ $template->param( > > #coping with subscriptions > my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); >-my $dat = TransformMarcToKoha( $record ); >+my $dat = TransformMarcToKoha({ record => $record }); > > my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' }); > my @subs; >diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl >index 0133784d39..1cd0681d9e 100755 >--- a/opac/opac-MARCdetail.pl >+++ b/opac/opac-MARCdetail.pl >@@ -343,7 +343,7 @@ if ( C4::Context->preference("OPACISBD") ) { > > #Search for title in links > my $marcflavour = C4::Context->preference("marcflavour"); >-my $dat = TransformMarcToKoha( $record ); >+my $dat = TransformMarcToKoha({ $record }); > my $isbn = GetNormalizedISBN(undef,$record,$marcflavour); > my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); > my $marcissns = GetMarcISSN( $record, $marcflavour ); >diff --git a/serials/subscription-bib-search.pl b/serials/subscription-bib-search.pl >index 8791f037da..2853404bcb 100755 >--- a/serials/subscription-bib-search.pl >+++ b/serials/subscription-bib-search.pl >@@ -114,7 +114,7 @@ if ( $op eq "do_search" && $query ) { > for ( my $i = 0 ; $i < $total ; $i++ ) { > my %resultsloop; > my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcrecords->[$i] ); >- my $biblio = TransformMarcToKoha( $marcrecord, '' ); >+ my $biblio = TransformMarcToKoha({ record => $marcrecord }); > > #build the hash for the template. > $resultsloop{highlight} = ( $i % 2 ) ? (1) : (0); >diff --git a/t/db_dependent/Biblio/TransformMarcToKoha.t b/t/db_dependent/Biblio/TransformMarcToKoha.t >index 9cd675858b..42f0a619b6 100755 >--- a/t/db_dependent/Biblio/TransformMarcToKoha.t >+++ b/t/db_dependent/Biblio/TransformMarcToKoha.t >@@ -42,7 +42,7 @@ Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '500', tagsu > Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); > > subtest 'Test a few mappings' => sub { >- plan tests => 7; >+ plan tests => 6; > > my $marc = MARC::Record->new; > $marc->append_fields( >@@ -50,7 +50,7 @@ subtest 'Test a few mappings' => sub { > MARC::Field->new( '300', '', '', a => 'a2', b => 'b2' ), > MARC::Field->new( '500', '', '', a => 'note1', a => 'note2' ), > ); >- my $result = C4::Biblio::TransformMarcToKoha( $marc ); >+ my $result = C4::Biblio::TransformMarcToKoha({ record => $marc }); > # Note: TransformMarcToKoha stripped the table prefix biblio. > is( keys %{$result}, 3, 'Found all three mappings' ); > is( $result->{field1}, 'a1 | a2', 'Check field1 results' ); >@@ -62,12 +62,6 @@ subtest 'Test a few mappings' => sub { > is( C4::Biblio::TransformMarcToKohaOneField( 'field4', $marc ), > undef, 'TransformMarcToKohaOneField returns undef' ); > >- # Bug 19096 Default is authoritative now >- # Test passing another framework >- # CAUTION: This parameter of TransformMarcToKoha will be removed later >- my $new_fw = t::lib::TestBuilder->new->build({source => 'BiblioFramework'}); >- $result = C4::Biblio::TransformMarcToKoha($marc, $new_fw->{frameworkcode}); >- is( keys %{$result}, 3, 'Still found all three mappings' ); > }; > > subtest 'Multiple mappings for one kohafield' => sub { >@@ -80,13 +74,13 @@ subtest 'Multiple mappings for one kohafield' => sub { > > my $marc = MARC::Record->new; > $marc->append_fields( MARC::Field->new( '300', '', '', a => '3a' ) ); >- my $result = C4::Biblio::TransformMarcToKoha( $marc ); >+ my $result = C4::Biblio::TransformMarcToKoha({ record => $marc }); > is_deeply( $result, { field1 => '3a' }, 'Simple start' ); > $marc->append_fields( MARC::Field->new( '510', '', '', a => '' ) ); >- $result = C4::Biblio::TransformMarcToKoha( $marc ); >+ $result = C4::Biblio::TransformMarcToKoha({ record => $marc }); > is_deeply( $result, { field1 => '3a' }, 'An empty 510a makes no difference' ); > $marc->append_fields( MARC::Field->new( '510', '', '', a => '51' ) ); >- $result = C4::Biblio::TransformMarcToKoha( $marc ); >+ $result = C4::Biblio::TransformMarcToKoha({ record => $marc }); > is_deeply( $result, { field1 => '3a | 51' }, 'Got 300a and 510a' ); > > is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc ), >@@ -128,7 +122,7 @@ subtest 'Test repeatable subfields' => sub { > > my $marc = MARC::Record->new; > $marc->append_fields( MARC::Field->new( '510', '', '', x => '1', x => '2', y => '3 | 4', y => '5' ) ); # actually, we should only have one $y (BZ 24652) >- my $result = C4::Biblio::TransformMarcToKoha( $marc ); >+ my $result = C4::Biblio::TransformMarcToKoha({ record => $marc }); > is( $result->{test}, '1 | 2', 'Check 510x for two values' ); > is( $result->{norepeat}, '3 | 4 | 5', 'Check 510y too' ); > >@@ -136,7 +130,7 @@ subtest 'Test repeatable subfields' => sub { > Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); > $marc->append_fields( MARC::Field->new( '510', '', '', a => '1' ) ); # actually, we should only have one $y (BZ 24652) > >- $result = C4::Biblio::TransformMarcToKoha( $marc, '', 'no_items' ); >+ $result = C4::Biblio::TransformMarcToKoha({ record => $marc, limit_table => 'no_items' }); > is( $result->{test}, undef, 'Item field not returned when "no_items" passed' ); > is( $result->{norepeat}, undef, 'Item field not returned when "no_items" passed' ); > is( $result->{field1}, 1, 'Biblio field returned when "no_items" passed' ); >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30813
:
135232
|
135233
|
135234
|
135235
|
135239
|
135240
|
135241
|
135242
|
135243
|
135302
|
135303
|
135304
|
135305
|
135306
|
135371
|
135374
|
135375
|
135376
|
135377
|
135378
|
135379
|
135763
|
135764
|
135765
|
135766
|
135767
|
135768
|
135769
|
135803
|
135825