Bugzilla – Attachment 180664 Details for
Bug 20551
Add option for including deleted records in export_records.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20551: Return 0 instead of undef from _get_record_for_export not to break iterator loop
Bug-20551-Return-0-instead-of-undef-from-getrecord.patch (text/plain), 7.46 KB, created by
Andrew Fuerste-Henry
on 2025-04-04 16:14:26 UTC
(
hide
)
Description:
Bug 20551: Return 0 instead of undef from _get_record_for_export not to break iterator loop
Filename:
MIME Type:
Creator:
Andrew Fuerste-Henry
Created:
2025-04-04 16:14:26 UTC
Size:
7.46 KB
patch
obsolete
>From b4c473222645d2562f880b3c8393faf653cdeaa4 Mon Sep 17 00:00:00 2001 >From: David Gustafsson <david.gustafsson@ub.gu.se> >Date: Thu, 27 Mar 2025 00:00:21 +0100 >Subject: [PATCH] Bug 20551: Return 0 instead of undef from > _get_record_for_export not to break iterator loop > >Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> >--- > Koha/Exporter/Record.pm | 37 ++++++++++++++++---------------- > t/db_dependent/Exporter/Record.t | 11 +++++----- > 2 files changed, 23 insertions(+), 25 deletions(-) > >diff --git a/Koha/Exporter/Record.pm b/Koha/Exporter/Record.pm >index 63e6f2c6de..0d19828624 100644 >--- a/Koha/Exporter/Record.pm >+++ b/Koha/Exporter/Record.pm >@@ -91,7 +91,7 @@ sub _get_record_for_export { > } > if ( !$record ) { > Koha::Logger->get->warn("Record $record_id with record type $record_type could not be exported."); >- return; >+ return 0; > } > > if ($dont_export_fields) { >@@ -114,7 +114,7 @@ sub _get_record_for_export { > } > } > >- return if $conditions && !_record_match_conditions( $record, $conditions ); >+ return 0 if $conditions && !_record_match_conditions( $record, $conditions ); > C4::Biblio::RemoveAllNsb($record) if $clean; > return $record; > } >@@ -125,10 +125,10 @@ sub _get_deleted_biblio_for_export { > > # Creating schema is expensive, so we cache it > my $memory_cache = Koha::Cache::Memory::Lite->get_instance(); >- my $resultset = $memory_cache->get_from_cache('_get_deleted_biblio_for_export:resultset'); >+ my $resultset = $memory_cache->get_from_cache('_get_deleted_biblio_for_export:resultset'); > unless ($resultset) { > $resultset = Koha::Database->new()->schema()->resultset('DeletedbiblioMetadata'); >- $memory_cache->set_in_cache('_get_deleted_biblio_for_export:resultset', $resultset); >+ $memory_cache->set_in_cache( '_get_deleted_biblio_for_export:resultset', $resultset ); > } > > my $marc_flavour = C4::Context->preference('marcflavour'); >@@ -142,7 +142,7 @@ sub _get_deleted_biblio_for_export { > > unless ($biblio_metadata) { > Koha::Logger->get->warn("Failed to load deleted biblio with biblionumber \"$biblionumber\""); >- return >+ return; > } > > my $marc_xml = $biblio_metadata->metadata; >@@ -243,14 +243,13 @@ sub export { > } > > if ( $format eq 'xml' || $format eq 'iso2709' ) { >- my @record_ids = reverse @{$record_ids}; >+ my @record_ids = reverse @{$record_ids}; > my @deleted_record_ids = reverse @{$deleted_record_ids}; > > my $records_iterator = sub { >- if (my $record_id = pop(@record_ids)) { >+ if ( my $record_id = pop(@record_ids) ) { > return _get_record_for_export( { %{$params}, record_id => $record_id } ); >- } >- elsif (my $deleted_record_id = pop(@deleted_record_ids)) { >+ } elsif ( my $deleted_record_id = pop(@deleted_record_ids) ) { > return _get_record_for_export( > { > %{$params}, >@@ -262,9 +261,9 @@ sub export { > return; > }; > >- if ($format eq 'iso2709') { >+ if ( $format eq 'iso2709' ) { > my $encoding_validator = sub { >- my ( $record ) = @_; >+ my ($record) = @_; > my @decoding_warnings = > eval { MARC::File::USMARC->decode( $record->as_usmarc )->warnings() }; > my $error = $@; >@@ -276,7 +275,7 @@ sub export { > if ($field) { > $msg .= " " . $field->is_control_field ? $field->data : $field->subfield($id_code); > } >- my $warnings = join(', ', @decoding_warnings); >+ my $warnings = join( ', ', @decoding_warnings ); > $msg .= " could not be USMARC decoded/encoded. " . ( $error // $warnings ); > chomp $msg; > Koha::Logger->get->warn($msg); >@@ -284,25 +283,25 @@ sub export { > } > return 1; > }; >- while (defined ( my $record = $records_iterator->() )) { >- if ($encoding_validator->($record)) { >- print $record->as_usmarc(); >- } >+ while ( defined( my $record = $records_iterator->() ) ) { >+ next unless $record && $encoding_validator->($record); >+ print $record->as_usmarc(); > } >- } elsif ($format eq 'xml') { >+ } elsif ( $format eq 'xml' ) { > my $marcflavour = C4::Context->preference("marcflavour"); > MARC::File::XML->default_record_format( > ( $marcflavour eq 'UNIMARC' && $record_type eq 'auths' ) ? 'UNIMARCAUTH' : $marcflavour ); > print MARC::File::XML::header(); > print "\n"; >- while (defined ( my $record = $records_iterator->() )) { >+ while ( defined( my $record = $records_iterator->() ) ) { >+ next unless $record; > print MARC::File::XML::record($record); > print "\n"; > } > print MARC::File::XML::footer(); > print "\n"; > } >- } elsif ($format eq 'csv') { >+ } elsif ( $format eq 'csv' ) { > die 'There is no valid csv profile defined for this export' > unless Koha::CsvProfiles->find($csv_profile_id); > print marc2csv( $record_ids, $csv_profile_id, $itemnumbers ); >diff --git a/t/db_dependent/Exporter/Record.t b/t/db_dependent/Exporter/Record.t >index 8947a2984f..802b8532d3 100755 >--- a/t/db_dependent/Exporter/Record.t >+++ b/t/db_dependent/Exporter/Record.t >@@ -367,7 +367,7 @@ subtest '_get_record_for_export MARC field conditions' => sub { > record_type => 'bibs', > } > ); >- is( $record, undef, "Record condition \"080a!=12345\" should not match" ); >+ is( $record, 0, "Record condition \"080a!=12345\" should not match" ); > > $record = Koha::Exporter::Record::_get_record_for_export( > { >@@ -394,7 +394,7 @@ subtest '_get_record_for_export MARC field conditions' => sub { > record_type => 'bibs', > } > ); >- is( $record, undef, "Record condition \"080a>123456\" should not match" ); >+ is( $record, 0, "Record condition \"080a>123456\" should not match" ); > > ## Multiple subfields > >@@ -414,8 +414,7 @@ subtest '_get_record_for_export MARC field conditions' => sub { > record_type => 'bibs', > } > ); >- is( $record, undef, "Record condition \"035a=TEST(1234)\" should not match" ) >- ; # Since matching all subfields required >+ is( $record, 0, "Record condition \"035a=TEST(1234)\" should not match" ); # Since matching all subfields required > > ## Multiple conditions > >@@ -435,7 +434,7 @@ subtest '_get_record_for_export MARC field conditions' => sub { > record_type => 'bibs', > } > ); >- is( $record, undef, "Record condition \"035a!=TEST(12345),080a<1234\" should not match" ); >+ is( $record, 0, "Record condition \"035a!=TEST(12345),080a<1234\" should not match" ); > > ## exists/not_exists > >@@ -456,7 +455,7 @@ subtest '_get_record_for_export MARC field conditions' => sub { > record_type => 'bibs', > } > ); >- is( $record, undef, "Record condition \"not_exists(035a)\" should not match" ); >+ is( $record, 0, "Record condition \"not_exists(035a)\" should not match" ); > }; > > $schema->storage->txn_rollback; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20551
:
73916
|
73923
|
75113
|
82843
|
82914
|
82918
|
90184
|
90190
|
90220
|
93619
|
93620
|
93621
|
105403
|
116408
|
116409
|
116410
|
116411
|
123099
|
123101
|
123102
|
125211
|
125212
|
125213
|
125214
|
125215
|
125216
|
128895
|
128896
|
128897
|
128898
|
128899
|
128900
|
132936
|
132937
|
176623
|
176624
|
176625
|
176626
|
176627
|
176628
|
176629
|
176630
|
176631
|
177536
|
178343
|
178344
|
178345
|
178346
|
178347
|
178348
|
178349
|
178350
|
178351
|
178352
|
178353
|
178378
|
178379
|
178575
|
178617
|
178618
|
178619
|
178679
|
178680
|
178681
|
178682
|
179748
|
179749
|
180648
|
180649
|
180650
|
180651
|
180652
|
180653
|
180654
|
180655
|
180656
|
180657
|
180658
|
180659
|
180660
|
180661
|
180662
|
180663
| 180664 |
180665