View | Details | Raw Unified | Return to bug 30813
Collapse All | Expand All

(-)a/C4/Biblio.pm (-6 / +7 lines)
Lines 220-226 sub AddBiblio { Link Here
220
220
221
            # transform the data into koha-table style data
221
            # transform the data into koha-table style data
222
            SetUTF8Flag($record);
222
            SetUTF8Flag($record);
223
            my $olddata = TransformMarcToKoha( $record, $frameworkcode, 'no_items' );
223
            my $olddata = TransformMarcToKoha({ record => $record, limit_table => 'no_items' });
224
224
225
            my $biblio = Koha::Biblio->new(
225
            my $biblio = Koha::Biblio->new(
226
                {
226
                {
Lines 417-423 sub ModBiblio { Link Here
417
    _koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber );
417
    _koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber );
418
418
419
    # load the koha-table data object
419
    # load the koha-table data object
420
    my $oldbiblio = TransformMarcToKoha( $record, $frameworkcode );
420
    my $oldbiblio = TransformMarcToKoha({ record => $record });
421
421
422
    # update MARC subfield that stores biblioitems.cn_sort
422
    # update MARC subfield that stores biblioitems.cn_sort
423
    _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );
423
    _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );
Lines 2292-2298 sub TransformHtmlToMarc { Link Here
2292
2292
2293
=head2 TransformMarcToKoha
2293
=head2 TransformMarcToKoha
2294
2294
2295
    $result = TransformMarcToKoha( $record, undef, $limit )
2295
    $result = TransformMarcToKoha({ record => $record, limit_table => $limit })
2296
2296
2297
Extract data from a MARC bib record into a hashref representing
2297
Extract data from a MARC bib record into a hashref representing
2298
Koha biblio, biblioitems, and items fields.
2298
Koha biblio, biblioitems, and items fields.
Lines 2303-2311 hash_ref. Link Here
2303
=cut
2303
=cut
2304
2304
2305
sub TransformMarcToKoha {
2305
sub TransformMarcToKoha {
2306
    my ( $record, $frameworkcode, $limit_table ) = @_;
2306
    my ( $params ) = @_;
2307
    # FIXME  Parameter $frameworkcode is obsolete and will be removed
2307
2308
    $limit_table //= q{};
2308
    my $record = $params->{record};
2309
    my $limit_table = $params->{limit_table} // q{};
2309
2310
2310
    my $result = {};
2311
    my $result = {};
2311
    if (!defined $record) {
2312
    if (!defined $record) {
(-)a/C4/Items.pm (-4 / +4 lines)
Lines 166-172 sub AddItemFromMarc { Link Here
166
    my $localitemmarc = MARC::Record->new;
166
    my $localitemmarc = MARC::Record->new;
167
    $localitemmarc->append_fields( $source_item_marc->field($itemtag) );
167
    $localitemmarc->append_fields( $source_item_marc->field($itemtag) );
168
168
169
    my $item_values = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
169
    my $item_values = C4::Biblio::TransformMarcToKoha({ record => $localitemmarc, limit_table => 'items' });
170
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
170
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
171
    $item_values->{more_subfields_xml} = _get_unlinked_subfields_xml($unlinked_item_subfields);
171
    $item_values->{more_subfields_xml} = _get_unlinked_subfields_xml($unlinked_item_subfields);
172
    $item_values->{biblionumber} = $biblionumber;
172
    $item_values->{biblionumber} = $biblionumber;
Lines 244-250 sub AddItemBatchFromMarc { Link Here
244
        $temp_item_marc->append_fields($item_field);
244
        $temp_item_marc->append_fields($item_field);
245
    
245
    
246
        # add biblionumber and biblioitemnumber
246
        # add biblionumber and biblioitemnumber
247
        my $item = TransformMarcToKoha( $temp_item_marc, $frameworkcode, 'items' );
247
        my $item = TransformMarcToKoha({ record => $temp_item_marc, limit_table => 'items' });
248
        my $unlinked_item_subfields = _get_unlinked_item_subfields($temp_item_marc, $frameworkcode);
248
        my $unlinked_item_subfields = _get_unlinked_item_subfields($temp_item_marc, $frameworkcode);
249
        $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
249
        $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
250
        $item->{'biblionumber'} = $biblionumber;
250
        $item->{'biblionumber'} = $biblionumber;
Lines 301-307 sub ModItemFromMarc { Link Here
301
    my $localitemmarc = MARC::Record->new;
301
    my $localitemmarc = MARC::Record->new;
302
    $localitemmarc->append_fields( $item_marc->field($itemtag) );
302
    $localitemmarc->append_fields( $item_marc->field($itemtag) );
303
    my $item_object = Koha::Items->find($itemnumber);
303
    my $item_object = Koha::Items->find($itemnumber);
304
    my $item = TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
304
    my $item = TransformMarcToKoha({ record => $localitemmarc, limit_table => 'items' });
305
305
306
    # When importing items we blank this column, we need to set it to the existing value
306
    # When importing items we blank this column, we need to set it to the existing value
307
    # to prevent it being blanked by set_or_blank
307
    # to prevent it being blanked by set_or_blank
Lines 409-415 sub ModDateLastSeen { Link Here
409
409
410
=head2 CheckItemPreSave
410
=head2 CheckItemPreSave
411
411
412
    my $item_ref = TransformMarcToKoha($marc, 'items');
412
    my $item_ref = TransformMarcToKoha({ record => $marc, limit_table => 'items' });
413
    # do stuff
413
    # do stuff
414
    my %errors = CheckItemPreSave($item_ref);
414
    my %errors = CheckItemPreSave($item_ref);
415
    if (exists $errors{'duplicate_barcode'}) {
415
    if (exists $errors{'duplicate_barcode'}) {
(-)a/C4/Search.pm (-4 / +4 lines)
Lines 85-91 This function attempts to find duplicate records using a hard-coded, fairly simp Link Here
85
sub FindDuplicate {
85
sub FindDuplicate {
86
    my ($record) = @_;
86
    my ($record) = @_;
87
    my $dbh = C4::Context->dbh;
87
    my $dbh = C4::Context->dbh;
88
    my $result = TransformMarcToKoha( $record, '' );
88
    my $result = TransformMarcToKoha({ record => $record });
89
    my $sth;
89
    my $sth;
90
    my $query;
90
    my $query;
91
91
Lines 128-134 sub FindDuplicate { Link Here
128
                $possible_duplicate_record
128
                $possible_duplicate_record
129
            );
129
            );
130
130
131
            my $result = TransformMarcToKoha( $marcrecord, '' );
131
            my $result = TransformMarcToKoha({ record => $marcrecord });
132
132
133
            # FIXME :: why 2 $biblionumber ?
133
            # FIXME :: why 2 $biblionumber ?
134
            if ($result) {
134
            if ($result) {
Lines 185-191 my @results; Link Here
185
185
186
for my $r ( @{$marcresults} ) {
186
for my $r ( @{$marcresults} ) {
187
    my $marcrecord = MARC::File::USMARC::decode($r);
187
    my $marcrecord = MARC::File::USMARC::decode($r);
188
    my $biblio = TransformMarcToKoha($marcrecord,q{});
188
    my $biblio = TransformMarcToKoha({ record => $marcrecord });
189
189
190
    #build the iarray of hashs for the template.
190
    #build the iarray of hashs for the template.
191
    push @results, {
191
    push @results, {
Lines 1718-1724 sub searchResults { Link Here
1718
               : GetFrameworkCode($marcrecord->subfield($bibliotag,$bibliosubf));
1718
               : GetFrameworkCode($marcrecord->subfield($bibliotag,$bibliosubf));
1719
1719
1720
        SetUTF8Flag($marcrecord);
1720
        SetUTF8Flag($marcrecord);
1721
        my $oldbiblio = TransformMarcToKoha( $marcrecord, $fw, 'no_items' );
1721
        my $oldbiblio = TransformMarcToKoha({ record => $marcrecord, limit_table => 'no_items' });
1722
        $oldbiblio->{result_number} = $i + 1;
1722
        $oldbiblio->{result_number} = $i + 1;
1723
1723
1724
		$oldbiblio->{normalized_upc}  = GetNormalizedUPC(       $marcrecord,$marcflavour);
1724
		$oldbiblio->{normalized_upc}  = GetNormalizedUPC(       $marcrecord,$marcflavour);
(-)a/cataloguing/value_builder/marc21_linking_section.pl (-1 / +1 lines)
Lines 202-208 my $launcher = sub { Link Here
202
        my @field_data = ($search);
202
        my @field_data = ($search);
203
        for ( my $i = 0 ; $i < $total && $i < $resultsperpage ; $i++ ) {
203
        for ( my $i = 0 ; $i < $total && $i < $resultsperpage ; $i++ ) {
204
            my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] );
204
            my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] );
205
            my $rechash = TransformMarcToKoha( $record );
205
            my $rechash = TransformMarcToKoha({ record => $record });
206
            my $pos;
206
            my $pos;
207
            my $countitems = $rechash->{itembumber} ? 1 : 0;
207
            my $countitems = $rechash->{itembumber} ? 1 : 0;
208
            while ( index( $rechash->{itemnumber}, '|', $pos ) > 0 ) {
208
            while ( index( $rechash->{itemnumber}, '|', $pos ) > 0 ) {
(-)a/cataloguing/value_builder/unimarc_field_4XX.pl (-1 / +1 lines)
Lines 374-380 sub plugin { Link Here
374
         {
374
         {
375
            my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] );
375
            my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] );
376
            next unless $record;
376
            next unless $record;
377
            my $rechash = TransformMarcToKoha( $record );
377
            my $rechash = TransformMarcToKoha({ record => $record });
378
            if ( my $f = $record->field('200') ) {
378
            if ( my $f = $record->field('200') ) {
379
                $rechash->{fulltitle} =
379
                $rechash->{fulltitle} =
380
                    join(', ', map { $_->[1] } grep { $_->[0] =~ /[aehi]/ } $f->subfields() );
380
                    join(', ', map { $_->[1] } grep { $_->[0] =~ /[aehi]/ } $f->subfields() );
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 345-351 if (@$barcodes) { Link Here
345
            my @barcodes;
345
            my @barcodes;
346
            foreach my $hit ( @{$results} ) {
346
            foreach my $hit ( @{$results} ) {
347
                my $chosen = # Maybe easier to retrieve the itemnumber from $hit?
347
                my $chosen = # Maybe easier to retrieve the itemnumber from $hit?
348
                  TransformMarcToKoha( C4::Search::new_record_from_zebra('biblioserver',$hit) );
348
                  TransformMarcToKoha({ record => C4::Search::new_record_from_zebra('biblioserver',$hit) });
349
349
350
                # offer all barcodes individually
350
                # offer all barcodes individually
351
                if ( $chosen->{barcode} ) {
351
                if ( $chosen->{barcode} ) {
(-)a/labels/label-item-search.pl (-1 / +1 lines)
Lines 109-115 if ($show_results) { Link Here
109
        #DEBUG Notes: Decode the MARC record from each resulting MARC record...
109
        #DEBUG Notes: Decode the MARC record from each resulting MARC record...
110
        my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcresults->[$i] );
110
        my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcresults->[$i] );
111
        #DEBUG Notes: Transform it to Koha form...
111
        #DEBUG Notes: Transform it to Koha form...
112
        my $biblio = TransformMarcToKoha( $marcrecord, '' );
112
        my $biblio = TransformMarcToKoha({ record => $marcrecord });
113
        #DEBUG Notes: Stuff the bib into @biblio_data...
113
        #DEBUG Notes: Stuff the bib into @biblio_data...
114
        push (@results_set, $biblio);
114
        push (@results_set, $biblio);
115
        my $biblionumber = $biblio->{'biblionumber'};
115
        my $biblionumber = $biblio->{'biblionumber'};
(-)a/misc/batchRebuildBiblioTables.pl (-1 / +1 lines)
Lines 66-72 while (my ($biblionumber, $frameworkcode) = $sth->fetchrow) { Link Here
66
        next;
66
        next;
67
    }
67
    }
68
68
69
    my $biblio = TransformMarcToKoha($record);
69
    my $biblio = TransformMarcToKoha({ record => $record });
70
    C4::Biblio::_koha_modify_biblio($dbh, $biblio, $frameworkcode);
70
    C4::Biblio::_koha_modify_biblio($dbh, $biblio, $frameworkcode);
71
    C4::Biblio::_koha_modify_biblioitem_nonmarc($dbh, $biblio);
71
    C4::Biblio::_koha_modify_biblioitem_nonmarc($dbh, $biblio);
72
72
(-)a/opac/opac-ISBDdetail.pl (-1 / +1 lines)
Lines 142-148 $template->param( Link Here
142
142
143
#coping with subscriptions
143
#coping with subscriptions
144
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
144
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
145
my $dat                 = TransformMarcToKoha( $record );
145
my $dat                 = TransformMarcToKoha({ record => $record });
146
146
147
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
147
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
148
my @subs;
148
my @subs;
(-)a/opac/opac-MARCdetail.pl (-1 / +1 lines)
Lines 343-349 if ( C4::Context->preference("OPACISBD") ) { Link Here
343
343
344
#Search for title in links
344
#Search for title in links
345
my $marcflavour  = C4::Context->preference("marcflavour");
345
my $marcflavour  = C4::Context->preference("marcflavour");
346
my $dat = TransformMarcToKoha( $record );
346
my $dat = TransformMarcToKoha({ record => $record });
347
my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
347
my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
348
my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
348
my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
349
my $marcissns = GetMarcISSN( $record, $marcflavour );
349
my $marcissns = GetMarcISSN( $record, $marcflavour );
(-)a/serials/subscription-bib-search.pl (-1 / +1 lines)
Lines 114-120 if ( $op eq "do_search" && $query ) { Link Here
114
    for ( my $i = 0 ; $i < $total ; $i++ ) {
114
    for ( my $i = 0 ; $i < $total ; $i++ ) {
115
        my %resultsloop;
115
        my %resultsloop;
116
        my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcrecords->[$i] );
116
        my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcrecords->[$i] );
117
        my $biblio = TransformMarcToKoha( $marcrecord, '' );
117
        my $biblio = TransformMarcToKoha({ record => $marcrecord });
118
118
119
        #build the hash for the template.
119
        #build the hash for the template.
120
        $resultsloop{highlight}       = ( $i % 2 ) ? (1) : (0);
120
        $resultsloop{highlight}       = ( $i % 2 ) ? (1) : (0);
(-)a/t/db_dependent/Biblio/TransformMarcToKoha.t (-14 / +7 lines)
Lines 42-48 Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '500', tagsu Link Here
42
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
42
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
43
43
44
subtest 'Test a few mappings' => sub {
44
subtest 'Test a few mappings' => sub {
45
    plan tests => 7;
45
    plan tests => 6;
46
46
47
    my $marc = MARC::Record->new;
47
    my $marc = MARC::Record->new;
48
    $marc->append_fields(
48
    $marc->append_fields(
Lines 50-56 subtest 'Test a few mappings' => sub { Link Here
50
        MARC::Field->new( '300', '', '', a => 'a2', b => 'b2' ),
50
        MARC::Field->new( '300', '', '', a => 'a2', b => 'b2' ),
51
        MARC::Field->new( '500', '', '', a => 'note1', a => 'note2' ),
51
        MARC::Field->new( '500', '', '', a => 'note1', a => 'note2' ),
52
    );
52
    );
53
    my $result = C4::Biblio::TransformMarcToKoha( $marc );
53
    my $result = C4::Biblio::TransformMarcToKoha({ record => $marc });
54
        # Note: TransformMarcToKoha stripped the table prefix biblio.
54
        # Note: TransformMarcToKoha stripped the table prefix biblio.
55
    is( keys %{$result}, 3, 'Found all three mappings' );
55
    is( keys %{$result}, 3, 'Found all three mappings' );
56
    is( $result->{field1}, 'a1 | a2', 'Check field1 results' );
56
    is( $result->{field1}, 'a1 | a2', 'Check field1 results' );
Lines 62-73 subtest 'Test a few mappings' => sub { Link Here
62
    is( C4::Biblio::TransformMarcToKohaOneField( 'field4', $marc ),
62
    is( C4::Biblio::TransformMarcToKohaOneField( 'field4', $marc ),
63
        undef, 'TransformMarcToKohaOneField returns undef' );
63
        undef, 'TransformMarcToKohaOneField returns undef' );
64
64
65
    # Bug 19096 Default is authoritative now
66
    # Test passing another framework
67
    # CAUTION: This parameter of TransformMarcToKoha will be removed later
68
    my $new_fw = t::lib::TestBuilder->new->build({source => 'BiblioFramework'});
69
    $result = C4::Biblio::TransformMarcToKoha($marc, $new_fw->{frameworkcode});
70
    is( keys %{$result}, 3, 'Still found all three mappings' );
71
};
65
};
72
66
73
subtest 'Multiple mappings for one kohafield' => sub {
67
subtest 'Multiple mappings for one kohafield' => sub {
Lines 80-92 subtest 'Multiple mappings for one kohafield' => sub { Link Here
80
74
81
    my $marc = MARC::Record->new;
75
    my $marc = MARC::Record->new;
82
    $marc->append_fields( MARC::Field->new( '300', '', '', a => '3a' ) );
76
    $marc->append_fields( MARC::Field->new( '300', '', '', a => '3a' ) );
83
    my $result = C4::Biblio::TransformMarcToKoha( $marc );
77
    my $result = C4::Biblio::TransformMarcToKoha({ record => $marc });
84
    is_deeply( $result, { field1 => '3a' }, 'Simple start' );
78
    is_deeply( $result, { field1 => '3a' }, 'Simple start' );
85
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '' ) );
79
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '' ) );
86
    $result = C4::Biblio::TransformMarcToKoha( $marc );
80
    $result = C4::Biblio::TransformMarcToKoha({ record => $marc });
87
    is_deeply( $result, { field1 => '3a' }, 'An empty 510a makes no difference' );
81
    is_deeply( $result, { field1 => '3a' }, 'An empty 510a makes no difference' );
88
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '51' ) );
82
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '51' ) );
89
    $result = C4::Biblio::TransformMarcToKoha( $marc );
83
    $result = C4::Biblio::TransformMarcToKoha({ record =>  $marc });
90
    is_deeply( $result, { field1 => '3a | 51' }, 'Got 300a and 510a' );
84
    is_deeply( $result, { field1 => '3a | 51' }, 'Got 300a and 510a' );
91
85
92
    is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc ),
86
    is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc ),
Lines 128-134 subtest 'Test repeatable subfields' => sub { Link Here
128
122
129
    my $marc = MARC::Record->new;
123
    my $marc = MARC::Record->new;
130
    $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)
124
    $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)
131
    my $result = C4::Biblio::TransformMarcToKoha( $marc );
125
    my $result = C4::Biblio::TransformMarcToKoha({ record => $marc });
132
    is( $result->{test}, '1 | 2', 'Check 510x for two values' );
126
    is( $result->{test}, '1 | 2', 'Check 510x for two values' );
133
    is( $result->{norepeat}, '3 | 4 | 5', 'Check 510y too' );
127
    is( $result->{norepeat}, '3 | 4 | 5', 'Check 510y too' );
134
128
Lines 136-142 subtest 'Test repeatable subfields' => sub { Link Here
136
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
130
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
137
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '1' ) ); # actually, we should only have one $y (BZ 24652)
131
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '1' ) ); # actually, we should only have one $y (BZ 24652)
138
132
139
    $result = C4::Biblio::TransformMarcToKoha( $marc, '', 'no_items' );
133
    $result = C4::Biblio::TransformMarcToKoha({ record => $marc, limit_table => 'no_items' });
140
    is( $result->{test}, undef, 'Item field not returned when "no_items" passed' );
134
    is( $result->{test}, undef, 'Item field not returned when "no_items" passed' );
141
    is( $result->{norepeat}, undef, 'Item field not returned when "no_items" passed' );
135
    is( $result->{norepeat}, undef, 'Item field not returned when "no_items" passed' );
142
    is( $result->{field1}, 1, 'Biblio field returned when "no_items" passed' );
136
    is( $result->{field1}, 1, 'Biblio field returned when "no_items" passed' );
143
- 

Return to bug 30813