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

(-)a/C4/Record.pm (-3 / +4 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 = ( defined $2 ) ? $2 : undef;
517
            #my $subfieldtag = $2 || undef;
517
            push @fields, { fieldtag => $fieldtag, subfieldtag => $subfieldtag };
518
            push @fields, { fieldtag => $fieldtag, subfieldtag => $subfieldtag };
518
        }
519
        }
519
        if ( @result == 2) {
520
        if ( @result == 2) {
Lines 558-564 sub marcrecord2csv { Link Here
558
            } else {
559
            } else {
559
                # If not, we get the matching tag name from koha
560
                # If not, we get the matching tag name from koha
560
                my $tag = $tags->[0];
561
                my $tag = $tags->[0];
561
                if ( $tag->{subfieldtag} ) {
562
                if (defined $tag->{subfieldtag} ) {
562
                    my $query = "SELECT liblibrarian FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield=?";
563
                    my $query = "SELECT liblibrarian FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield=?";
563
                    my @results = $dbh->selectrow_array( $query, {}, $tag->{fieldtag}, $tag->{subfieldtag} );
564
                    my @results = $dbh->selectrow_array( $query, {}, $tag->{fieldtag}, $tag->{subfieldtag} );
564
                    push @marcfieldsheaders, $results[0];
565
                    push @marcfieldsheaders, $results[0];
Lines 585-591 sub marcrecord2csv { Link Here
585
                my @fields = $record->field( $tag->{fieldtag} );
586
                my @fields = $record->field( $tag->{fieldtag} );
586
                # If it is a subfield
587
                # If it is a subfield
587
                my @loop_values;
588
                my @loop_values;
588
                if ( $tag->{subfieldtag} ) {
589
                if (defined $tag->{subfieldtag} ) {
589
                    my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, tagsubfield => $tag->{subfieldtag}, });
590
                    my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, tagsubfield => $tag->{subfieldtag}, });
590
                    $av = $av->count ? $av->unblessed : [];
591
                    $av = $av->count ? $av->unblessed : [];
591
                    my $av_description_mapping = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av };
592
                    my $av_description_mapping = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av };
(-)a/t/db_dependent/Record/marcrecord2csv.t (-3 / +32 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 48-54 $csv_content = q(245|650); Link Here
48
my $csv_profile_id_2 = insert_csv_profile({ csv_content => $csv_content });
50
my $csv_profile_id_2 = insert_csv_profile({ csv_content => $csv_content });
49
51
50
$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_2, 1, $csv );
52
$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_2, 1, $csv );
51
is( $csv_output, q["TITLE STATEMENT"|"SUBJECT ADDED ENTRY--TOPICAL TERM"
53
is( $csv_output, q["Mention du titre"|Vedette-matière--Sujet
52
"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"
54
"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"
53
], q|normal way: headers retrieved from the DB| );
55
], q|normal way: headers retrieved from the DB| );
54
56
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