@@ -, +, @@ profile --- C4/Record.pm | 6 ++--- t/db_dependent/Record/marcrecord2csv.t | 32 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) --- a/C4/Record.pm +++ a/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 }; --- a/t/db_dependent/Record/marcrecord2csv.t +++ a/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', --