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

(-)a/Koha/Biblio/Metadata/Extractor/MARC/MARC21.pm (+4 lines)
Lines 129-134 sub check_fixed_length { Link Here
129
        '008' => 40,
129
        '008' => 40,
130
    };
130
    };
131
    my $record = $self->metadata;
131
    my $record = $self->metadata;
132
    if( ref($record) ne 'MARC::Record' ) { # TODO Move to Extractor::MARC->metadata?
133
        warn "MARC extractor: metadata is not a MARC::Record object\n";
134
        return;
135
    }
132
    my $result = { passed => [], failed => [] };
136
    my $result = { passed => [], failed => [] };
133
    foreach my $field ( $record->field( '005', '006', '007', '008' ) ) {
137
    foreach my $field ( $record->field( '005', '006', '007', '008' ) ) {
134
        my ( $length, $pass );
138
        my ( $length, $pass );
(-)a/cataloguing/addbiblio.pl (-5 / +4 lines)
Lines 831-846 if ( $op eq "cud-addbiblio" ) { Link Here
831
831
832
} else {
832
} else {
833
833
834
    #----------------------------------------------------------------------------
834
    # Check fixed length fields for existing biblio
835
    # If we're in a duplication case, we have to set to "" the biblionumber
835
    if ( $biblio && C4::Context->preference('marcflavour') eq 'MARC21' ) {
836
    # as we'll save the biblio as a new one.
837
838
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
839
        my $fixed_length_info =
836
        my $fixed_length_info =
840
            Koha::Biblio::Metadata::Extractor::MARC::MARC21->new( { biblio => $biblio } )->check_fixed_length;
837
            Koha::Biblio::Metadata::Extractor::MARC::MARC21->new( { biblio => $biblio } )->check_fixed_length;
841
        $template->param( marc21_fixlen => $fixed_length_info ) if @{ $fixed_length_info->{failed} };
838
        $template->param( marc21_fixlen => $fixed_length_info ) if @{ $fixed_length_info->{failed} };
842
    }
839
    }
843
840
841
    # If we're in a duplication case, we have to set to "" the biblionumber
842
    # as we'll save the biblio as a new one.
844
    $template->param(
843
    $template->param(
845
        biblionumberdata => $biblionumber,
844
        biblionumberdata => $biblionumber,
846
        op               => $op,
845
        op               => $op,
(-)a/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC/MARC21.t (-4 / +13 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 5;
23
use Test::More tests => 5;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::Warn;
25
26
26
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
27
use t::lib::Mocks;
28
use t::lib::Mocks;
Lines 92-110 subtest 'get_normalized_oclc() tests' => sub { Link Here
92
93
93
subtest 'check_fixed_length' => sub {
94
subtest 'check_fixed_length' => sub {
94
95
95
    plan tests => 6;
96
    plan tests => 9;
96
    $schema->storage->txn_begin;
97
    $schema->storage->txn_begin;
97
98
99
    # Check empty string (no valid metadata)
100
    my $extractor = Koha::Biblio::Metadata::Extractor::MARC::MARC21->new( { metadata => q{} } );
101
    warning_like { $extractor->check_fixed_length } qr/not a MARC::Record object/, 'Extractor should warn';
102
103
    # Check empty object
98
    my $record = MARC::Record->new;
104
    my $record = MARC::Record->new;
105
    $extractor = Koha::Biblio::Metadata::Extractor::MARC::MARC21->new( { metadata => $record } );
106
    my $result = $extractor->check_fixed_length;
107
    is( scalar @{ $result->{passed} }, 0, 'No passed fields' );
108
    is( scalar @{ $result->{failed} }, 0, 'No failed fields' );
109
99
    $record->append_fields(
110
    $record->append_fields(
100
        MARC::Field->new( '005', '0123456789012345' ),
111
        MARC::Field->new( '005', '0123456789012345' ),
101
    );
112
    );
102
    my $biblio = $builder->build_sample_biblio;
113
    my $biblio = $builder->build_sample_biblio;
103
    ModBiblio( $record, $biblio->biblionumber );
114
    ModBiblio( $record, $biblio->biblionumber );
104
115
105
    my $extractor;
106
    $extractor = Koha::Biblio::Metadata::Extractor::MARC::MARC21->new( { biblio => $biblio } );
116
    $extractor = Koha::Biblio::Metadata::Extractor::MARC::MARC21->new( { biblio => $biblio } );
107
    my $result = $extractor->check_fixed_length;
117
    $result = $extractor->check_fixed_length;
108
    is( $result->{passed}->[0],        '005', 'Check first passed field' );
118
    is( $result->{passed}->[0],        '005', 'Check first passed field' );
109
    is( scalar @{ $result->{failed} }, 0,     'Check failed count' );
119
    is( scalar @{ $result->{failed} }, 0,     'Check failed count' );
110
120
111
- 

Return to bug 40272