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

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2022-05-19 19:53:16 +00:00 committed by Tomas Cohen Arazi
parent 24c4b408ff
commit ee669178f6
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
12 changed files with 30 additions and 35 deletions

View File

@ -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) {

View File

@ -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'}) {

View File

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

View File

@ -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 ) {

View File

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

View File

@ -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} ) {

View File

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

View File

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

View File

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

View File

@ -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 => $record });
my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
my $marcissns = GetMarcISSN( $record, $marcflavour );

View File

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

View File

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