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

(-)a/C4/Record.pm (-5 / +15 lines)
Lines 29-34 use Unicode::Normalize; # _entity_encode Link Here
29
use C4::Biblio; #marc2bibtex
29
use C4::Biblio; #marc2bibtex
30
use C4::Koha; #marc2csv
30
use C4::Koha; #marc2csv
31
use C4::XSLT ();
31
use C4::XSLT ();
32
use C4::MarcModificationTemplates;
32
use YAML; #marcrecords2csv
33
use YAML; #marcrecords2csv
33
use Template;
34
use Template;
34
use Text::CSV::Encoded; #marc2csv
35
use Text::CSV::Encoded; #marc2csv
Lines 404-413 C<$csvprofileid> - the id of the CSV profile to use for the export (see export_f Link Here
404
405
405
C<$itemnumbers> - a list of itemnumbers to export
406
C<$itemnumbers> - a list of itemnumbers to export
406
407
408
C<$marc_modification_template_id> - MARC modification template to apply
409
407
=cut
410
=cut
408
411
409
sub marc2csv {
412
sub marc2csv {
410
    my ($biblios, $id, $itemnumbers) = @_;
413
    my ($biblios, $id, $itemnumbers, $marc_modification_template_id) = @_;
411
    $itemnumbers ||= [];
414
    $itemnumbers ||= [];
412
    my $output;
415
    my $output;
413
    my $csv = Text::CSV::Encoded->new();
416
    my $csv = Text::CSV::Encoded->new();
Lines 427-438 sub marc2csv { Link Here
427
        for my $itemnumber ( @$itemnumbers) {
430
        for my $itemnumber ( @$itemnumbers) {
428
            my $item = Koha::Items->find( $itemnumber );
431
            my $item = Koha::Items->find( $itemnumber );
429
            my $biblionumber = $item->biblio->biblionumber;
432
            my $biblionumber = $item->biblio->biblionumber;
430
            $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber] ) // '';
433
            $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber], $marc_modification_template_id ) // '';
431
            $firstpass = 0;
434
            $firstpass = 0;
432
        }
435
        }
433
    } else {
436
    } else {
434
        foreach my $biblio (@$biblios) {
437
        foreach my $biblio (@$biblios) {
435
            $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing ) // '';
438
            $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing, undef, $marc_modification_template_id ) // '';
436
            $firstpass = 0;
439
            $firstpass = 0;
437
        }
440
        }
438
    }
441
    }
Lines 445-451 sub marc2csv { Link Here
445
448
446
=head2 marcrecord2csv - Convert a single record from UNIMARC to CSV
449
=head2 marcrecord2csv - Convert a single record from UNIMARC to CSV
447
450
448
  my ($csv) = marcrecord2csv($biblio, $csvprofileid, $header);
451
  my ($csv) = marcrecord2csv($biblio, $csvprofileid, $header, $csv, $fieldprocessing, $itemnumbers, $marc_modification_template_id);
449
452
450
Returns a CSV scalar
453
Returns a CSV scalar
451
454
Lines 461-470 C<$fieldprocessing> Link Here
461
464
462
C<$itemnumbers> a list of itemnumbers to export
465
C<$itemnumbers> a list of itemnumbers to export
463
466
467
C<$marc_modification_template_id> - MARC modification template to apply
468
464
=cut
469
=cut
465
470
466
sub marcrecord2csv {
471
sub marcrecord2csv {
467
    my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_;
472
    my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers, $marc_modification_template_id) = @_;
468
    my $output;
473
    my $output;
469
474
470
    # Getting the record
475
    # Getting the record
Lines 474-479 sub marcrecord2csv { Link Here
474
        marc_record  => $record,
479
        marc_record  => $record,
475
        biblionumber => $biblio,
480
        biblionumber => $biblio,
476
        item_numbers => $itemnumbers });
481
        item_numbers => $itemnumbers });
482
483
    if ($marc_modification_template_id) {
484
        C4::MarcModificationTemplates::ModifyRecordWithTemplate($marc_modification_template_id, $record);
485
    }
486
477
    # Getting the framework
487
    # Getting the framework
478
    my $frameworkcode = GetFrameworkCode($biblio);
488
    my $frameworkcode = GetFrameworkCode($biblio);
479
489
(-)a/Koha/Exporter/Record.pm (-1 / +17 lines)
Lines 7-12 use MARC::File::USMARC; Link Here
7
use C4::AuthoritiesMarc;
7
use C4::AuthoritiesMarc;
8
use C4::Biblio;
8
use C4::Biblio;
9
use C4::Record;
9
use C4::Record;
10
use C4::MarcModificationTemplates;
10
use Koha::CsvProfiles;
11
use Koha::CsvProfiles;
11
use Koha::Logger;
12
use Koha::Logger;
12
use List::Util qw(all any);
13
use List::Util qw(all any);
Lines 155-160 sub export { Link Here
155
    my $dont_export_fields = $params->{dont_export_fields};
156
    my $dont_export_fields = $params->{dont_export_fields};
156
    my $csv_profile_id     = $params->{csv_profile_id};
157
    my $csv_profile_id     = $params->{csv_profile_id};
157
    my $output_filepath    = $params->{output_filepath};
158
    my $output_filepath    = $params->{output_filepath};
159
    my $marc_modification_template_id = $params->{marc_modification_template_id};
158
160
159
    if( !$record_type ) {
161
    if( !$record_type ) {
160
        Koha::Logger->get->warn( "No record_type given." );
162
        Koha::Logger->get->warn( "No record_type given." );
Lines 183-188 sub export { Link Here
183
                Koha::Logger->get->info( $msg );
185
                Koha::Logger->get->info( $msg );
184
                next;
186
                next;
185
            }
187
            }
188
189
            if ($marc_modification_template_id) {
190
                C4::MarcModificationTemplates::ModifyRecordWithTemplate($marc_modification_template_id, $record);
191
            }
192
186
            print $record->as_usmarc();
193
            print $record->as_usmarc();
187
        }
194
        }
188
    } elsif ( $format eq 'xml' ) {
195
    } elsif ( $format eq 'xml' ) {
Lines 194-199 sub export { Link Here
194
        for my $record_id (@$record_ids) {
201
        for my $record_id (@$record_ids) {
195
            my $record = _get_record_for_export( { %$params, record_id => $record_id } );
202
            my $record = _get_record_for_export( { %$params, record_id => $record_id } );
196
            next unless $record;
203
            next unless $record;
204
205
            if ($marc_modification_template_id) {
206
                C4::MarcModificationTemplates::ModifyRecordWithTemplate($marc_modification_template_id, $record);
207
            }
208
197
            print MARC::File::XML::record($record);
209
            print MARC::File::XML::record($record);
198
            print "\n";
210
            print "\n";
199
        }
211
        }
Lines 202-208 sub export { Link Here
202
    } elsif ( $format eq 'csv' ) {
214
    } elsif ( $format eq 'csv' ) {
203
        die 'There is no valid csv profile defined for this export'
215
        die 'There is no valid csv profile defined for this export'
204
            unless Koha::CsvProfiles->find( $csv_profile_id );
216
            unless Koha::CsvProfiles->find( $csv_profile_id );
205
        print marc2csv( $record_ids, $csv_profile_id, $itemnumbers );
217
        print marc2csv( $record_ids, $csv_profile_id, $itemnumbers, $marc_modification_template_id );
206
    }
218
    }
207
219
208
    close $fh if $output_filepath;
220
    close $fh if $output_filepath;
Lines 263-268 It will displays on STDOUT the generated file. Link Here
263
275
264
  If the format is csv, you have to define a csv_profile_id.
276
  If the format is csv, you have to define a csv_profile_id.
265
277
278
=item marc_modification_template_id
279
280
  Apply MARC modification template to records before export
281
266
=cut
282
=cut
267
283
268
=back
284
=back
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt (-1 / +24 lines)
Lines 129-135 Link Here
129
        <label for="export_remove_fields">Don't export fields:</label>
129
        <label for="export_remove_fields">Don't export fields:</label>
130
        <input id="export_remove_fields" type="text" name="export_remove_fields" value="[% export_remove_fields | html %]" />
130
        <input id="export_remove_fields" type="text" name="export_remove_fields" value="[% export_remove_fields | html %]" />
131
        separate by a blank. (e.g., 100a 200 606)
131
        separate by a blank. (e.g., 100a 200 606)
132
        </li></ol>
132
        </li>
133
        [% IF marc_modification_templates.size > 0 %]
134
            <li>
135
                <label for="marc_modification_template_id">Modify records using template:</label>
136
                <select id="marc_modification_template_id" name="marc_modification_template_id">
137
                    <option value=""></option>
138
                    [% FOREACH marc_modification_template IN marc_modification_templates %]
139
                        <option value="[% marc_modification_template.template_id | html %]">[% marc_modification_template.name | html %]</option>
140
                    [% END %]
141
                </select>
142
            </li>
143
        [% END %]
144
    </ol>
133
    </fieldset>
145
    </fieldset>
134
    <fieldset class="rows">
146
    <fieldset class="rows">
135
    <legend>
147
    <legend>
Lines 201-206 Link Here
201
    <fieldset class="rows">
213
    <fieldset class="rows">
202
    <legend>Options</legend>
214
    <legend>Options</legend>
203
        <ol>
215
        <ol>
216
        [% IF marc_modification_templates.size > 0 %]
217
            <li>
218
                <label for="marc_modification_template_id">Modify records using template:</label>
219
                <select id="marc_modification_template_id" name="marc_modification_template_id">
220
                    <option value=""></option>
221
                    [% FOREACH marc_modification_template IN marc_modification_templates %]
222
                        <option value="[% marc_modification_template.template_id | html %]">[% marc_modification_template.name | html %]</option>
223
                    [% END %]
224
                </select>
225
            </li>
226
        [% END %]
204
        <li>
227
        <li>
205
            <label for="export_remove_fields">Don't export fields:</label>
228
            <label for="export_remove_fields">Don't export fields:</label>
206
            <input id="export_remove_fields" type="text" name="export_remove_fields" />
229
            <input id="export_remove_fields" type="text" name="export_remove_fields" />
(-)a/t/db_dependent/Exporter/Record.t (-23 / +125 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 6;
20
use Test::More tests => 9;
21
use Test::Warn;
21
use Test::Warn;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
Lines 45-61 my $biblio_1_title = 'Silence in the library'; Link Here
45
my $biblio_2_title = 'The art of computer programming ກ ຂ ຄ ງ ຈ ຊ ຍ é';
45
my $biblio_2_title = 'The art of computer programming ກ ຂ ຄ ງ ຈ ຊ ຍ é';
46
my $biblio_1 = MARC::Record->new();
46
my $biblio_1 = MARC::Record->new();
47
$biblio_1->leader('00266nam a22001097a 4500');
47
$biblio_1->leader('00266nam a22001097a 4500');
48
$biblio_1->append_fields(
49
    MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
50
    MARC::Field->new('245', ' ', ' ', a => $biblio_1_title),
51
);
52
my ($biblionumber_1, $biblioitemnumber_1) = AddBiblio($biblio_1, '');
53
my $biblio_2 = MARC::Record->new();
48
my $biblio_2 = MARC::Record->new();
54
$biblio_2->leader('00266nam a22001097a 4500');
49
$biblio_2->leader('00266nam a22001097a 4500');
55
$biblio_2->append_fields(
50
56
    MARC::Field->new('100', ' ', ' ', a => 'Knuth, Donald Ervin'),
51
my ($title_field, $title_subfield, $item_field, $barcode_subfield, $homebranch_subfield);
57
    MARC::Field->new('245', ' ', ' ', a => $biblio_2_title),
52
if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
58
);
53
    $biblio_1->append_fields(
54
        MARC::Field->new('200', ' ', ' ', a => $biblio_1_title, f => 'Moffat, Steven'),
55
    );
56
    $biblio_2->append_fields(
57
        MARC::Field->new('200', ' ', ' ', a => $biblio_2_title, f => 'Knuth, Donald Ervin'),
58
    );
59
    ($title_field, $title_subfield) = ('200', 'a');
60
    ($item_field, $barcode_subfield, $homebranch_subfield) = ('995', 'f', 'b');
61
} else {
62
    $biblio_1->append_fields(
63
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
64
        MARC::Field->new('245', ' ', ' ', a => $biblio_1_title),
65
    );
66
    $biblio_2->append_fields(
67
        MARC::Field->new('100', ' ', ' ', a => 'Knuth, Donald Ervin'),
68
        MARC::Field->new('245', ' ', ' ', a => $biblio_2_title),
69
    );
70
    ($title_field, $title_subfield) = ('245', 'a');
71
    ($item_field, $barcode_subfield, $homebranch_subfield) = ('952', 'p', 'a');
72
}
73
74
my ($biblionumber_1, $biblioitemnumber_1) = AddBiblio($biblio_1, '');
59
my ($biblionumber_2, $biblioitemnumber_2) = AddBiblio($biblio_2, '');
75
my ($biblionumber_2, $biblioitemnumber_2) = AddBiblio($biblio_2, '');
60
76
61
my $bad_biblio = Koha::Biblio->new()->store();
77
my $bad_biblio = Koha::Biblio->new()->store();
Lines 94-100 my $bad_item = $builder->build({ Link Here
94
110
95
subtest 'export csv' => sub {
111
subtest 'export csv' => sub {
96
    plan tests => 3;
112
    plan tests => 3;
97
    my $csv_content = q{Title=245$a|Barcode=952$p};
113
    my $csv_content = qq{Title=$title_field\$$title_subfield|Barcode=$item_field\$$barcode_subfield};
98
    $dbh->do(q|INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)|, {}, "TEST_PROFILE_Records.t", "my useless desc", $csv_content, '|', ';', ',', 'utf8', 'marc');
114
    $dbh->do(q|INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)|, {}, "TEST_PROFILE_Records.t", "my useless desc", $csv_content, '|', ';', ',', 'utf8', 'marc');
99
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
115
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
100
    my $generated_csv_file = '/tmp/test_export_1.csv';
116
    my $generated_csv_file = '/tmp/test_export_1.csv';
Lines 167-173 subtest 'export xml' => sub { Link Here
167
    }
183
    }
168
    is( scalar( @records ), 2, 'Export XML: 2 records should have been exported' );
184
    is( scalar( @records ), 2, 'Export XML: 2 records should have been exported' );
169
    my $second_record = $records[1];
185
    my $second_record = $records[1];
170
    my $title = $second_record->subfield(245, 'a');
186
    my $title = $second_record->subfield($title_field, $title_subfield);
171
    $title = Encode::encode('UTF-8', $title);
187
    $title = Encode::encode('UTF-8', $title);
172
    is( $title, $biblio_2_title, 'Export XML: The title is correctly encoded' );
188
    is( $title, $biblio_2_title, 'Export XML: The title is correctly encoded' );
173
};
189
};
Lines 194-200 subtest 'export iso2709' => sub { Link Here
194
    }
210
    }
195
    is( scalar( @records ), 2, 'Export ISO2709: 2 records should have been exported' );
211
    is( scalar( @records ), 2, 'Export ISO2709: 2 records should have been exported' );
196
    my $second_record = $records[1];
212
    my $second_record = $records[1];
197
    my $title = $second_record->subfield(245, 'a');
213
    my $title = $second_record->subfield($title_field, $title_subfield);
198
    $title = Encode::encode('UTF-8', $title);
214
    $title = Encode::encode('UTF-8', $title);
199
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
215
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
200
};
216
};
Lines 216-225 subtest '_get_biblio_for_export' => sub { Link Here
216
232
217
    my $biblio = MARC::Record->new();
233
    my $biblio = MARC::Record->new();
218
    $biblio->leader('00266nam a22001097a 4500');
234
    $biblio->leader('00266nam a22001097a 4500');
219
    $biblio->append_fields(
235
    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
220
        MARC::Field->new( '100', ' ', ' ', a => 'Thurber, James' ),
236
        $biblio->append_fields(
221
        MARC::Field->new( '245', ' ', ' ', a => "The 13 Clocks" ),
237
            MARC::Field->new( '200', ' ', ' ', a => "The 13 Clocks", f => 'Thurber, James' ),
222
    );
238
        );
239
    } else {
240
        $biblio->append_fields(
241
            MARC::Field->new( '100', ' ', ' ', a => 'Thurber, James' ),
242
            MARC::Field->new( '245', ' ', ' ', a => "The 13 Clocks" ),
243
        );
244
    }
223
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
245
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
224
    my $branch_a = $builder->build({source => 'Branch',});
246
    my $branch_a = $builder->build({source => 'Branch',});
225
    my $branch_b = $builder->build({source => 'Branch',});
247
    my $branch_b = $builder->build({source => 'Branch',});
Lines 251-257 subtest '_get_biblio_for_export' => sub { Link Here
251
            only_export_items_for_branches => undef
273
            only_export_items_for_branches => undef
252
        }
274
        }
253
    );
275
    );
254
    my @items = $record->field('952');
276
    my @items = $record->field($item_field);
255
    is( scalar @items, 2, "We should retrieve all items if we don't pass specific branches and request items" );
277
    is( scalar @items, 2, "We should retrieve all items if we don't pass specific branches and request items" );
256
278
257
    $record = Koha::Exporter::Record::_get_biblio_for_export(
279
    $record = Koha::Exporter::Record::_get_biblio_for_export(
Lines 261-270 subtest '_get_biblio_for_export' => sub { Link Here
261
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
283
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
262
        }
284
        }
263
    );
285
    );
264
    @items = $record->field('952');
286
    @items = $record->field($item_field);
265
    is( scalar @items, 1, "We should retrieve only item for branch_b item if we request items and pass branch" );
287
    is( scalar @items, 1, "We should retrieve only item for branch_b item if we request items and pass branch" );
266
    is(
288
    is(
267
        $items[0]->subfield('a'),
289
        $items[0]->subfield($homebranch_subfield),
268
        $branch_b->{branchcode},
290
        $branch_b->{branchcode},
269
        "And the homebranch for that item should be branch_b branchcode"
291
        "And the homebranch for that item should be branch_b branchcode"
270
    );
292
    );
Lines 276-282 subtest '_get_biblio_for_export' => sub { Link Here
276
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
298
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
277
        }
299
        }
278
    );
300
    );
279
    @items = $record->field('952');
301
    @items = $record->field($item_field);
280
    is( scalar @items, 0, "We should not have any items if we don't request items and pass a branch");
302
    is( scalar @items, 0, "We should not have any items if we don't request items and pass a branch");
281
303
282
};
304
};
Lines 287-294 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
287
    my $biblio = MARC::Record->new();
309
    my $biblio = MARC::Record->new();
288
    $biblio->leader('00266nam a22001097a 4500');
310
    $biblio->leader('00266nam a22001097a 4500');
289
    $biblio->append_fields(
311
    $biblio->append_fields(
290
        MARC::Field->new( '100', ' ', ' ', a => 'Thurber, James' ),
312
        MARC::Field->new( '200', ' ', ' ', f => 'Thurber, James' ),
291
        MARC::Field->new( '245', ' ', ' ', a => 'The 13 Clocks' ),
313
        MARC::Field->new( '200', ' ', ' ', a => 'The 13 Clocks' ),
292
        MARC::Field->new( '080', ' ', ' ', a => '12345' ),
314
        MARC::Field->new( '080', ' ', ' ', a => '12345' ),
293
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)123' ),
315
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)123' ),
294
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)1234' ),
316
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)1234' ),
Lines 406-409 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
406
    is( $record, undef, "Record condition \"not_exists(035a)\" should not match" );
428
    is( $record, undef, "Record condition \"not_exists(035a)\" should not match" );
407
};
429
};
408
430
431
subtest 'export csv with marc modification template' => sub {
432
    plan tests => 1;
433
    my $csv_content = qq{Title=$title_field\$$title_subfield|Test=999\$9};
434
    $dbh->do(q|INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)|, {}, "TEST_PROFILE_Records.t", "my useless desc", $csv_content, '|', ';', ',', 'utf8', 'marc');
435
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
436
437
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
438
    C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar');
439
440
    my $generated_csv_file = '/tmp/test_export_1.csv';
441
    Koha::Exporter::Record::export({
442
        record_type     => 'bibs',
443
        record_ids      => [ $biblionumber_1 ],
444
        format          => 'csv',
445
        csv_profile_id  => $csv_profile_id,
446
        marc_modification_template_id => $template_id,
447
        output_filepath => $generated_csv_file,
448
    });
449
450
    my $expected_csv = <<EOF;
451
Title|Test
452
"$biblio_1_title"|Foobar
453
EOF
454
    my $generated_csv_content = read_file( $generated_csv_file );
455
    is( $generated_csv_content, $expected_csv, "Export CSV: Modification template should have been applied" );
456
};
457
458
subtest 'export xml with marc modification template' => sub {
459
    plan tests => 2;
460
461
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
462
    C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar');
463
464
    my $generated_xml_file = '/tmp/test_export.xml';
465
    Koha::Exporter::Record::export({
466
        record_type     => 'bibs',
467
        record_ids      => [ $biblionumber_1 ],
468
        format          => 'xml',
469
        marc_modification_template_id => $template_id,
470
        output_filepath => $generated_xml_file,
471
    });
472
473
    my $generated_xml_content = read_file( $generated_xml_file );
474
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
475
    open my $fh, '<', $generated_xml_file;
476
    my $records = MARC::Batch->new( 'XML', $fh );
477
    my @records;
478
    while ( my $record = $records->next ) {
479
        push @records, $record;
480
    }
481
    is( scalar( @records ), 1, 'Export XML: 1 record should have been exported' );
482
    my $record = $records[0];
483
    is( $record->subfield('999', '9'), 'Foobar', 'Export XML: marc modification template should have added 999$9' );
484
};
485
486
subtest 'export iso2709 with marc modification template' => sub {
487
    plan tests => 2;
488
489
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
490
    C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar');
491
492
    my $generated_mrc_file = '/tmp/test_export.mrc';
493
    Koha::Exporter::Record::export({
494
        record_type     => 'bibs',
495
        record_ids      => [ $biblionumber_1 ],
496
        format          => 'iso2709',
497
        marc_modification_template_id => $template_id,
498
        output_filepath => $generated_mrc_file,
499
    });
500
501
    my $records = MARC::File::USMARC->in( $generated_mrc_file );
502
    my @records;
503
    while ( my $record = $records->next ) {
504
        push @records, $record;
505
    }
506
    is( scalar( @records ), 1, 'Export ISO2709: 1 record should have been exported' );
507
    my $record = $records[0];
508
    is( $record->subfield('999', '9'), 'Foobar', 'Export ISO2709: marc modification template should have added 999$9' );
509
};
510
409
$schema->storage->txn_rollback;
511
$schema->storage->txn_rollback;
(-)a/tools/export.pl (-1 / +5 lines)
Lines 22-27 use MARC::File::XML; Link Here
22
use List::MoreUtils qw(uniq);
22
use List::MoreUtils qw(uniq);
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Output;
24
use C4::Output;
25
use C4::MarcModificationTemplates;
25
26
26
use Koha::Authority::Types;
27
use Koha::Authority::Types;
27
use Koha::Biblioitems;
28
use Koha::Biblioitems;
Lines 214-219 if ( $op eq "export" ) { Link Here
214
                csv_profile_id     => $csv_profile_id,
215
                csv_profile_id     => $csv_profile_id,
215
                export_items       => (not $dont_export_items),
216
                export_items       => (not $dont_export_items),
216
                only_export_items_for_branches => $only_export_items_for_branches,
217
                only_export_items_for_branches => $only_export_items_for_branches,
218
                marc_modification_template_id => scalar $query->param('marc_modification_template_id'),
217
            }
219
            }
218
        );
220
        );
219
    }
221
    }
Lines 300-305 else { Link Here
300
            { directory => "$backupdir", extension => 'tar' } );
302
            { directory => "$backupdir", extension => 'tar' } );
301
    }
303
    }
302
304
305
    my @marc_modification_templates = C4::MarcModificationTemplates::GetModificationTemplates();
306
303
    $template->param(
307
    $template->param(
304
        libraries                => $libraries,
308
        libraries                => $libraries,
305
        itemtypes                => $itemtypes,
309
        itemtypes                => $itemtypes,
Lines 307-312 else { Link Here
307
        export_remove_fields     => C4::Context->preference("ExportRemoveFields"),
311
        export_remove_fields     => C4::Context->preference("ExportRemoveFields"),
308
        csv_profiles             => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
312
        csv_profiles             => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
309
        messages                 => \@messages,
313
        messages                 => \@messages,
314
        marc_modification_templates => \@marc_modification_templates,
310
    );
315
    );
311
316
312
    output_html_with_http_headers $query, $cookie, $template->output;
317
    output_html_with_http_headers $query, $cookie, $template->output;
313
- 

Return to bug 24679