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

(-)a/Koha/Exporter/Record.pm (-16 / +65 lines)
Lines 85-111 sub _get_record_for_export { Link Here
85
        }
85
        }
86
    }
86
    }
87
87
88
    if ($dont_export_fields) {
88
    _strip_unwanted_fields($record, $dont_export_fields) if $dont_export_fields;
89
        for my $f ( split / /, $dont_export_fields ) {
89
    C4::Biblio::RemoveAllNsb($record) if $clean;
90
            if ( $f =~ m/^(\d{3})(.)?$/ ) {
90
    return $record;
91
                my ( $field, $subfield ) = ( $1, $2 );
91
}
92
92
93
                # skip if this record doesn't have this field
93
sub _strip_unwanted_fields {
94
                if ( defined $record->field($field) ) {
94
    my ($record, $dont_export_fields) = @_;
95
                    if ( defined $subfield ) {
95
96
                        my @tags = $record->field($field);
96
    for my $f ( split / /, $dont_export_fields ) {
97
                        foreach my $t (@tags) {
97
        if ( $f =~ m/^(\d{3})(.)?$/ ) {
98
                            $t->delete_subfields($subfield);
98
            my ( $field, $subfield ) = ( $1, $2 );
99
                        }
99
100
                    } else {
100
            # skip if this record doesn't have this field
101
                        $record->delete_fields( $record->field($field) );
101
            if ( defined $record->field($field) ) {
102
                if ( defined $subfield ) {
103
                    my @tags = $record->field($field);
104
                    foreach my $t (@tags) {
105
                        $t->delete_subfields($subfield);
102
                    }
106
                    }
107
                } else {
108
                    $record->delete_fields( $record->field($field) );
103
                }
109
                }
104
            }
110
            }
105
        }
111
        }
106
    }
112
    }
107
    C4::Biblio::RemoveAllNsb($record) if $clean;
108
    return $record;
109
}
113
}
110
114
111
sub _get_authority_for_export {
115
sub _get_authority_for_export {
Lines 152-157 sub _get_biblio_for_export { Link Here
152
    return $record;
156
    return $record;
153
}
157
}
154
158
159
sub _get_holdings_for_export {
160
    my ($params)           = @_;
161
    my $dont_export_fields = $params->{dont_export_fields};
162
    my $clean              = $params->{clean};
163
    my $biblionumber       = $params->{biblionumber};
164
165
    my @records;
166
    my $holdings = Koha::Holdings->search({ biblionumber => $biblionumber, deleted_on => undef });
167
    while (my $holding = $holdings->next()) {
168
        my $record = $holding->metadata()->record();
169
        _strip_unwanted_fields($record, $dont_export_fields) if $dont_export_fields;
170
        C4::Biblio::RemoveAllNsb($record) if $clean;
171
        C4::Biblio::UpsertMarcControlField($record, '004', $biblionumber);
172
        my $leader = $record->leader();
173
        if ($leader !~ /^.{6}[uvxy]/) {
174
            $leader =~ s/^(.{6})./$1u/;
175
            $record->leader($leader);
176
        }
177
        push @records, $record;
178
    }
179
    return \@records;
180
}
181
155
sub export {
182
sub export {
156
    my ($params) = @_;
183
    my ($params) = @_;
157
184
Lines 163-168 sub export { Link Here
163
    my $dont_export_fields = $params->{dont_export_fields};
190
    my $dont_export_fields = $params->{dont_export_fields};
164
    my $csv_profile_id     = $params->{csv_profile_id};
191
    my $csv_profile_id     = $params->{csv_profile_id};
165
    my $output_filepath    = $params->{output_filepath};
192
    my $output_filepath    = $params->{output_filepath};
193
    my $export_holdings    = $params->{export_holdings} // 0;
166
194
167
    if( !$record_type ) {
195
    if( !$record_type ) {
168
        Koha::Logger->get->warn( "No record_type given." );
196
        Koha::Logger->get->warn( "No record_type given." );
Lines 192-197 sub export { Link Here
192
                next;
220
                next;
193
            }
221
            }
194
            print $record->as_usmarc();
222
            print $record->as_usmarc();
223
            if ($export_holdings && $record_type eq 'bibs') {
224
                my $holdings = _get_holdings_for_export( { %$params, biblionumber => $record_id } );
225
                foreach my $holding (@$holdings) {
226
                    my $errorcount_on_decode = eval { scalar( MARC::File::USMARC->decode( $holding->as_usmarc )->warnings() ) };
227
                    if ( $errorcount_on_decode or $@ ) {
228
                        my $msg = "Holdings record for biblio $record_id could not be exported. " .
229
                            ( $@ // '' );
230
                        chomp $msg;
231
                        Koha::Logger->get->info( $msg );
232
                        next;
233
                    }
234
                    print $holding->as_usmarc();
235
                }
236
            }
195
        }
237
        }
196
    } elsif ( $format eq 'xml' ) {
238
    } elsif ( $format eq 'xml' ) {
197
        my $marcflavour = C4::Context->preference("marcflavour");
239
        my $marcflavour = C4::Context->preference("marcflavour");
Lines 204-209 sub export { Link Here
204
            next unless $record;
246
            next unless $record;
205
            print MARC::File::XML::record($record);
247
            print MARC::File::XML::record($record);
206
            print "\n";
248
            print "\n";
249
            if ($export_holdings && $record_type eq 'bibs') {
250
                my $holdings = _get_holdings_for_export( { %$params, biblionumber => $record_id } );
251
                foreach my $holding (@$holdings) {
252
                    print MARC::File::XML::record($holding);
253
                    print "\n";
254
                }
255
            }
207
        }
256
        }
208
        print MARC::File::XML::footer();
257
        print MARC::File::XML::footer();
209
        print "\n";
258
        print "\n";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt (+7 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE Branches %]
3
[% USE Branches %]
4
[% USE Koha %]
4
[% SET footerjs = 1 %]
5
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Export data &rsaquo; Cataloging &rsaquo; Koha</title>
7
<title>Export data &rsaquo; Cataloging &rsaquo; Koha</title>
Lines 137-142 Link Here
137
                <fieldset class="rows">
138
                <fieldset class="rows">
138
                    <legend> Options</legend>
139
                    <legend> Options</legend>
139
                    <ol>
140
                    <ol>
141
                        [% IF ( Koha.Preference('SummaryHoldings') ) %]
142
                        <li>
143
                            <label for="export_holdings">Export holdings records (MARC 21 biblios only):</label>
144
                            <input id="export_holdings" type="checkbox" name="export_holdings" />
145
                        </li>
146
                        [% END %]
140
                        <li>
147
                        <li>
141
                            <label for="dont_export_item">Don't export items:</label>
148
                            <label for="dont_export_item">Don't export items:</label>
142
                            <input id="dont_export_item" type="checkbox" name="dont_export_item" />
149
                            <input id="dont_export_item" type="checkbox" name="dont_export_item" />
(-)a/misc/export_records.pl (-1 / +14 lines)
Lines 54-59 my ( Link Here
54
    $start_accession,
54
    $start_accession,
55
    $end_accession,
55
    $end_accession,
56
    $marc_conditions,
56
    $marc_conditions,
57
    $export_holdings,
57
    $help
58
    $help
58
);
59
);
59
60
Lines 78-83 GetOptions( Link Here
78
    'start_accession=s'       => \$start_accession,
79
    'start_accession=s'       => \$start_accession,
79
    'end_accession=s'         => \$end_accession,
80
    'end_accession=s'         => \$end_accession,
80
    'marc_conditions=s'       => \$marc_conditions,
81
    'marc_conditions=s'       => \$marc_conditions,
82
    'holdings'                => \$export_holdings,
81
    'h|help|?'                => \$help
83
    'h|help|?'                => \$help
82
) || pod2usage(1);
84
) || pod2usage(1);
83
85
Lines 112-117 if ( $deleted_barcodes and $record_type ne 'bibs' ) { Link Here
112
    pod2usage(q|--deleted_barcodes can only be used with biblios|);
114
    pod2usage(q|--deleted_barcodes can only be used with biblios|);
113
}
115
}
114
116
117
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
118
if ( $export_holdings and ( $record_type ne 'bibs' or $marcFlavour ne 'MARC21' ) ) {
119
    pod2usage(q|--holdings can only be used with MARC 21 biblios|);
120
}
121
115
$start_accession = dt_from_string( $start_accession ) if $start_accession;
122
$start_accession = dt_from_string( $start_accession ) if $start_accession;
116
$end_accession   = dt_from_string( $end_accession )   if $end_accession;
123
$end_accession   = dt_from_string( $end_accession )   if $end_accession;
117
124
Lines 255-260 else { Link Here
255
            format             => $output_format,
262
            format             => $output_format,
256
            csv_profile_id     => $csv_profile_id,
263
            csv_profile_id     => $csv_profile_id,
257
            export_items       => (not $dont_export_items),
264
            export_items       => (not $dont_export_items),
265
            export_holdings    => $export_holdings,
258
            clean              => $clean || 0,
266
            clean              => $clean || 0,
259
        }
267
        }
260
    );
268
    );
Lines 268-274 export records - This script exports record (biblios or authorities) Link Here
268
276
269
=head1 SYNOPSIS
277
=head1 SYNOPSIS
270
278
271
export_records.pl [-h|--help] [--format=format] [--date=datetime] [--record-type=TYPE] [--dont_export_items] [--deleted_barcodes] [--clean] [--id_list_file=PATH] --filename=outputfile
279
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
272
280
273
=head1 OPTIONS
281
=head1 OPTIONS
274
282
Lines 293-298 Print a brief help message. Link Here
293
301
294
 --record-type=TYPE     TYPE is 'bibs' or 'auths'.
302
 --record-type=TYPE     TYPE is 'bibs' or 'auths'.
295
303
304
=item B<--holdings>
305
306
 --holdings             Export MARC 21 holdings records interleaved with bibs. Used only if TYPE
307
                        is 'bibs' and FORMAT is 'xml' or 'marc'.
308
296
=item B<--dont_export_items>
309
=item B<--dont_export_items>
297
310
298
 --dont_export_items    If enabled, the item infos won't be exported.
311
 --dont_export_items    If enabled, the item infos won't be exported.
(-)a/misc/migration_tools/bulkmarcimport.pl (-9 / +54 lines)
Lines 43-49 use open qw( :std :encoding(UTF-8) ); Link Here
43
binmode( STDOUT, ":encoding(UTF-8)" );
43
binmode( STDOUT, ":encoding(UTF-8)" );
44
my ( $input_marc_file, $number, $offset) = ('',0,0);
44
my ( $input_marc_file, $number, $offset) = ('',0,0);
45
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
45
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
46
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append );
46
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append, $import_holdings );
47
my $cleanisbn = 1;
47
my $cleanisbn = 1;
48
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
48
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
49
my $framework = '';
49
my $framework = '';
Lines 87-99 GetOptions( Link Here
87
    'framework=s' => \$framework,
87
    'framework=s' => \$framework,
88
    'custom:s'    => \$localcust,
88
    'custom:s'    => \$localcust,
89
    'marcmodtemplate:s' => \$marc_mod_template,
89
    'marcmodtemplate:s' => \$marc_mod_template,
90
    'holdings' => \$import_holdings,
90
);
91
);
91
$biblios ||= !$authorities;
92
$biblios ||= !$authorities;
92
$insert  ||= !$update;
93
$insert  ||= !$update;
93
my $writemode = ($append) ? "a" : "w";
94
my $writemode = ($append) ? "a" : "w";
95
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
94
96
95
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities;
97
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities;
96
98
99
pod2usage( -msg => "\nHoldings only supported for MARC 21 biblios.\n", -exitval ) if $import_holdings && (!$biblios || $marcFlavour ne 'MARC21');
100
97
if ($all) {
101
if ($all) {
98
    $insert = 1;
102
    $insert = 1;
99
    $update = 1;
103
    $update = 1;
Lines 171-182 if ($fk_off) { Link Here
171
175
172
176
173
if ($delete) {
177
if ($delete) {
174
	if ($biblios){
178
    if ($biblios) {
175
    	print "deleting biblios\n";
179
        print "deleting biblios\n";
176
        $dbh->do("DELETE FROM biblio");
180
        $dbh->do("DELETE FROM biblio");
177
        $dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1");
181
        $dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1");
178
        $dbh->do("DELETE FROM biblioitems");
182
        $dbh->do("DELETE FROM biblioitems");
179
        $dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1");
183
        $dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1");
184
        $dbh->do("DELETE FROM holdings");
185
        $dbh->do("ALTER TABLE holdings AUTO_INCREMENT = 1");
180
        $dbh->do("DELETE FROM items");
186
        $dbh->do("DELETE FROM items");
181
        $dbh->do("ALTER TABLE items AUTO_INCREMENT = 1");
187
        $dbh->do("ALTER TABLE items AUTO_INCREMENT = 1");
182
	}
188
	}
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
# The definition of $searcher must be before MARC::Batch->new
202
# The definition of $searcher must be before MARC::Batch->new
199
my $searcher = Koha::SearchEngine::Search->new(
203
my $searcher = Koha::SearchEngine::Search->new(
200
    {
204
    {
Lines 232-237 if (defined $format && $format =~ /XML/i) { Link Here
232
$batch->warnings_off();
236
$batch->warnings_off();
233
$batch->strict_off();
237
$batch->strict_off();
234
my $i=0;
238
my $i=0;
239
my $holdings_count = 0;
235
my $commitnum = $commit ? $commit : 50;
240
my $commitnum = $commit ? $commit : 50;
236
my $yamlhash;
241
my $yamlhash;
237
242
Lines 261-266 if ($logfile){ Link Here
261
}
266
}
262
267
263
my $logger = Koha::Logger->get;
268
my $logger = Koha::Logger->get;
269
my $biblionumber;
264
my $schema = Koha::Database->schema;
270
my $schema = Koha::Database->schema;
265
$schema->txn_begin;
271
$schema->txn_begin;
266
RECORD: while (  ) {
272
RECORD: while (  ) {
Lines 311-321 RECORD: while ( ) { Link Here
311
            $field->update('a' => $isbn);
317
            $field->update('a' => $isbn);
312
        }
318
        }
313
    }
319
    }
320
321
    # check for holdings records
322
    my $holdings_record = 0;
323
    if ($biblios && $marcFlavour eq 'MARC21') {
324
        my $leader = $record->leader();
325
        $holdings_record = $leader =~ /^.{6}[uvxy]/;
326
    }
327
314
    my $id;
328
    my $id;
315
    # search for duplicates (based on Local-number)
329
    # search for duplicates (based on Local-number)
316
    my $originalid;
330
    my $originalid;
317
    $originalid = GetRecordId( $record, $tagid, $subfieldid );
331
    $originalid = GetRecordId( $record, $tagid, $subfieldid );
318
    if ($match) {
332
    if ($match && !$holdings_record) {
319
        require C4::Search;
333
        require C4::Search;
320
        my $query = build_query( $match, $record );
334
        my $query = build_query( $match, $record );
321
        my $server = ( $authorities ? 'authorityserver' : 'biblioserver' );
335
        my $server = ( $authorities ? 'authorityserver' : 'biblioserver' );
Lines 419-426 RECORD: while ( ) { Link Here
419
            $yamlhash->{$originalid}->{'updated'} = 1;
433
            $yamlhash->{$originalid}->{'updated'} = 1;
420
            }
434
            }
421
        }
435
        }
436
        elsif ($holdings_record) {
437
            if ($import_holdings) {
438
                if (!defined $biblionumber) {
439
                    warn "ERROR: Encountered holdings record without preceding biblio record\n";
440
                } else {
441
                    if ($insert) {
442
                        my $holding = Koha::Holding->new({ biblionumber => $biblionumber });
443
                        $holding->set_marc({ record => $record });
444
                        my $branchcode = $holding->holdingbranch();
445
                        if (defined $branchcode && !Koha::Libraries->find({ branchcode => $branchcode})) {
446
                            printlog( { id => 0, op => 'insert', status => "warning : library $branchcode not defined, holdings record skipped" } ) if ($logfile);
447
                        } else {
448
                            $holding->store();
449
                            ++$holdings_count;
450
                            printlog( { id => $holding->holding_id(), op => 'insert', status => 'ok' } ) if ($logfile);
451
                        }
452
                    } else {
453
                        printlog( { id => 0, op => 'update', status => 'warning : not in database' } ) if ($logfile);
454
                    }
455
                }
456
            }
457
        }
422
        else {
458
        else {
423
            my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref );
459
            my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref );
424
            $biblionumber = $id;
460
            $biblionumber = $id;
425
            # check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter
461
            # check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter
426
            if (!$biblionumber && $isbn_check && $isbn) {
462
            if (!$biblionumber && $isbn_check && $isbn) {
Lines 557-563 delete $ENV{OVERRIDE_SYSPREF_CataloguingLog}; Link Here
557
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog};
593
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog};
558
594
559
my $timeneeded = gettimeofday - $starttime;
595
my $timeneeded = gettimeofday - $starttime;
560
print "\n$i MARC records done in $timeneeded seconds\n";
596
if ($import_holdings) {
597
    printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded);
598
} else {
599
    printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded);
600
}
561
if ($logfile){
601
if ($logfile){
562
  print $loghandle "file : $input_marc_file\n";
602
  print $loghandle "file : $input_marc_file\n";
563
  print $loghandle "$i MARC records done in $timeneeded seconds\n";
603
  print $loghandle "$i MARC records done in $timeneeded seconds\n";
Lines 678-683 Type of import: authority records Link Here
678
718
679
The I<FILE> to import
719
The I<FILE> to import
680
720
721
=item B<-holdings>
722
723
Import MARC 21 holdings records when interleaved with bibliographic records
724
(insert only, update not supported). Used only with -biblios.
725
681
=item  B<-v>
726
=item  B<-v>
682
727
683
Verbose mode. 1 means "some infos", 2 means "MARC dumping"
728
Verbose mode. 1 means "some infos", 2 means "MARC dumping"
Lines 723-729 I<UNIMARC> are supported. MARC21 by default. Link Here
723
=item B<-d>
768
=item B<-d>
724
769
725
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio,
770
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio,
726
biblioitems, items
771
biblioitems, items, holdings
727
772
728
=item B<-m>=I<FORMAT>
773
=item B<-m>=I<FORMAT>
729
774
(-)a/t/db_dependent/Exporter/Record.t (-1 / +115 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 => 8;
21
use Test::Warn;
21
use Test::Warn;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
Lines 34-40 use Koha::Database; Link Here
34
use Koha::Biblio;
34
use Koha::Biblio;
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::Metadatas;
38
use Koha::Biblio::Metadatas;
39
use Koha::BiblioFramework;
40
use Koha::BiblioFrameworks;
38
41
39
use t::lib::TestBuilder;
42
use t::lib::TestBuilder;
40
43
Lines 80-85 my $bad_biblio = Koha::Biblio->new()->store(); Link Here
80
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', schema => $marcflavour } )->store();
83
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', schema => $marcflavour } )->store();
81
my $bad_biblionumber = $bad_biblio->id;
84
my $bad_biblionumber = $bad_biblio->id;
82
85
86
# Add a framework for holdings
87
my $frameworkcode = 'HLD';
88
my $existing_mss = Koha::MarcSubfieldStructures->search({frameworkcode => $frameworkcode});
89
$existing_mss->delete() if $existing_mss;
90
my $existing_fw = Koha::BiblioFrameworks->find({frameworkcode => $frameworkcode});
91
$existing_fw->delete() if $existing_fw;
92
Koha::BiblioFramework->new({
93
    frameworkcode => $frameworkcode,
94
    frameworktext => 'Holdings'
95
})->store();
96
Koha::MarcSubfieldStructure->new({
97
    frameworkcode => $frameworkcode,
98
    tagfield => 852,
99
    tagsubfield => 'b',
100
    kohafield => 'holdings.holdingbranch'
101
})->store();
102
Koha::MarcSubfieldStructure->new({
103
    frameworkcode => $frameworkcode,
104
    tagfield => 852,
105
    tagsubfield => 'c',
106
    kohafield => 'holdings.location'
107
})->store();
108
Koha::MarcSubfieldStructure->new({
109
    frameworkcode => $frameworkcode,
110
    tagfield => 942,
111
    tagsubfield => 'n',
112
    kohafield => 'holdings.suppress'
113
})->store();
114
Koha::MarcSubfieldStructure->new({
115
    frameworkcode => $frameworkcode,
116
    tagfield => 999,
117
    tagsubfield => 'c',
118
    kohafield => 'biblio.biblionumber'
119
})->store();
120
Koha::MarcSubfieldStructure->new({
121
    frameworkcode => $frameworkcode,
122
    tagfield => 999,
123
    tagsubfield => 'e',
124
    kohafield => 'holdings.holding_id'
125
})->store();
126
127
my $builder = t::lib::TestBuilder->new;
128
my $holdingbranch = $builder->build({ source => 'Branch' });
129
130
my $holding_marc_1 = MARC::Record->new();
131
$holding_marc_1->leader('00202cx  a22000973  4500');
132
$holding_marc_1->append_fields(
133
    MARC::Field->new('852', '8', ' ', b => $holdingbranch->{branchcode}, c => 'Location', k => '1973', h => 'Tb', t => 'Copy 1')
134
);
135
my $holding = Koha::Holding->new();
136
$holding->biblionumber($biblionumber_1);
137
$holding->set_marc({ record => $holding_marc_1 });
138
$holding->store();
139
83
my $item_1_1 = $builder->build_sample_item(
140
my $item_1_1 = $builder->build_sample_item(
84
    {
141
    {
85
        biblionumber => $biblionumber_1,
142
        biblionumber => $biblionumber_1,
Lines 209-214 subtest 'export iso2709' => sub { Link Here
209
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
266
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
210
};
267
};
211
268
269
subtest 'export xml with holdings' => sub {
270
    plan tests => 3;
271
    my $generated_xml_file = '/tmp/test_export.xml';
272
    Koha::Exporter::Record::export(
273
        {   record_type     => 'bibs',
274
            record_ids      => [ $biblionumber_1, $biblionumber_2 ],
275
            format          => 'xml',
276
            output_filepath => $generated_xml_file,
277
            export_holdings => 1,
278
        }
279
    );
280
281
    my $generated_xml_content = read_file( $generated_xml_file );
282
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
283
    open my $fh, '<', $generated_xml_file;
284
    my $records = MARC::Batch->new( 'XML', $fh );
285
    my @records;
286
    # The following statement produces
287
    # Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/MARC/File/XML.pm line 398, <$fh> chunk 5.
288
    # Why?
289
    while ( my $record = $records->next ) {
290
        push @records, $record;
291
    }
292
    is( scalar( @records ), 3, 'Export XML with holdings: 3 records should have been exported' );
293
    my $holding_record = $records[1];
294
    my $branch = $holding_record->subfield('852', 'b');
295
    is( $branch, $holdingbranch->{branchcode}, 'Export XML with holdings: The holdings record contains correct branch code' );
296
    my $location = $holding_record->subfield('852', 'c');
297
    is( $location, 'Location', 'Export XML with holdings: The holdings record contains correct location' );
298
};
299
300
subtest 'export iso2709 with holdings' => sub {
301
    plan tests => 3;
302
    my $generated_mrc_file = '/tmp/test_export.mrc';
303
    # Get all item infos
304
    Koha::Exporter::Record::export(
305
        {   record_type     => 'bibs',
306
            record_ids      => [ $biblionumber_1, $biblionumber_2 ],
307
            format          => 'iso2709',
308
            output_filepath => $generated_mrc_file,
309
            export_holdings => 1,
310
        }
311
    );
312
313
    my $records = MARC::File::USMARC->in( $generated_mrc_file );
314
    my @records;
315
    while ( my $record = $records->next ) {
316
        push @records, $record;
317
    }
318
    is( scalar( @records ), 3, 'Export ISO2709 with holdings: 3 records should have been exported' );
319
    my $holding_record = $records[1];
320
    my $branch = $holding_record->subfield('852', 'b');
321
    is( $branch, $holdingbranch->{branchcode}, 'Export ISO2709 with holdings: The holdings record contains correct branch code' );
322
    my $location = $holding_record->subfield('852', 'c');
323
    is( $location, 'Location', 'Export ISO2709 with holdings: The holdings record contains correct location' );
324
};
325
212
subtest 'export without record_type' => sub {
326
subtest 'export without record_type' => sub {
213
    plan tests => 1;
327
    plan tests => 1;
214
328
(-)a/tools/export.pl (-1 / +2 lines)
Lines 35-40 use Koha::Libraries; Link Here
35
my $query = CGI->new;
35
my $query = CGI->new;
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 228-233 if ( $op eq "export" ) { Link Here
228
                dont_export_fields => $export_remove_fields,
229
                dont_export_fields => $export_remove_fields,
229
                csv_profile_id     => $csv_profile_id,
230
                csv_profile_id     => $csv_profile_id,
230
                export_items       => (not $dont_export_items),
231
                export_items       => (not $dont_export_items),
232
                export_holdings    => $export_holdings,
231
                only_export_items_for_branches => $only_export_items_for_branches,
233
                only_export_items_for_branches => $only_export_items_for_branches,
232
            }
234
            }
233
        );
235
        );
234
- 

Return to bug 20447