From 9c4f91c4150fff75211888fba449b2412cc9091d Mon Sep 17 00:00:00 2001 From: Alexis Ripetti Date: Fri, 11 Sep 2020 16:11:55 -0400 Subject: [PATCH] Bug 26414: Unable to export Withdrawn status using CSV profile When using CSV profiles to export MARC records, it is impossible to export the withdrawn status. I suspect it is because withdrawn is in 952$0 and 0 is considered null rather than an actual 0. Test Plan : 1) Go to Tools > CSV profiles 2) Click on New CSV profile 3) Enter a profile name (ex. Simple record) 4) In the Profile MARC fields field enter the following (for MARC21) 245a|100a|952o|9520 5) Save your profile 6) Go to Search and search for something 7) Add a couple of things in your cart 8) Go to your cart 9) Click on Download and choose your CSV profile 10) Open the file and notice the 9520 column contains the whole of the 952 field and not just the withdrawn status 11) Apply patch 12) Redo steps 9) and 10) --- C4/Record.pm | 7 +++--- t/db_dependent/Record/marcrecord2csv.t | 34 ++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/C4/Record.pm b/C4/Record.pm index f4a75818dd..39cef43469 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -513,7 +513,8 @@ sub marcrecord2csv { my @fields; while ( $content =~ m|(\d{3})\$?(.)?|g ) { my $fieldtag = $1; - my $subfieldtag = $2 || undef; + my $subfieldtag = ( defined $2 ) ? $2 : undef; + #my $subfieldtag = $2 || undef; push @fields, { fieldtag => $fieldtag, subfieldtag => $subfieldtag }; } if ( @result == 2) { @@ -558,7 +559,7 @@ sub marcrecord2csv { } else { # If not, we get the matching tag name from koha my $tag = $tags->[0]; - if ( $tag->{subfieldtag} ) { + if (defined $tag->{subfieldtag} ) { my $query = "SELECT liblibrarian FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield=?"; my @results = $dbh->selectrow_array( $query, {}, $tag->{fieldtag}, $tag->{subfieldtag} ); push @marcfieldsheaders, $results[0]; @@ -585,7 +586,7 @@ sub marcrecord2csv { my @fields = $record->field( $tag->{fieldtag} ); # If it is a subfield my @loop_values; - if ( $tag->{subfieldtag} ) { + if (defined $tag->{subfieldtag} ) { my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, tagsubfield => $tag->{subfieldtag}, }); $av = $av->count ? $av->unblessed : []; my $av_description_mapping = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av }; diff --git a/t/db_dependent/Record/marcrecord2csv.t b/t/db_dependent/Record/marcrecord2csv.t index a2ae394e2c..2d5f732a14 100644 --- a/t/db_dependent/Record/marcrecord2csv.t +++ b/t/db_dependent/Record/marcrecord2csv.t @@ -1,7 +1,7 @@ #!/usr/bin/perl; use Modern::Perl; -use Test::More tests => 12; +use Test::More tests => 13; use Test::MockModule; use MARC::Record; use MARC::Field; @@ -12,6 +12,8 @@ use C4::Context; use C4::Record; use Koha::Database; +use C4::Items; + use t::lib::TestBuilder; my $schema = Koha::Database->new->schema; @@ -48,7 +50,7 @@ $csv_content = q(245|650); my $csv_profile_id_2 = insert_csv_profile({ csv_content => $csv_content }); $csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_2, 1, $csv ); -is( $csv_output, q["TITLE STATEMENT"|"SUBJECT ADDED ENTRY--TOPICAL TERM" +is( $csv_output, q["Mention du titre"|Vedette-matière--Sujet "The art of computer programming,Donald E. Knuth.,0;The art of another title,Donald E. Knuth. II,1"|"Computer programming.,462;Computer algorithms.,499" ], q|normal way: headers retrieved from the DB| ); @@ -126,6 +128,33 @@ is( $csv_output, q[Title|AVs +# Bug 26414 - Unable to export Withdrawn status using CSV profile +# Test that subfieldtag '0' works in the fieldtag '952' +my $record2 = new_record(); +my $frameworkcode2 = q||; +# We change the barcode of the second item record to prevent an error "duplicate entry" +my $field = $record->field('952'); +my $new_field = new MARC::Field('952', ' ', ' ', + 0 => '1', + p => '3010023918', +); +$field->replace_with($new_field); +# We create another record +my ( $biblionumber2, $biblioitemnumber2 ) = AddBiblio( $record2, $frameworkcode2 ); +# We add two item to two record to test fieldtag 952 and subfieldtag 9520 +my (undef, undef, $itemnumber2) = AddItemFromMarc($record2, $biblionumber); +my (undef, undef, $itemnumber) = AddItemFromMarc($record, $biblionumber); +$csv_content = q(Titre=245a|Nom de personne=100a|Statut « Élagué »=9520); +my $csv_profile_id_10 = insert_csv_profile( {csv_content => $csv_content } ); +$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_10, 1, $csv); +is($csv_output, q[Titre|"Nom de personne"|"Statut « Élagué »" +"The art of computer programming,The art of another title"|"Knuth, Donald Ervin"|Withdrawn;Withdrawn +], q|subfieldtag 952$0 is not working, should return 'Withdrawn'| +); + +# End Bug 26414 + + sub insert_csv_profile { my ( $params ) = @_; my $csv_content = $params->{csv_content}; @@ -172,6 +201,7 @@ sub new_record { ), MARC::Field->new( 952, ' ', ' ', + 0 => '1', p => '3010023917', y => 'BK', c => 'GEN', -- 2.25.1