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

(-)a/Koha/Exporter/Record.pm (-19 / +18 lines)
Lines 91-97 sub _get_record_for_export { Link Here
91
    }
91
    }
92
    if ( !$record ) {
92
    if ( !$record ) {
93
        Koha::Logger->get->warn("Record $record_id with record type $record_type could not be exported.");
93
        Koha::Logger->get->warn("Record $record_id with record type $record_type could not be exported.");
94
        return;
94
        return 0;
95
    }
95
    }
96
96
97
    if ($dont_export_fields) {
97
    if ($dont_export_fields) {
Lines 114-120 sub _get_record_for_export { Link Here
114
        }
114
        }
115
    }
115
    }
116
116
117
    return                            if $conditions && !_record_match_conditions( $record, $conditions );
117
    return 0                          if $conditions && !_record_match_conditions( $record, $conditions );
118
    C4::Biblio::RemoveAllNsb($record) if $clean;
118
    C4::Biblio::RemoveAllNsb($record) if $clean;
119
    return $record;
119
    return $record;
120
}
120
}
Lines 125-134 sub _get_deleted_biblio_for_export { Link Here
125
125
126
    # Creating schema is expensive, so we cache it
126
    # Creating schema is expensive, so we cache it
127
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance();
127
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance();
128
    my $resultset = $memory_cache->get_from_cache('_get_deleted_biblio_for_export:resultset');
128
    my $resultset    = $memory_cache->get_from_cache('_get_deleted_biblio_for_export:resultset');
129
    unless ($resultset) {
129
    unless ($resultset) {
130
        $resultset = Koha::Database->new()->schema()->resultset('DeletedbiblioMetadata');
130
        $resultset = Koha::Database->new()->schema()->resultset('DeletedbiblioMetadata');
131
        $memory_cache->set_in_cache('_get_deleted_biblio_for_export:resultset', $resultset);
131
        $memory_cache->set_in_cache( '_get_deleted_biblio_for_export:resultset', $resultset );
132
    }
132
    }
133
133
134
    my $marc_flavour    = C4::Context->preference('marcflavour');
134
    my $marc_flavour    = C4::Context->preference('marcflavour');
Lines 142-148 sub _get_deleted_biblio_for_export { Link Here
142
142
143
    unless ($biblio_metadata) {
143
    unless ($biblio_metadata) {
144
        Koha::Logger->get->warn("Failed to load deleted biblio with biblionumber \"$biblionumber\"");
144
        Koha::Logger->get->warn("Failed to load deleted biblio with biblionumber \"$biblionumber\"");
145
        return
145
        return;
146
    }
146
    }
147
147
148
    my $marc_xml = $biblio_metadata->metadata;
148
    my $marc_xml = $biblio_metadata->metadata;
Lines 243-256 sub export { Link Here
243
    }
243
    }
244
244
245
    if ( $format eq 'xml' || $format eq 'iso2709' ) {
245
    if ( $format eq 'xml' || $format eq 'iso2709' ) {
246
        my @record_ids = reverse @{$record_ids};
246
        my @record_ids         = reverse @{$record_ids};
247
        my @deleted_record_ids = reverse @{$deleted_record_ids};
247
        my @deleted_record_ids = reverse @{$deleted_record_ids};
248
248
249
        my $records_iterator = sub {
249
        my $records_iterator = sub {
250
            if (my $record_id = pop(@record_ids)) {
250
            if ( my $record_id = pop(@record_ids) ) {
251
                return _get_record_for_export( { %{$params}, record_id => $record_id } );
251
                return _get_record_for_export( { %{$params}, record_id => $record_id } );
252
            }
252
            } elsif ( my $deleted_record_id = pop(@deleted_record_ids) ) {
253
            elsif (my $deleted_record_id = pop(@deleted_record_ids)) {
254
                return _get_record_for_export(
253
                return _get_record_for_export(
255
                    {
254
                    {
256
                        %{$params},
255
                        %{$params},
Lines 262-270 sub export { Link Here
262
            return;
261
            return;
263
        };
262
        };
264
263
265
        if ($format eq 'iso2709') {
264
        if ( $format eq 'iso2709' ) {
266
            my $encoding_validator = sub {
265
            my $encoding_validator = sub {
267
                my ( $record ) = @_;
266
                my ($record) = @_;
268
                my @decoding_warnings =
267
                my @decoding_warnings =
269
                    eval { MARC::File::USMARC->decode( $record->as_usmarc )->warnings() };
268
                    eval { MARC::File::USMARC->decode( $record->as_usmarc )->warnings() };
270
                my $error = $@;
269
                my $error = $@;
Lines 276-282 sub export { Link Here
276
                    if ($field) {
275
                    if ($field) {
277
                        $msg .= " " . $field->is_control_field ? $field->data : $field->subfield($id_code);
276
                        $msg .= " " . $field->is_control_field ? $field->data : $field->subfield($id_code);
278
                    }
277
                    }
279
                    my $warnings = join(', ', @decoding_warnings);
278
                    my $warnings = join( ', ', @decoding_warnings );
280
                    $msg .= " could not be USMARC decoded/encoded. " . ( $error // $warnings );
279
                    $msg .= " could not be USMARC decoded/encoded. " . ( $error // $warnings );
281
                    chomp $msg;
280
                    chomp $msg;
282
                    Koha::Logger->get->warn($msg);
281
                    Koha::Logger->get->warn($msg);
Lines 284-308 sub export { Link Here
284
                }
283
                }
285
                return 1;
284
                return 1;
286
            };
285
            };
287
            while (defined ( my $record = $records_iterator->() )) {
286
            while ( defined( my $record = $records_iterator->() ) ) {
288
                if ($encoding_validator->($record)) {
287
                next unless $record && $encoding_validator->($record);
289
                    print $record->as_usmarc();
288
                print $record->as_usmarc();
290
                }
291
            }
289
            }
292
        } elsif ($format eq 'xml') {
290
        } elsif ( $format eq 'xml' ) {
293
            my $marcflavour = C4::Context->preference("marcflavour");
291
            my $marcflavour = C4::Context->preference("marcflavour");
294
            MARC::File::XML->default_record_format(
292
            MARC::File::XML->default_record_format(
295
                ( $marcflavour eq 'UNIMARC' && $record_type eq 'auths' ) ? 'UNIMARCAUTH' : $marcflavour );
293
                ( $marcflavour eq 'UNIMARC' && $record_type eq 'auths' ) ? 'UNIMARCAUTH' : $marcflavour );
296
            print MARC::File::XML::header();
294
            print MARC::File::XML::header();
297
            print "\n";
295
            print "\n";
298
            while (defined ( my $record = $records_iterator->() )) {
296
            while ( defined( my $record = $records_iterator->() ) ) {
297
                next unless $record;
299
                print MARC::File::XML::record($record);
298
                print MARC::File::XML::record($record);
300
                print "\n";
299
                print "\n";
301
            }
300
            }
302
            print MARC::File::XML::footer();
301
            print MARC::File::XML::footer();
303
            print "\n";
302
            print "\n";
304
        }
303
        }
305
    } elsif ($format eq 'csv') {
304
    } elsif ( $format eq 'csv' ) {
306
        die 'There is no valid csv profile defined for this export'
305
        die 'There is no valid csv profile defined for this export'
307
            unless Koha::CsvProfiles->find($csv_profile_id);
306
            unless Koha::CsvProfiles->find($csv_profile_id);
308
        print marc2csv( $record_ids, $csv_profile_id, $itemnumbers );
307
        print marc2csv( $record_ids, $csv_profile_id, $itemnumbers );
(-)a/t/db_dependent/Exporter/Record.t (-7 / +5 lines)
Lines 367-373 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
367
            record_type       => 'bibs',
367
            record_type       => 'bibs',
368
        }
368
        }
369
    );
369
    );
370
    is( $record, undef, "Record condition \"080a!=12345\" should not match" );
370
    is( $record, 0, "Record condition \"080a!=12345\" should not match" );
371
371
372
    $record = Koha::Exporter::Record::_get_record_for_export(
372
    $record = Koha::Exporter::Record::_get_record_for_export(
373
        {
373
        {
Lines 394-400 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
394
            record_type       => 'bibs',
394
            record_type       => 'bibs',
395
        }
395
        }
396
    );
396
    );
397
    is( $record, undef, "Record condition \"080a>123456\" should not match" );
397
    is( $record, 0, "Record condition \"080a>123456\" should not match" );
398
398
399
    ## Multiple subfields
399
    ## Multiple subfields
400
400
Lines 414-421 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
414
            record_type       => 'bibs',
414
            record_type       => 'bibs',
415
        }
415
        }
416
    );
416
    );
417
    is( $record, undef, "Record condition \"035a=TEST(1234)\" should not match" )
417
    is( $record, 0, "Record condition \"035a=TEST(1234)\" should not match" );   # Since matching all subfields required
418
        ;    # Since matching all subfields required
419
418
420
    ## Multiple conditions
419
    ## Multiple conditions
421
420
Lines 435-441 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
435
            record_type       => 'bibs',
434
            record_type       => 'bibs',
436
        }
435
        }
437
    );
436
    );
438
    is( $record, undef, "Record condition \"035a!=TEST(12345),080a<1234\" should not match" );
437
    is( $record, 0, "Record condition \"035a!=TEST(12345),080a<1234\" should not match" );
439
438
440
    ## exists/not_exists
439
    ## exists/not_exists
441
440
Lines 456-462 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
456
            record_type       => 'bibs',
455
            record_type       => 'bibs',
457
        }
456
        }
458
    );
457
    );
459
    is( $record, undef, "Record condition \"not_exists(035a)\" should not match" );
458
    is( $record, 0, "Record condition \"not_exists(035a)\" should not match" );
460
};
459
};
461
460
462
$schema->storage->txn_rollback;
461
$schema->storage->txn_rollback;
463
- 

Return to bug 20551