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

(-)a/Koha/Biblio/Metadata/Extractor/MARC/MARC21.pm (+54 lines)
Lines 96-101 sub get_normalized_oclc { Link Here
96
    }
96
    }
97
}
97
}
98
98
99
=head2 check_fixed_length
100
101
    my $info = $extractor->check_fixed_length;
102
103
Returns a hash containing passed and failed fixed-length control fields.
104
105
=cut
106
107
sub check_fixed_length {
108
    my $self   = shift;
109
    my $len_ok = {
110
        '005' => 16,
111
        '006' => 18,
112
        '007' => {
113
            a => 8,
114
            c => [ 6, 14 ],
115
            d => 6,
116
            f => 10,
117
            g => 9,
118
            h => 13,
119
            k => 6,
120
            m => [ 8, 23 ],
121
            o => 2,
122
            q => 2,
123
            r => 11,
124
            s => 14,
125
            t => 2,
126
            v => 9,
127
            z => 2,
128
        },
129
        '008' => 40,
130
    };
131
    my $record = $self->metadata;
132
    my $result = { passed => [], failed => [] };
133
    foreach my $field ( $record->field( '005', '006', '007', '008' ) ) {
134
        my ( $length, $pass );
135
        if ( $field->tag ne '007' ) {
136
            $length = $len_ok->{ $field->tag };
137
            $pass   = length( $field->data ) eq $length;
138
        } else {
139
            my $pos_0 = substr( $field->data, 0, 1 );
140
            $length = $len_ok->{ $field->tag }->{$pos_0};
141
            if ( ref($length) eq 'ARRAY' ) {
142
                $pass = grep { $_ eq length( $field->data ) } @$length;
143
            } else {
144
                $pass = length( $field->data ) eq $length;
145
            }
146
        }
147
        push @{ $result->{passed} }, $field->tag if $pass;
148
        push @{ $result->{failed} }, $field->tag unless $pass;
149
    }
150
    return $result;
151
}
152
99
=head1 AUTHOR
153
=head1 AUTHOR
100
154
101
Tomas Cohen Arazi, E<lt>tomascohen@theke.ioE<gt>
155
Tomas Cohen Arazi, E<lt>tomascohen@theke.ioE<gt>
(-)a/cataloguing/addbiblio.pl (-2 / +9 lines)
Lines 1-4 Link Here
1
#!/usr/bin/perl 
1
#!/usr/bin/perl
2
2
3
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2004-2010 BibLibre
4
# Copyright 2004-2010 BibLibre
Lines 53-59 use Koha::Biblios; Link Here
53
use Koha::ItemTypes;
53
use Koha::ItemTypes;
54
use Koha::Libraries;
54
use Koha::Libraries;
55
55
56
use Koha::BiblioFrameworks;
56
use Koha::Biblio::Metadata::Extractor::MARC::MARC21;
57
use Koha::Patrons;
57
use Koha::Patrons;
58
use Koha::UI::Form::Builder::Biblio;
58
use Koha::UI::Form::Builder::Biblio;
59
59
Lines 833-838 if ( $op eq "cud-addbiblio" ) { Link Here
833
    #----------------------------------------------------------------------------
833
    #----------------------------------------------------------------------------
834
    # If we're in a duplication case, we have to set to "" the biblionumber
834
    # If we're in a duplication case, we have to set to "" the biblionumber
835
    # as we'll save the biblio as a new one.
835
    # as we'll save the biblio as a new one.
836
837
    if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
838
        my $fixed_length_info =
839
            Koha::Biblio::Metadata::Extractor::MARC::MARC21->new( { biblio => $biblio } )->check_fixed_length;
840
        $template->param( marc21_fixlen => $fixed_length_info ) if @{ $fixed_length_info->{failed} };
841
    }
842
836
    $template->param(
843
    $template->param(
837
        biblionumberdata => $biblionumber,
844
        biblionumberdata => $biblionumber,
838
        op               => $op,
845
        op               => $op,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (+4 lines)
Lines 805-810 Link Here
805
        </div>
805
        </div>
806
    [% END %]
806
    [% END %]
807
807
808
    [% IF marc21_fixlen %]
809
        <div class="alert alert-warning"><h1>WARNING</h1><p>The following fixed-length control field(s) have an invalid length: [% marc21_fixlen.failed.join(',') | html %]. Please fix.</p></div>
810
    [% END %]
811
808
    [% IF ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_editcatalogue_advanced_editor ) %]
812
    [% IF ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_editcatalogue_advanced_editor ) %]
809
        <div id="toggle-editor">
813
        <div id="toggle-editor">
810
            <label for="toggle-editor">Advanced editor: </label>
814
            <label for="toggle-editor">Advanced editor: </label>
(-)a/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC/MARC21.t (-2 / +39 lines)
Lines 20-32 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 4;
23
use Test::More tests => 5;
24
use Test::Exception;
24
use Test::Exception;
25
25
26
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
27
use t::lib::Mocks;
27
use t::lib::Mocks;
28
28
29
use C4::Biblio qw(ModBiblio);
29
use Koha::Biblio::Metadata::Extractor;
30
use Koha::Biblio::Metadata::Extractor;
31
use Koha::Biblio::Metadata::Extractor::MARC::MARC21;
30
32
31
my $schema  = Koha::Database->schema;
33
my $schema  = Koha::Database->schema;
32
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
Lines 87-89 subtest 'get_normalized_oclc() tests' => sub { Link Here
87
    is( $extractor->get_normalized_oclc, "" );
89
    is( $extractor->get_normalized_oclc, "" );
88
90
89
};
91
};
90
- 
92
93
subtest 'check_fixed_length' => sub {
94
95
    plan tests => 6;
96
    $schema->storage->txn_begin;
97
98
    my $record = MARC::Record->new;
99
    $record->append_fields(
100
        MARC::Field->new( '005', '0123456789012345' ),
101
    );
102
    my $biblio = $builder->build_sample_biblio;
103
    ModBiblio( $record, $biblio->biblionumber );
104
105
    my $extractor;
106
    $extractor = Koha::Biblio::Metadata::Extractor::MARC::MARC21->new( { biblio => $biblio } );
107
    my $result = $extractor->check_fixed_length;
108
    is( $result->{passed}->[0],        '005', 'Check first passed field' );
109
    is( scalar @{ $result->{failed} }, 0,     'Check failed count' );
110
111
    $record->append_fields(
112
        MARC::Field->new( '006', '01234567890123456789' ),      # too long
113
        MARC::Field->new( '007', 'a1234567' ),
114
        MARC::Field->new( '007', 'm12345678' ),                 # should be 8 or 23
115
        MARC::Field->new( '007', 'm1234567890123456789012' ),
116
    );
117
118
    # Passing latest record changes via metadata now
119
    $extractor = Koha::Biblio::Metadata::Extractor::MARC::MARC21->new( { metadata => $record } );
120
    $result    = $extractor->check_fixed_length;
121
    is( $result->{passed}->[1], '007', 'Check second passed field' );
122
    is( $result->{passed}->[2], '007', 'Check third passed field' );
123
    is( $result->{failed}->[0], '006', 'Check first failed field' );
124
    is( $result->{failed}->[1], '007', 'Check second failed field' );
125
126
    $schema->storage->txn_rollback;
127
};

Return to bug 40272