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

(-)a/C4/Record.pm (-3 / +3 lines)
Lines 513-519 sub marcrecord2csv { Link Here
513
        my @fields;
513
        my @fields;
514
        while ( $content =~ m|(\d{3})\$?(.)?|g ) {
514
        while ( $content =~ m|(\d{3})\$?(.)?|g ) {
515
            my $fieldtag = $1;
515
            my $fieldtag = $1;
516
            my $subfieldtag = $2 || undef;
516
            my $subfieldtag = $2;
517
            push @fields, { fieldtag => $fieldtag, subfieldtag => $subfieldtag };
517
            push @fields, { fieldtag => $fieldtag, subfieldtag => $subfieldtag };
518
        }
518
        }
519
        if ( @result == 2) {
519
        if ( @result == 2) {
Lines 558-564 sub marcrecord2csv { Link Here
558
            } else {
558
            } else {
559
                # If not, we get the matching tag name from koha
559
                # If not, we get the matching tag name from koha
560
                my $tag = $tags->[0];
560
                my $tag = $tags->[0];
561
                if ( $tag->{subfieldtag} ) {
561
                if (defined $tag->{subfieldtag} ) {
562
                    my $query = "SELECT liblibrarian FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield=?";
562
                    my $query = "SELECT liblibrarian FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield=?";
563
                    my @results = $dbh->selectrow_array( $query, {}, $tag->{fieldtag}, $tag->{subfieldtag} );
563
                    my @results = $dbh->selectrow_array( $query, {}, $tag->{fieldtag}, $tag->{subfieldtag} );
564
                    push @marcfieldsheaders, $results[0];
564
                    push @marcfieldsheaders, $results[0];
Lines 585-591 sub marcrecord2csv { Link Here
585
                my @fields = $record->field( $tag->{fieldtag} );
585
                my @fields = $record->field( $tag->{fieldtag} );
586
                # If it is a subfield
586
                # If it is a subfield
587
                my @loop_values;
587
                my @loop_values;
588
                if ( $tag->{subfieldtag} ) {
588
                if (defined $tag->{subfieldtag} ) {
589
                    my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, tagsubfield => $tag->{subfieldtag}, });
589
                    my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, tagsubfield => $tag->{subfieldtag}, });
590
                    $av = $av->count ? $av->unblessed : [];
590
                    $av = $av->count ? $av->unblessed : [];
591
                    my $av_description_mapping = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av };
591
                    my $av_description_mapping = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av };
(-)a/t/db_dependent/Record/marcrecord2csv.t (-2 / +31 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl;
1
#!/usr/bin/perl;
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 12;
4
use Test::More tests => 13;
5
use Test::MockModule;
5
use Test::MockModule;
6
use MARC::Record;
6
use MARC::Record;
7
use MARC::Field;
7
use MARC::Field;
Lines 12-17 use C4::Context; Link Here
12
use C4::Record;
12
use C4::Record;
13
use Koha::Database;
13
use Koha::Database;
14
14
15
use C4::Items;
16
15
use t::lib::TestBuilder;
17
use t::lib::TestBuilder;
16
18
17
my $schema = Koha::Database->new->schema;
19
my $schema = Koha::Database->new->schema;
Lines 126-131 is( $csv_output, q[Title|AVs Link Here
126
128
127
129
128
130
131
# Bug 26414 - Unable to export Withdrawn status using CSV profile
132
# Test that subfieldtag '0' works in the fieldtag '952'
133
my $record2 = new_record();
134
my $frameworkcode2 = q||;
135
# We change the barcode of the second item record to prevent an error "duplicate entry"
136
my $field = $record->field('952');
137
my $new_field = new MARC::Field('952', ' ', ' ',
138
    0 => '1',
139
    p => '3010023918',
140
);
141
$field->replace_with($new_field);
142
# We create another record
143
my ( $biblionumber2, $biblioitemnumber2 ) = AddBiblio( $record2, $frameworkcode2 );
144
# We add two item to two record to test fieldtag 952 and subfieldtag 9520
145
my (undef, undef, $itemnumber2) = AddItemFromMarc($record2, $biblionumber);
146
my (undef, undef, $itemnumber) = AddItemFromMarc($record, $biblionumber);
147
$csv_content = q(Titre=245a|Nom de personne=100a|Statut « Élagué »=9520);
148
my $csv_profile_id_10 = insert_csv_profile( {csv_content => $csv_content } );
149
$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_10, 1, $csv);
150
is($csv_output, q[Titre|"Nom de personne"|"Statut « Élagué »"
151
"The art of computer programming,The art of another title"|"Knuth, Donald Ervin"|Withdrawn;Withdrawn
152
], q|subfieldtag 952$0 is not working, should return 'Withdrawn'|
153
);
154
155
# End Bug 26414
156
157
129
sub insert_csv_profile {
158
sub insert_csv_profile {
130
    my ( $params ) = @_;
159
    my ( $params ) = @_;
131
    my $csv_content = $params->{csv_content};
160
    my $csv_content = $params->{csv_content};
Lines 172-177 sub new_record { Link Here
172
        ),
201
        ),
173
        MARC::Field->new(
202
        MARC::Field->new(
174
            952, ' ', ' ',
203
            952, ' ', ' ',
204
            0 => '1',
175
            p => '3010023917',
205
            p => '3010023917',
176
            y => 'BK',
206
            y => 'BK',
177
            c => 'GEN',
207
            c => 'GEN',
178
- 

Return to bug 26414