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

(-)a/C4/Holdings.pm (+47 lines)
Lines 368-373 sub GetXmlHolding { Link Here
368
    return $marcxml;
368
    return $marcxml;
369
}
369
}
370
370
371
=head2 GetMarcHoldingsByBiblionumber
372
373
  my $records = GetMarcHoldingsByBiblionumber(biblionumber);
374
375
Returns MARC::Record array representing holding records
376
377
=over 4
378
379
=item C<$biblionumber>
380
381
biblionumber
382
383
=back
384
385
=cut
386
387
sub GetMarcHoldingsByBiblionumber {
388
    my $biblionumber = shift;
389
390
    my $marcflavour = C4::Context->preference('marcflavour');
391
    my $sth = C4::Context->dbh->prepare(
392
        q|
393
        SELECT metadata
394
        FROM holdings_metadata
395
        WHERE holding_id IN (SELECT holding_id FROM holdings WHERE biblionumber=?)
396
            AND format='marcxml'
397
            AND marcflavour=?
398
        |
399
    );
400
401
    $sth->execute( $biblionumber, $marcflavour );
402
403
    my @records;
404
    while (my ($marcxml) = $sth->fetchrow()) {
405
        $marcxml = StripNonXmlChars( $marcxml );
406
        my $record = eval {
407
            MARC::Record::new_from_xml( $marcxml, "utf8", $marcflavour );
408
        };
409
        if ($@) {
410
            warn " problem with holding for biblio $biblionumber : $@ \n$marcxml";
411
        }
412
        push @records, $record if $record;
413
    }
414
    $sth->finish();
415
    return \@records;
416
}
417
371
=head2 GetHoldingFrameworkCode
418
=head2 GetHoldingFrameworkCode
372
419
373
  $frameworkcode = GetFrameworkCode( $holding_id )
420
  $frameworkcode = GetFrameworkCode( $holding_id )
(-)a/Koha/Exporter/Record.pm (-16 / +62 lines)
Lines 27-53 sub _get_record_for_export { Link Here
27
    }
27
    }
28
    return unless $record;
28
    return unless $record;
29
29
30
    if ($dont_export_fields) {
30
    _strip_unwanted_fields($record, $dont_export_fields) if $dont_export_fields;
31
        for my $f ( split / /, $dont_export_fields ) {
31
    C4::Biblio::RemoveAllNsb($record) if $clean;
32
            if ( $f =~ m/^(\d{3})(.)?$/ ) {
32
    return $record;
33
                my ( $field, $subfield ) = ( $1, $2 );
33
}
34
34
35
                # skip if this record doesn't have this field
35
sub _strip_unwanted_fields {
36
                if ( defined $record->field($field) ) {
36
    my ($record, $dont_export_fields) = @_;
37
                    if ( defined $subfield ) {
37
38
                        my @tags = $record->field($field);
38
    for my $f ( split / /, $dont_export_fields ) {
39
                        foreach my $t (@tags) {
39
        if ( $f =~ m/^(\d{3})(.)?$/ ) {
40
                            $t->delete_subfields($subfield);
40
            my ( $field, $subfield ) = ( $1, $2 );
41
                        }
41
42
                    } else {
42
            # skip if this record doesn't have this field
43
                        $record->delete_fields( $record->field($field) );
43
            if ( defined $record->field($field) ) {
44
                if ( defined $subfield ) {
45
                    my @tags = $record->field($field);
46
                    foreach my $t (@tags) {
47
                        $t->delete_subfields($subfield);
44
                    }
48
                    }
49
                } else {
50
                    $record->delete_fields( $record->field($field) );
45
                }
51
                }
46
            }
52
            }
47
        }
53
        }
48
    }
54
    }
49
    C4::Biblio::RemoveAllNsb($record) if $clean;
50
    return $record;
51
}
55
}
52
56
53
sub _get_authority_for_export {
57
sub _get_authority_for_export {
Lines 86-91 sub _get_biblio_for_export { Link Here
86
    return $record;
90
    return $record;
87
}
91
}
88
92
93
sub _get_holdings_for_export {
94
    my ($params)           = @_;
95
    my $dont_export_fields = $params->{dont_export_fields};
96
    my $clean              = $params->{clean};
97
    my $biblionumber       = $params->{biblionumber};
98
99
    my $records = C4::Holdings::GetMarcHoldingsByBiblionumber($biblionumber);
100
    foreach my $record (@$records) {
101
        _strip_unwanted_fields($record, $dont_export_fields) if $dont_export_fields;
102
        C4::Biblio::RemoveAllNsb($record) if $clean;
103
        C4::Biblio::UpsertMarcControlField($record, '004', $biblionumber);
104
        my $leader = $record->leader();
105
        if ($leader !~ /^.{6}[uvxy]/) {
106
            $leader =~ s/^(.{6})./$1u/;
107
            $record->leader($leader);
108
        }
109
    }
110
    return $records;
111
}
112
89
sub export {
113
sub export {
90
    my ($params) = @_;
114
    my ($params) = @_;
91
115
Lines 97-102 sub export { Link Here
97
    my $dont_export_fields = $params->{dont_export_fields};
121
    my $dont_export_fields = $params->{dont_export_fields};
98
    my $csv_profile_id     = $params->{csv_profile_id};
122
    my $csv_profile_id     = $params->{csv_profile_id};
99
    my $output_filepath    = $params->{output_filepath};
123
    my $output_filepath    = $params->{output_filepath};
124
    my $export_holdings    = $params->{export_holdings} // 0;
100
125
101
    if( !$record_type ) {
126
    if( !$record_type ) {
102
        Koha::Logger->get->warn( "No record_type given." );
127
        Koha::Logger->get->warn( "No record_type given." );
Lines 125-130 sub export { Link Here
125
                next;
150
                next;
126
            }
151
            }
127
            print $record->as_usmarc();
152
            print $record->as_usmarc();
153
            if ($export_holdings && $record_type eq 'bibs') {
154
                my $holdings = _get_holdings_for_export( { %$params, biblionumber => $record_id } );
155
                foreach my $holding (@$holdings) {
156
                    my $errorcount_on_decode = eval { scalar( MARC::File::USMARC->decode( $holding->as_usmarc )->warnings() ) };
157
                    if ( $errorcount_on_decode or $@ ) {
158
                        my $msg = "Holdings record for biblio $record_id could not be exported. " .
159
                            ( $@ // '' );
160
                        chomp $msg;
161
                        Koha::Logger->get->info( $msg );
162
                        next;
163
                    }
164
                    print $holding->as_usmarc();
165
                }
166
            }
128
        }
167
        }
129
    } elsif ( $format eq 'xml' ) {
168
    } elsif ( $format eq 'xml' ) {
130
        my $marcflavour = C4::Context->preference("marcflavour");
169
        my $marcflavour = C4::Context->preference("marcflavour");
Lines 140-145 sub export { Link Here
140
            }
179
            }
141
            print MARC::File::XML::record($record);
180
            print MARC::File::XML::record($record);
142
            print "\n";
181
            print "\n";
182
            if ($export_holdings && $record_type eq 'bibs') {
183
                my $holdings = _get_holdings_for_export( { %$params, biblionumber => $record_id } );
184
                foreach my $holding (@$holdings) {
185
                    print MARC::File::XML::record($holding);
186
                    print "\n";
187
                }
188
            }
143
        }
189
        }
144
        print MARC::File::XML::footer();
190
        print MARC::File::XML::footer();
145
        print "\n";
191
        print "\n";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt (-1 / +8 lines)
Lines 118-124 Link Here
118
    </fieldset>
118
    </fieldset>
119
    <fieldset class="rows">
119
    <fieldset class="rows">
120
    <legend> Options</legend>
120
    <legend> Options</legend>
121
<ol>        <li>
121
<ol>
122
        [% IF ( show_summary_holdings ) %]
123
        <li>
124
        <label for="export_holdings">Export holdings records (MARC 21 biblios only):</label>
125
        <input id="export_holdings" type="checkbox" name="export_holdings" />
126
        </li>
127
        [% END %]
128
        <li>
122
        <label for="dont_export_item">Don't export items:</label>
129
        <label for="dont_export_item">Don't export items:</label>
123
        <input id="dont_export_item" type="checkbox" name="dont_export_item" />
130
        <input id="dont_export_item" type="checkbox" name="dont_export_item" />
124
        </li>
131
        </li>
(-)a/misc/export_records.pl (-3 / +15 lines)
Lines 32-38 use Koha::CsvProfiles; Link Here
32
use Koha::Exporter::Record;
32
use Koha::Exporter::Record;
33
use Koha::DateUtils qw( dt_from_string output_pref );
33
use Koha::DateUtils qw( dt_from_string output_pref );
34
34
35
my ( $output_format, $timestamp, $dont_export_items, $csv_profile_id, $deleted_barcodes, $clean, $filename, $record_type, $id_list_file, $starting_authid, $ending_authid, $authtype, $starting_biblionumber, $ending_biblionumber, $itemtype, $starting_callnumber, $ending_callnumber, $start_accession, $end_accession, $help );
35
my ( $output_format, $timestamp, $dont_export_items, $csv_profile_id, $deleted_barcodes, $clean, $filename, $record_type, $id_list_file, $starting_authid, $ending_authid, $authtype, $starting_biblionumber, $ending_biblionumber, $itemtype, $starting_callnumber, $ending_callnumber, $start_accession, $end_accession, $help, $export_holdings );
36
GetOptions(
36
GetOptions(
37
    'format=s'                => \$output_format,
37
    'format=s'                => \$output_format,
38
    'date=s'                  => \$timestamp,
38
    'date=s'                  => \$timestamp,
Lines 53-59 GetOptions( Link Here
53
    'ending_callnumber=s'     => \$ending_callnumber,
53
    'ending_callnumber=s'     => \$ending_callnumber,
54
    'start_accession=s'       => \$start_accession,
54
    'start_accession=s'       => \$start_accession,
55
    'end_accession=s'         => \$end_accession,
55
    'end_accession=s'         => \$end_accession,
56
    'h|help|?'                => \$help
56
    'h|help|?'                => \$help,
57
    'holdings'                => \$export_holdings
57
) || pod2usage(1);
58
) || pod2usage(1);
58
59
59
if ($help) {
60
if ($help) {
Lines 87-92 if ( $deleted_barcodes and $record_type ne 'bibs' ) { Link Here
87
    pod2usage(q|--deleted_barcodes can only be used with biblios|);
88
    pod2usage(q|--deleted_barcodes can only be used with biblios|);
88
}
89
}
89
90
91
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
92
if ( $export_holdings and ( $record_type ne 'bibs' or $marcFlavour ne 'MARC21' ) ) {
93
    pod2usage(q|--holdings can only be used with MARC 21 biblios|);
94
}
95
90
$start_accession = dt_from_string( $start_accession ) if $start_accession;
96
$start_accession = dt_from_string( $start_accession ) if $start_accession;
91
$end_accession   = dt_from_string( $end_accession )   if $end_accession;
97
$end_accession   = dt_from_string( $end_accession )   if $end_accession;
92
98
Lines 202-207 else { Link Here
202
            format             => $output_format,
208
            format             => $output_format,
203
            csv_profile_id     => $csv_profile_id,
209
            csv_profile_id     => $csv_profile_id,
204
            export_items       => (not $dont_export_items),
210
            export_items       => (not $dont_export_items),
211
            export_holdings    => $export_holdings,
205
            clean              => $clean || 0,
212
            clean              => $clean || 0,
206
        }
213
        }
207
    );
214
    );
Lines 215-221 export records - This script exports record (biblios or authorities) Link Here
215
222
216
=head1 SYNOPSIS
223
=head1 SYNOPSIS
217
224
218
export_records.pl [-h|--help] [--format=format] [--date=datetime] [--record-type=TYPE] [--dont_export_items] [--deleted_barcodes] [--clean] [--id_list_file=PATH] --filename=outputfile
225
export_records.pl [-h|--help] [--format=format] [--date=datetime] [--record-type=TYPE] [--holdings] [--dont_export_items] [--deleted_barcodes] [--clean] [--id_list_file=PATH] --filename=outputfile
219
226
220
=head1 OPTIONS
227
=head1 OPTIONS
221
228
Lines 240-245 Print a brief help message. Link Here
240
247
241
 --record-type=TYPE     TYPE is 'bibs' or 'auths'.
248
 --record-type=TYPE     TYPE is 'bibs' or 'auths'.
242
249
250
=item B<--holdings>
251
252
 --holdings             Export MARC 21 holding records interleaved with bibs. Used only if TYPE
253
                        is 'bibs' and FORMAT is 'xml' or 'marc'.
254
243
=item B<--dont_export_items>
255
=item B<--dont_export_items>
244
256
245
 --dont_export_items    If enabled, the item infos won't be exported.
257
 --dont_export_items    If enabled, the item infos won't be exported.
(-)a/misc/migration_tools/bulkmarcimport.pl (-6 / +45 lines)
Lines 24-29 use C4::Debug; Link Here
24
use C4::Charset;
24
use C4::Charset;
25
use C4::Items;
25
use C4::Items;
26
use C4::MarcModificationTemplates;
26
use C4::MarcModificationTemplates;
27
use C4::Holdings;
27
28
28
use YAML;
29
use YAML;
29
use Unicode::Normalize;
30
use Unicode::Normalize;
Lines 40-46 use open qw( :std :encoding(UTF-8) ); Link Here
40
binmode( STDOUT, ":encoding(UTF-8)" );
41
binmode( STDOUT, ":encoding(UTF-8)" );
41
my ( $input_marc_file, $number, $offset) = ('',0,0);
42
my ( $input_marc_file, $number, $offset) = ('',0,0);
42
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
43
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
43
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append );
44
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append, $import_holdings );
44
my $cleanisbn = 1;
45
my $cleanisbn = 1;
45
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
46
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
46
my $framework = '';
47
my $framework = '';
Lines 84-96 GetOptions( Link Here
84
    'framework=s' => \$framework,
85
    'framework=s' => \$framework,
85
    'custom:s'    => \$localcust,
86
    'custom:s'    => \$localcust,
86
    'marcmodtemplate:s' => \$marc_mod_template,
87
    'marcmodtemplate:s' => \$marc_mod_template,
88
    'holdings' => \$import_holdings,
87
);
89
);
88
$biblios ||= !$authorities;
90
$biblios ||= !$authorities;
89
$insert  ||= !$update;
91
$insert  ||= !$update;
90
my $writemode = ($append) ? "a" : "w";
92
my $writemode = ($append) ? "a" : "w";
93
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
91
94
92
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities;
95
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities;
93
96
97
pod2usage( -msg => "\nHoldings only supported for MARC 21 biblios.\n", -exitval ) if $import_holdings && (!$biblios || $marcFlavour ne 'MARC21');
98
94
if ($all) {
99
if ($all) {
95
    $insert = 1;
100
    $insert = 1;
96
    $update = 1;
101
    $update = 1;
Lines 176-181 if ($fk_off) { Link Here
176
if ($delete) {
181
if ($delete) {
177
	if ($biblios){
182
	if ($biblios){
178
    	print "deleting biblios\n";
183
    	print "deleting biblios\n";
184
	$dbh->do("truncate holdings");
179
    	$dbh->do("truncate biblio");
185
    	$dbh->do("truncate biblio");
180
    	$dbh->do("truncate biblioitems");
186
    	$dbh->do("truncate biblioitems");
181
    	$dbh->do("truncate items");
187
    	$dbh->do("truncate items");
Lines 193-200 if ($test_parameter) { Link Here
193
    print "TESTING MODE ONLY\n    DOING NOTHING\n===============\n";
199
    print "TESTING MODE ONLY\n    DOING NOTHING\n===============\n";
194
}
200
}
195
201
196
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
197
198
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose;
202
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose;
199
my $starttime = gettimeofday;
203
my $starttime = gettimeofday;
200
my $batch;
204
my $batch;
Lines 260-265 my $searcher = Koha::SearchEngine::Search->new( Link Here
260
    }
264
    }
261
);
265
);
262
266
267
my $biblionumber;
263
RECORD: while (  ) {
268
RECORD: while (  ) {
264
    my $record;
269
    my $record;
265
    # get records
270
    # get records
Lines 308-318 RECORD: while ( ) { Link Here
308
            $field->update('a' => $isbn);
313
            $field->update('a' => $isbn);
309
        }
314
        }
310
    }
315
    }
316
317
    # check for holdings records
318
    my $holdings_record = 0;
319
    if ($biblios && $marcFlavour eq 'MARC21') {
320
        my $leader = $record->leader();
321
        $holdings_record = $leader =~ /^.{6}[uvxy]/;
322
    }
323
311
    my $id;
324
    my $id;
312
    # search for duplicates (based on Local-number)
325
    # search for duplicates (based on Local-number)
313
    my $originalid;
326
    my $originalid;
314
    $originalid = GetRecordId( $record, $tagid, $subfieldid );
327
    $originalid = GetRecordId( $record, $tagid, $subfieldid );
315
    if ($match) {
328
    if ($match && !$holdings_record) {
316
        require C4::Search;
329
        require C4::Search;
317
        my $query = build_query( $match, $record );
330
        my $query = build_query( $match, $record );
318
        my $server = ( $authorities ? 'authorityserver' : 'biblioserver' );
331
        my $server = ( $authorities ? 'authorityserver' : 'biblioserver' );
Lines 428-435 RECORD: while ( ) { Link Here
428
            $yamlhash->{$originalid}->{'subfields'} = \@subfields;
441
            $yamlhash->{$originalid}->{'subfields'} = \@subfields;
429
            }
442
            }
430
        }
443
        }
444
        elsif ($holdings_record) {
445
            if ($import_holdings) {
446
                if (!defined $biblionumber) {
447
                    warn "ERROR: Encountered holdings record without preceding biblio record\n";
448
                } else {
449
                    if ($insert) {
450
                        my $holdings_id = 0;
451
                        eval { ( $holdings_id ) = AddHolding( $record, '', $biblionumber ) };
452
                        if ($@) {
453
                            warn "ERROR: Adding holdings record $holdings_id for biblio $biblionumber failed: $@\n";
454
                            printlog( { $holdings_id, op => "insert", status => "ERROR" } ) if ($logfile);
455
                            next RECORD;
456
                        } else {
457
                            printlog( { $holdings_id, op => "insert", status => "ok" } ) if ($logfile);
458
                        }
459
                    } else {
460
                        printlog( { 0, op => "update", status => "warning : not in database" } ) if ($logfile);
461
                    }
462
                }
463
            }
464
        }
431
        else {
465
        else {
432
            my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref );
466
            my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref );
433
            $biblionumber = $id;
467
            $biblionumber = $id;
434
            # check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter
468
            # check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter
435
            if (!$biblionumber && $isbn_check && $isbn) {
469
            if (!$biblionumber && $isbn_check && $isbn) {
Lines 701-706 Type of import: authority records Link Here
701
735
702
The I<FILE> to import
736
The I<FILE> to import
703
737
738
=item B<-holdings>
739
740
Import MARC 21 holdings records when interleaved with bibliographic records
741
(insert only, update not supported). Used only with -biblios.
742
704
=item  B<-v>
743
=item  B<-v>
705
744
706
Verbose mode. 1 means "some infos", 2 means "MARC dumping"
745
Verbose mode. 1 means "some infos", 2 means "MARC dumping"
Lines 746-752 I<UNIMARC> are supported. MARC21 by default. Link Here
746
=item B<-d>
785
=item B<-d>
747
786
748
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio,
787
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio,
749
biblioitems, items
788
biblioitems, items, holdings
750
789
751
=item B<-m>=I<FORMAT>
790
=item B<-m>=I<FORMAT>
752
791
(-)a/t/db_dependent/Exporter/Record.t (-1 / +62 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 7;
21
use Test::Warn;
21
use Test::Warn;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
Lines 35-40 use Koha::Biblio; Link Here
35
use Koha::Biblioitem;
35
use Koha::Biblioitem;
36
use Koha::Exporter::Record;
36
use Koha::Exporter::Record;
37
use Koha::Biblio::Metadata;
37
use Koha::Biblio::Metadata;
38
use Koha::Holdings;
38
39
39
my $schema  = Koha::Database->new->schema;
40
my $schema  = Koha::Database->new->schema;
40
$schema->storage->txn_begin;
41
$schema->storage->txn_begin;
Lines 62-67 my $bad_biblio = Koha::Biblio->new()->store(); Link Here
62
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', marcflavour => C4::Context->preference('marcflavour') } )->store();
63
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', marcflavour => C4::Context->preference('marcflavour') } )->store();
63
my $bad_biblionumber = $bad_biblio->id;
64
my $bad_biblionumber = $bad_biblio->id;
64
65
66
my $holding_1 = MARC::Record->new();
67
$holding_1->leader('00202cx  a22000973  4500');
68
$holding_1->append_fields(
69
    MARC::Field->new('852', '8', ' ', b => 'Location', k => '1973', h => 'Tb', t => 'Copy 1')
70
);
71
C4::Holdings::AddHolding($holding_1, '', $biblionumber_1);
72
65
my $builder = t::lib::TestBuilder->new;
73
my $builder = t::lib::TestBuilder->new;
66
my $item_1_1 = $builder->build({
74
my $item_1_1 = $builder->build({
67
    source => 'Item',
75
    source => 'Item',
Lines 199-204 subtest 'export iso2709' => sub { Link Here
199
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
207
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
200
};
208
};
201
209
210
subtest 'export xml with holdings' => sub {
211
    plan tests => 2;
212
    my $generated_xml_file = '/tmp/test_export.xml';
213
    Koha::Exporter::Record::export(
214
        {   record_type     => 'bibs',
215
            record_ids      => [ $biblionumber_1, $biblionumber_2 ],
216
            format          => 'xml',
217
            output_filepath => $generated_xml_file,
218
            export_holdings => 1,
219
        }
220
    );
221
222
    my $generated_xml_content = read_file( $generated_xml_file );
223
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
224
    open my $fh, '<', $generated_xml_file;
225
    my $records = MARC::Batch->new( 'XML', $fh );
226
    my @records;
227
    # The following statement produces
228
    # Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/MARC/File/XML.pm line 398, <$fh> chunk 5.
229
    # Why?
230
    while ( my $record = $records->next ) {
231
        push @records, $record;
232
    }
233
    is( scalar( @records ), 3, 'Export XML with holdings: 3 records should have been exported' );
234
    my $holding_record = $records[1];
235
    my $location = $holding_record->subfield('852', 'b');
236
    is( $location, 'Location', 'Export XML with holdings: The holding record is correctly exported' );
237
};
238
239
subtest 'export iso2709 with holdings' => sub {
240
    plan tests => 2;
241
    my $generated_mrc_file = '/tmp/test_export.mrc';
242
    # Get all item infos
243
    Koha::Exporter::Record::export(
244
        {   record_type     => 'bibs',
245
            record_ids      => [ $biblionumber_1, $biblionumber_2 ],
246
            format          => 'iso2709',
247
            output_filepath => $generated_mrc_file,
248
            export_holdings => 1,
249
        }
250
    );
251
252
    my $records = MARC::File::USMARC->in( $generated_mrc_file );
253
    my @records;
254
    while ( my $record = $records->next ) {
255
        push @records, $record;
256
    }
257
    is( scalar( @records ), 3, 'Export ISO2709 with holdings: 3 records should have been exported' );
258
    my $holding_record = $records[1];
259
    my $location = $holding_record->subfield('852', 'b');
260
    is( $location, 'Location', 'Export ISO2709 with holdings: The holding record is correctly exported' );
261
};
262
202
subtest 'export without record_type' => sub {
263
subtest 'export without record_type' => sub {
203
    plan tests => 1;
264
    plan tests => 1;
204
265
(-)a/tools/export.pl (-1 / +3 lines)
Lines 35-40 use Koha::Libraries; Link Here
35
my $query = new CGI;
35
my $query = new CGI;
36
36
37
my $dont_export_items = $query->param("dont_export_item") || 0;
37
my $dont_export_items = $query->param("dont_export_item") || 0;
38
my $export_holdings   = $query->param("export_holdings") || 0;
38
my $record_type       = $query->param("record_type");
39
my $record_type       = $query->param("record_type");
39
my $op                = $query->param("op") || '';
40
my $op                = $query->param("op") || '';
40
my $output_format     = $query->param("format") || $query->param("output_format") || 'iso2709';
41
my $output_format     = $query->param("format") || $query->param("output_format") || 'iso2709';
Lines 208-213 if ( $op eq "export" ) { Link Here
208
                dont_export_fields => $export_remove_fields,
209
                dont_export_fields => $export_remove_fields,
209
                csv_profile_id     => $csv_profile_id,
210
                csv_profile_id     => $csv_profile_id,
210
                export_items       => (not $dont_export_items),
211
                export_items       => (not $dont_export_items),
212
                export_holdings    => $export_holdings,
211
                only_export_items_for_branches => $only_export_items_for_branches,
213
                only_export_items_for_branches => $only_export_items_for_branches,
212
            }
214
            }
213
        );
215
        );
Lines 302-307 else { Link Here
302
        export_remove_fields     => C4::Context->preference("ExportRemoveFields"),
304
        export_remove_fields     => C4::Context->preference("ExportRemoveFields"),
303
        csv_profiles             => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
305
        csv_profiles             => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
304
        messages                 => \@messages,
306
        messages                 => \@messages,
307
        show_summary_holdings    => C4::Context->preference('SummaryHoldings') ? 1 : 0,
305
    );
308
    );
306
309
307
    output_html_with_http_headers $query, $cookie, $template->output;
310
    output_html_with_http_headers $query, $cookie, $template->output;
308
- 

Return to bug 20447