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 403-412 C<$csvprofileid> - the id of the CSV profile to use for the export (see export_f Link Here
403
404
404
C<$itemnumbers> - a list of itemnumbers to export
405
C<$itemnumbers> - a list of itemnumbers to export
405
406
407
C<$marc_modification_template_id> - MARC modification template to apply
408
406
=cut
409
=cut
407
410
408
sub marc2csv {
411
sub marc2csv {
409
    my ($biblios, $id, $itemnumbers) = @_;
412
    my ($biblios, $id, $itemnumbers, $marc_modification_template_id) = @_;
410
    $itemnumbers ||= [];
413
    $itemnumbers ||= [];
411
    my $output;
414
    my $output;
412
    my $csv = Text::CSV::Encoded->new();
415
    my $csv = Text::CSV::Encoded->new();
Lines 426-437 sub marc2csv { Link Here
426
        for my $itemnumber ( @$itemnumbers) {
429
        for my $itemnumber ( @$itemnumbers) {
427
            my $item = Koha::Items->find( $itemnumber );
430
            my $item = Koha::Items->find( $itemnumber );
428
            my $biblionumber = $item->biblio->biblionumber;
431
            my $biblionumber = $item->biblio->biblionumber;
429
            $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber] ) // '';
432
            $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber], $marc_modification_template_id ) // '';
430
            $firstpass = 0;
433
            $firstpass = 0;
431
        }
434
        }
432
    } else {
435
    } else {
433
        foreach my $biblio (@$biblios) {
436
        foreach my $biblio (@$biblios) {
434
            $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing ) // '';
437
            $output .= marcrecord2csv( $biblio, $id, $firstpass, $csv, $fieldprocessing, undef, $marc_modification_template_id ) // '';
435
            $firstpass = 0;
438
            $firstpass = 0;
436
        }
439
        }
437
    }
440
    }
Lines 444-450 sub marc2csv { Link Here
444
447
445
=head2 marcrecord2csv - Convert a single record from UNIMARC to CSV
448
=head2 marcrecord2csv - Convert a single record from UNIMARC to CSV
446
449
447
  my ($csv) = marcrecord2csv($biblio, $csvprofileid, $header);
450
  my ($csv) = marcrecord2csv($biblio, $csvprofileid, $header, $csv, $fieldprocessing, $itemnumbers, $marc_modification_template_id);
448
451
449
Returns a CSV scalar
452
Returns a CSV scalar
450
453
Lines 460-469 C<$fieldprocessing> Link Here
460
463
461
C<$itemnumbers> a list of itemnumbers to export
464
C<$itemnumbers> a list of itemnumbers to export
462
465
466
C<$marc_modification_template_id> - MARC modification template to apply
467
463
=cut
468
=cut
464
469
465
sub marcrecord2csv {
470
sub marcrecord2csv {
466
    my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_;
471
    my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers, $marc_modification_template_id) = @_;
467
    my $output;
472
    my $output;
468
473
469
    # Getting the record
474
    # Getting the record
Lines 473-478 sub marcrecord2csv { Link Here
473
        marc_record  => $record,
478
        marc_record  => $record,
474
        biblionumber => $biblio,
479
        biblionumber => $biblio,
475
        item_numbers => $itemnumbers });
480
        item_numbers => $itemnumbers });
481
482
    if ($marc_modification_template_id) {
483
        C4::MarcModificationTemplates::ModifyRecordWithTemplate($marc_modification_template_id, $record);
484
    }
485
476
    # Getting the framework
486
    # Getting the framework
477
    my $frameworkcode = GetFrameworkCode($biblio);
487
    my $frameworkcode = GetFrameworkCode($biblio);
478
488
(-)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 87-93 my $bad_item = $builder->build({ # Cannot call build_sample_item, we want incons Link Here
87
103
88
subtest 'export csv' => sub {
104
subtest 'export csv' => sub {
89
    plan tests => 3;
105
    plan tests => 3;
90
    my $csv_content = q{Title=245$a|Barcode=952$p};
106
    my $csv_content = qq{Title=$title_field\$$title_subfield|Barcode=$item_field\$$barcode_subfield};
91
    $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');
107
    $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');
92
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
108
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
93
    my $generated_csv_file = '/tmp/test_export_1.csv';
109
    my $generated_csv_file = '/tmp/test_export_1.csv';
Lines 160-166 subtest 'export xml' => sub { Link Here
160
    }
176
    }
161
    is( scalar( @records ), 2, 'Export XML: 2 records should have been exported' );
177
    is( scalar( @records ), 2, 'Export XML: 2 records should have been exported' );
162
    my $second_record = $records[1];
178
    my $second_record = $records[1];
163
    my $title = $second_record->subfield(245, 'a');
179
    my $title = $second_record->subfield($title_field, $title_subfield);
164
    $title = Encode::encode('UTF-8', $title);
180
    $title = Encode::encode('UTF-8', $title);
165
    is( $title, $biblio_2_title, 'Export XML: The title is correctly encoded' );
181
    is( $title, $biblio_2_title, 'Export XML: The title is correctly encoded' );
166
};
182
};
Lines 187-193 subtest 'export iso2709' => sub { Link Here
187
    }
203
    }
188
    is( scalar( @records ), 2, 'Export ISO2709: 2 records should have been exported' );
204
    is( scalar( @records ), 2, 'Export ISO2709: 2 records should have been exported' );
189
    my $second_record = $records[1];
205
    my $second_record = $records[1];
190
    my $title = $second_record->subfield(245, 'a');
206
    my $title = $second_record->subfield($title_field, $title_subfield);
191
    $title = Encode::encode('UTF-8', $title);
207
    $title = Encode::encode('UTF-8', $title);
192
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
208
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
193
};
209
};
Lines 209-218 subtest '_get_biblio_for_export' => sub { Link Here
209
225
210
    my $biblio = MARC::Record->new();
226
    my $biblio = MARC::Record->new();
211
    $biblio->leader('00266nam a22001097a 4500');
227
    $biblio->leader('00266nam a22001097a 4500');
212
    $biblio->append_fields(
228
    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
213
        MARC::Field->new( '100', ' ', ' ', a => 'Thurber, James' ),
229
        $biblio->append_fields(
214
        MARC::Field->new( '245', ' ', ' ', a => "The 13 Clocks" ),
230
            MARC::Field->new( '200', ' ', ' ', a => "The 13 Clocks", f => 'Thurber, James' ),
215
    );
231
        );
232
    } else {
233
        $biblio->append_fields(
234
            MARC::Field->new( '100', ' ', ' ', a => 'Thurber, James' ),
235
            MARC::Field->new( '245', ' ', ' ', a => "The 13 Clocks" ),
236
        );
237
    }
216
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
238
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
217
    my $branch_a = $builder->build({source => 'Branch',});
239
    my $branch_a = $builder->build({source => 'Branch',});
218
    my $branch_b = $builder->build({source => 'Branch',});
240
    my $branch_b = $builder->build({source => 'Branch',});
Lines 236-242 subtest '_get_biblio_for_export' => sub { Link Here
236
            only_export_items_for_branches => undef
258
            only_export_items_for_branches => undef
237
        }
259
        }
238
    );
260
    );
239
    my @items = $record->field('952');
261
    my @items = $record->field($item_field);
240
    is( scalar @items, 2, "We should retrieve all items if we don't pass specific branches and request items" );
262
    is( scalar @items, 2, "We should retrieve all items if we don't pass specific branches and request items" );
241
263
242
    $record = Koha::Exporter::Record::_get_biblio_for_export(
264
    $record = Koha::Exporter::Record::_get_biblio_for_export(
Lines 246-255 subtest '_get_biblio_for_export' => sub { Link Here
246
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
268
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
247
        }
269
        }
248
    );
270
    );
249
    @items = $record->field('952');
271
    @items = $record->field($item_field);
250
    is( scalar @items, 1, "We should retrieve only item for branch_b item if we request items and pass branch" );
272
    is( scalar @items, 1, "We should retrieve only item for branch_b item if we request items and pass branch" );
251
    is(
273
    is(
252
        $items[0]->subfield('a'),
274
        $items[0]->subfield($homebranch_subfield),
253
        $branch_b->{branchcode},
275
        $branch_b->{branchcode},
254
        "And the homebranch for that item should be branch_b branchcode"
276
        "And the homebranch for that item should be branch_b branchcode"
255
    );
277
    );
Lines 261-267 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, 0, "We should not have any items if we don't request items and pass a branch");
287
    is( scalar @items, 0, "We should not have any items if we don't request items and pass a branch");
266
288
267
};
289
};
Lines 272-279 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
272
    my $biblio = MARC::Record->new();
294
    my $biblio = MARC::Record->new();
273
    $biblio->leader('00266nam a22001097a 4500');
295
    $biblio->leader('00266nam a22001097a 4500');
274
    $biblio->append_fields(
296
    $biblio->append_fields(
275
        MARC::Field->new( '100', ' ', ' ', a => 'Thurber, James' ),
297
        MARC::Field->new( '200', ' ', ' ', f => 'Thurber, James' ),
276
        MARC::Field->new( '245', ' ', ' ', a => 'The 13 Clocks' ),
298
        MARC::Field->new( '200', ' ', ' ', a => 'The 13 Clocks' ),
277
        MARC::Field->new( '080', ' ', ' ', a => '12345' ),
299
        MARC::Field->new( '080', ' ', ' ', a => '12345' ),
278
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)123' ),
300
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)123' ),
279
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)1234' ),
301
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)1234' ),
Lines 391-394 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
391
    is( $record, undef, "Record condition \"not_exists(035a)\" should not match" );
413
    is( $record, undef, "Record condition \"not_exists(035a)\" should not match" );
392
};
414
};
393
415
416
subtest 'export csv with marc modification template' => sub {
417
    plan tests => 1;
418
    my $csv_content = qq{Title=$title_field\$$title_subfield|Test=999\$9};
419
    $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');
420
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
421
422
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
423
    C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar');
424
425
    my $generated_csv_file = '/tmp/test_export_1.csv';
426
    Koha::Exporter::Record::export({
427
        record_type     => 'bibs',
428
        record_ids      => [ $biblionumber_1 ],
429
        format          => 'csv',
430
        csv_profile_id  => $csv_profile_id,
431
        marc_modification_template_id => $template_id,
432
        output_filepath => $generated_csv_file,
433
    });
434
435
    my $expected_csv = <<EOF;
436
Title|Test
437
"$biblio_1_title"|Foobar
438
EOF
439
    my $generated_csv_content = read_file( $generated_csv_file );
440
    is( $generated_csv_content, $expected_csv, "Export CSV: Modification template should have been applied" );
441
};
442
443
subtest 'export xml with marc modification template' => sub {
444
    plan tests => 2;
445
446
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
447
    C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar');
448
449
    my $generated_xml_file = '/tmp/test_export.xml';
450
    Koha::Exporter::Record::export({
451
        record_type     => 'bibs',
452
        record_ids      => [ $biblionumber_1 ],
453
        format          => 'xml',
454
        marc_modification_template_id => $template_id,
455
        output_filepath => $generated_xml_file,
456
    });
457
458
    my $generated_xml_content = read_file( $generated_xml_file );
459
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
460
    open my $fh, '<', $generated_xml_file;
461
    my $records = MARC::Batch->new( 'XML', $fh );
462
    my @records;
463
    while ( my $record = $records->next ) {
464
        push @records, $record;
465
    }
466
    is( scalar( @records ), 1, 'Export XML: 1 record should have been exported' );
467
    my $record = $records[0];
468
    is( $record->subfield('999', '9'), 'Foobar', 'Export XML: marc modification template should have added 999$9' );
469
};
470
471
subtest 'export iso2709 with marc modification template' => sub {
472
    plan tests => 2;
473
474
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
475
    C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar');
476
477
    my $generated_mrc_file = '/tmp/test_export.mrc';
478
    Koha::Exporter::Record::export({
479
        record_type     => 'bibs',
480
        record_ids      => [ $biblionumber_1 ],
481
        format          => 'iso2709',
482
        marc_modification_template_id => $template_id,
483
        output_filepath => $generated_mrc_file,
484
    });
485
486
    my $records = MARC::File::USMARC->in( $generated_mrc_file );
487
    my @records;
488
    while ( my $record = $records->next ) {
489
        push @records, $record;
490
    }
491
    is( scalar( @records ), 1, 'Export ISO2709: 1 record should have been exported' );
492
    my $record = $records[0];
493
    is( $record->subfield('999', '9'), 'Foobar', 'Export ISO2709: marc modification template should have added 999$9' );
494
};
495
394
$schema->storage->txn_rollback;
496
$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 211-216 if ( $op eq "export" ) { Link Here
211
                csv_profile_id     => $csv_profile_id,
212
                csv_profile_id     => $csv_profile_id,
212
                export_items       => (not $dont_export_items),
213
                export_items       => (not $dont_export_items),
213
                only_export_items_for_branches => $only_export_items_for_branches,
214
                only_export_items_for_branches => $only_export_items_for_branches,
215
                marc_modification_template_id => scalar $query->param('marc_modification_template_id'),
214
            }
216
            }
215
        );
217
        );
216
    }
218
    }
Lines 297-302 else { Link Here
297
            { directory => "$backupdir", extension => 'tar' } );
299
            { directory => "$backupdir", extension => 'tar' } );
298
    }
300
    }
299
301
302
    my @marc_modification_templates = C4::MarcModificationTemplates::GetModificationTemplates();
303
300
    $template->param(
304
    $template->param(
301
        libraries                => $libraries,
305
        libraries                => $libraries,
302
        itemtypes                => $itemtypes,
306
        itemtypes                => $itemtypes,
Lines 304-309 else { Link Here
304
        export_remove_fields     => C4::Context->preference("ExportRemoveFields"),
308
        export_remove_fields     => C4::Context->preference("ExportRemoveFields"),
305
        csv_profiles             => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
309
        csv_profiles             => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
306
        messages                 => \@messages,
310
        messages                 => \@messages,
311
        marc_modification_templates => \@marc_modification_templates,
307
    );
312
    );
308
313
309
    output_html_with_http_headers $query, $cookie, $template->output;
314
    output_html_with_http_headers $query, $cookie, $template->output;
310
- 

Return to bug 24679