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

(-)a/Koha/Exporter/Record.pm (-8 / +14 lines)
Lines 8-13 use C4::AuthoritiesMarc; Link Here
8
use C4::Biblio;
8
use C4::Biblio;
9
use C4::Record;
9
use C4::Record;
10
use Koha::CsvProfiles;
10
use Koha::CsvProfiles;
11
use Koha::Logger;
11
12
12
sub _get_record_for_export {
13
sub _get_record_for_export {
13
    my ($params)           = @_;
14
    my ($params)           = @_;
Lines 22-32 sub _get_record_for_export { Link Here
22
    } elsif ( $record_type eq 'bibs' ) {
23
    } elsif ( $record_type eq 'bibs' ) {
23
        $record = _get_biblio_for_export( { %$params, biblionumber => $record_id } );
24
        $record = _get_biblio_for_export( { %$params, biblionumber => $record_id } );
24
    } else {
25
    } else {
25
26
        Koha::Logger->get->warn( "Record_type $record_type not supported." );
26
        # TODO log "record_type not supported"
27
        return;
28
    }
27
    }
29
30
    return unless $record;
28
    return unless $record;
31
29
32
    if ($dont_export_fields) {
30
    if ($dont_export_fields) {
Lines 99-105 sub export { Link Here
99
    my $csv_profile_id     = $params->{csv_profile_id};
97
    my $csv_profile_id     = $params->{csv_profile_id};
100
    my $output_filepath    = $params->{output_filepath};
98
    my $output_filepath    = $params->{output_filepath};
101
99
102
    return unless $record_type;
100
    if( !$record_type ) {
101
        Koha::Logger->get->warn( "No record_type given." );
102
        return;
103
    }
103
    return unless @$record_ids;
104
    return unless @$record_ids;
104
105
105
    my $fh;
106
    my $fh;
Lines 116-123 sub export { Link Here
116
            my $record = _get_record_for_export( { %$params, record_id => $record_id } );
117
            my $record = _get_record_for_export( { %$params, record_id => $record_id } );
117
            my $errorcount_on_decode = eval { scalar( MARC::File::USMARC->decode( $record->as_usmarc )->warnings() ) };
118
            my $errorcount_on_decode = eval { scalar( MARC::File::USMARC->decode( $record->as_usmarc )->warnings() ) };
118
            if ( $errorcount_on_decode or $@ ) {
119
            if ( $errorcount_on_decode or $@ ) {
119
                warn $@ if $@;
120
                my $msg = "Record $record_id could not be exported. " .
120
                warn "record (number $record_id) is invalid and therefore not exported because its reopening generates warnings above";
121
                    ( $@ // '' );
122
                chomp $msg;
123
                Koha::Logger->get->info( $msg );
121
                next;
124
                next;
122
            }
125
            }
123
            print $record->as_usmarc();
126
            print $record->as_usmarc();
Lines 130-136 sub export { Link Here
130
        print "\n";
133
        print "\n";
131
        for my $record_id (@$record_ids) {
134
        for my $record_id (@$record_ids) {
132
            my $record = _get_record_for_export( { %$params, record_id => $record_id } );
135
            my $record = _get_record_for_export( { %$params, record_id => $record_id } );
133
            next unless $record;
136
            if( !$record ) {
137
                Koha::Logger->get->info( "Record $record_id could not be exported." );
138
                next;
139
            }
134
            print MARC::File::XML::record($record);
140
            print MARC::File::XML::record($record);
135
            print "\n";
141
            print "\n";
136
        }
142
        }
(-)a/t/db_dependent/Exporter/Record.t (-2 / +13 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 3;
20
use Test::More tests => 4;
21
use t::lib::TestBuilder;
21
use t::lib::TestBuilder;
22
22
23
use MARC::Record;
23
use MARC::Record;
Lines 176-181 subtest 'export iso2709' => sub { Link Here
176
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
176
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
177
};
177
};
178
178
179
subtest 'export without record_type' => sub {
180
    plan tests => 1;
181
182
    my $rv = Koha::Exporter::Record::export({
183
            record_ids => [ $biblionumber_1, $biblionumber_2 ],
184
            format => 'iso2709',
185
            output_filepath => 'does_not_matter_here',
186
    });
187
    is( $rv, undef, 'export returns undef' );
188
    #Depending on your logger config, you might have a warn in your logs
189
};
190
179
$schema->storage->txn_rollback;
191
$schema->storage->txn_rollback;
180
192
181
1;
193
1;
182
- 

Return to bug 17088