From 937e831ea300042e7be89fc9524bb871edaf23ba 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) Signed-off-by: David Nind Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit b048d155bf18d794d2ac97eaafc6f0fc00996018) Signed-off-by: Lucas Gass --- C4/Record.pm | 6 ++--- t/db_dependent/Record/marcrecord2csv.t | 32 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/C4/Record.pm b/C4/Record.pm index f4a75818dd..1916a1beca 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -513,7 +513,7 @@ sub marcrecord2csv { my @fields; while ( $content =~ m|(\d{3})\$?(.)?|g ) { my $fieldtag = $1; - my $subfieldtag = $2 || undef; + my $subfieldtag = $2; push @fields, { fieldtag => $fieldtag, subfieldtag => $subfieldtag }; } if ( @result == 2) { @@ -558,7 +558,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 +585,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..0dcdbab0b6 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; @@ -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.39.5