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

(-)a/Koha/Exporter/Record.pm (-17 / +67 lines)
Lines 82-108 sub _get_record_for_export { Link Here
82
        }
82
        }
83
    }
83
    }
84
84
85
    if ($dont_export_fields) {
85
    _strip_unwanted_fields($record, $dont_export_fields) if $dont_export_fields;
86
        for my $f ( split / /, $dont_export_fields ) {
86
    C4::Biblio::RemoveAllNsb($record) if $clean;
87
            if ( $f =~ m/^(\d{3})(.)?$/ ) {
87
    return $record;
88
                my ( $field, $subfield ) = ( $1, $2 );
88
}
89
89
90
                # skip if this record doesn't have this field
90
sub _strip_unwanted_fields {
91
                if ( defined $record->field($field) ) {
91
    my ($record, $dont_export_fields) = @_;
92
                    if ( defined $subfield ) {
92
93
                        my @tags = $record->field($field);
93
    for my $f ( split / /, $dont_export_fields ) {
94
                        foreach my $t (@tags) {
94
        if ( $f =~ m/^(\d{3})(.)?$/ ) {
95
                            $t->delete_subfields($subfield);
95
            my ( $field, $subfield ) = ( $1, $2 );
96
                        }
96
97
                    } else {
97
            # skip if this record doesn't have this field
98
                        $record->delete_fields( $record->field($field) );
98
            if ( defined $record->field($field) ) {
99
                if ( defined $subfield ) {
100
                    my @tags = $record->field($field);
101
                    foreach my $t (@tags) {
102
                        $t->delete_subfields($subfield);
99
                    }
103
                    }
104
                } else {
105
                    $record->delete_fields( $record->field($field) );
100
                }
106
                }
101
            }
107
            }
102
        }
108
        }
103
    }
109
    }
104
    C4::Biblio::RemoveAllNsb($record) if $clean;
105
    return $record;
106
}
110
}
107
111
108
sub _get_authority_for_export {
112
sub _get_authority_for_export {
Lines 128-134 sub _get_biblio_for_export { Link Here
128
        C4::Biblio::EmbedItemsInMarcBiblio({
132
        C4::Biblio::EmbedItemsInMarcBiblio({
129
            marc_record  => $record,
133
            marc_record  => $record,
130
            biblionumber => $biblionumber,
134
            biblionumber => $biblionumber,
131
            item_numbers => $itemnumbers });
135
            item_numbers => $itemnumbers,
136
            skip_holdings => 1 });
132
        if ($only_export_items_for_branches && @$only_export_items_for_branches) {
137
        if ($only_export_items_for_branches && @$only_export_items_for_branches) {
133
            my %export_items_for_branches = map { $_ => 1 } @$only_export_items_for_branches;
138
            my %export_items_for_branches = map { $_ => 1 } @$only_export_items_for_branches;
134
            my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField( 'items.homebranch' );
139
            my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField( 'items.homebranch' );
Lines 144-149 sub _get_biblio_for_export { Link Here
144
    return $record;
149
    return $record;
145
}
150
}
146
151
152
sub _get_holdings_for_export {
153
    my ($params)           = @_;
154
    my $dont_export_fields = $params->{dont_export_fields};
155
    my $clean              = $params->{clean};
156
    my $biblionumber       = $params->{biblionumber};
157
158
    my @records;
159
    my $holdings = Koha::Holdings->search({ biblionumber => $biblionumber, deleted_on => undef });
160
    while (my $holding = $holdings->next()) {
161
        my $record = $holding->metadata()->record();
162
        _strip_unwanted_fields($record, $dont_export_fields) if $dont_export_fields;
163
        C4::Biblio::RemoveAllNsb($record) if $clean;
164
        C4::Biblio::UpsertMarcControlField($record, '004', $biblionumber);
165
        my $leader = $record->leader();
166
        if ($leader !~ /^.{6}[uvxy]/) {
167
            $leader =~ s/^(.{6})./$1u/;
168
            $record->leader($leader);
169
        }
170
        push @records, $record;
171
    }
172
    return \@records;
173
}
174
147
sub export {
175
sub export {
148
    my ($params) = @_;
176
    my ($params) = @_;
149
177
Lines 155-160 sub export { Link Here
155
    my $dont_export_fields = $params->{dont_export_fields};
183
    my $dont_export_fields = $params->{dont_export_fields};
156
    my $csv_profile_id     = $params->{csv_profile_id};
184
    my $csv_profile_id     = $params->{csv_profile_id};
157
    my $output_filepath    = $params->{output_filepath};
185
    my $output_filepath    = $params->{output_filepath};
186
    my $export_holdings    = $params->{export_holdings} // 0;
158
187
159
    if( !$record_type ) {
188
    if( !$record_type ) {
160
        Koha::Logger->get->warn( "No record_type given." );
189
        Koha::Logger->get->warn( "No record_type given." );
Lines 184-189 sub export { Link Here
184
                next;
213
                next;
185
            }
214
            }
186
            print $record->as_usmarc();
215
            print $record->as_usmarc();
216
            if ($export_holdings && $record_type eq 'bibs') {
217
                my $holdings = _get_holdings_for_export( { %$params, biblionumber => $record_id } );
218
                foreach my $holding (@$holdings) {
219
                    my $errorcount_on_decode = eval { scalar( MARC::File::USMARC->decode( $holding->as_usmarc )->warnings() ) };
220
                    if ( $errorcount_on_decode or $@ ) {
221
                        my $msg = "Holdings record for biblio $record_id could not be exported. " .
222
                            ( $@ // '' );
223
                        chomp $msg;
224
                        Koha::Logger->get->info( $msg );
225
                        next;
226
                    }
227
                    print $holding->as_usmarc();
228
                }
229
            }
187
        }
230
        }
188
    } elsif ( $format eq 'xml' ) {
231
    } elsif ( $format eq 'xml' ) {
189
        my $marcflavour = C4::Context->preference("marcflavour");
232
        my $marcflavour = C4::Context->preference("marcflavour");
Lines 196-201 sub export { Link Here
196
            next unless $record;
239
            next unless $record;
197
            print MARC::File::XML::record($record);
240
            print MARC::File::XML::record($record);
198
            print "\n";
241
            print "\n";
242
            if ($export_holdings && $record_type eq 'bibs') {
243
                my $holdings = _get_holdings_for_export( { %$params, biblionumber => $record_id } );
244
                foreach my $holding (@$holdings) {
245
                    print MARC::File::XML::record($holding);
246
                    print "\n";
247
                }
248
            }
199
        }
249
        }
200
        print MARC::File::XML::footer();
250
        print MARC::File::XML::footer();
201
        print "\n";
251
        print "\n";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt (-1 / +8 lines)
Lines 117-123 Link Here
117
    </fieldset>
117
    </fieldset>
118
    <fieldset class="rows">
118
    <fieldset class="rows">
119
    <legend> Options</legend>
119
    <legend> Options</legend>
120
<ol>        <li>
120
<ol>
121
        [% IF ( Koha.Preference('SummaryHoldings') ) %]
122
        <li>
123
        <label for="export_holdings">Export holdings records (MARC 21 biblios only):</label>
124
        <input id="export_holdings" type="checkbox" name="export_holdings" />
125
        </li>
126
        [% END %]
127
        <li>
121
        <label for="dont_export_item">Don't export items:</label>
128
        <label for="dont_export_item">Don't export items:</label>
122
        <input id="dont_export_item" type="checkbox" name="dont_export_item" />
129
        <input id="dont_export_item" type="checkbox" name="dont_export_item" />
123
        </li>
130
        </li>
(-)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 / +55 lines)
Lines 34-39 use IO::File; Link Here
34
use Pod::Usage;
34
use Pod::Usage;
35
35
36
use Koha::Biblios;
36
use Koha::Biblios;
37
use Koha::Holdings;
37
use Koha::SearchEngine;
38
use Koha::SearchEngine;
38
use Koha::SearchEngine::Search;
39
use Koha::SearchEngine::Search;
39
40
Lines 41-47 use open qw( :std :encoding(UTF-8) ); Link Here
41
binmode( STDOUT, ":encoding(UTF-8)" );
42
binmode( STDOUT, ":encoding(UTF-8)" );
42
my ( $input_marc_file, $number, $offset) = ('',0,0);
43
my ( $input_marc_file, $number, $offset) = ('',0,0);
43
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
44
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile);
44
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append );
45
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append, $import_holdings );
45
my $cleanisbn = 1;
46
my $cleanisbn = 1;
46
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
47
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode);
47
my $framework = '';
48
my $framework = '';
Lines 85-97 GetOptions( Link Here
85
    'framework=s' => \$framework,
86
    'framework=s' => \$framework,
86
    'custom:s'    => \$localcust,
87
    'custom:s'    => \$localcust,
87
    'marcmodtemplate:s' => \$marc_mod_template,
88
    'marcmodtemplate:s' => \$marc_mod_template,
89
    'holdings' => \$import_holdings,
88
);
90
);
89
$biblios ||= !$authorities;
91
$biblios ||= !$authorities;
90
$insert  ||= !$update;
92
$insert  ||= !$update;
91
my $writemode = ($append) ? "a" : "w";
93
my $writemode = ($append) ? "a" : "w";
94
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
92
95
93
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities;
96
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities;
94
97
98
pod2usage( -msg => "\nHoldings only supported for MARC 21 biblios.\n", -exitval ) if $import_holdings && (!$biblios || $marcFlavour ne 'MARC21');
99
95
if ($all) {
100
if ($all) {
96
    $insert = 1;
101
    $insert = 1;
97
    $update = 1;
102
    $update = 1;
Lines 169-180 if ($fk_off) { Link Here
169
174
170
175
171
if ($delete) {
176
if ($delete) {
172
	if ($biblios){
177
    if ($biblios) {
173
    	print "deleting biblios\n";
178
        print "deleting biblios\n";
174
        $dbh->do("DELETE FROM biblio");
179
        $dbh->do("DELETE FROM biblio");
175
        $dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1");
180
        $dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1");
176
        $dbh->do("DELETE FROM biblioitems");
181
        $dbh->do("DELETE FROM biblioitems");
177
        $dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1");
182
        $dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1");
183
        $dbh->do("DELETE FROM holdings");
184
        $dbh->do("ALTER TABLE holdings AUTO_INCREMENT = 1");
178
        $dbh->do("DELETE FROM items");
185
        $dbh->do("DELETE FROM items");
179
        $dbh->do("ALTER TABLE items AUTO_INCREMENT = 1");
186
        $dbh->do("ALTER TABLE items AUTO_INCREMENT = 1");
180
	}
187
	}
Lines 191-198 if ($test_parameter) { Link Here
191
    print "TESTING MODE ONLY\n    DOING NOTHING\n===============\n";
198
    print "TESTING MODE ONLY\n    DOING NOTHING\n===============\n";
192
}
199
}
193
200
194
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
195
196
# The definition of $searcher must be before MARC::Batch->new
201
# The definition of $searcher must be before MARC::Batch->new
197
my $searcher = Koha::SearchEngine::Search->new(
202
my $searcher = Koha::SearchEngine::Search->new(
198
    {
203
    {
Lines 230-235 if (defined $format && $format =~ /XML/i) { Link Here
230
$batch->warnings_off();
235
$batch->warnings_off();
231
$batch->strict_off();
236
$batch->strict_off();
232
my $i=0;
237
my $i=0;
238
my $holdings_count = 0;
233
my $commitnum = $commit ? $commit : 50;
239
my $commitnum = $commit ? $commit : 50;
234
my $yamlhash;
240
my $yamlhash;
235
241
Lines 259-264 if ($logfile){ Link Here
259
   print $loghandle "id;operation;status\n";
265
   print $loghandle "id;operation;status\n";
260
}
266
}
261
267
268
my $biblionumber;
262
RECORD: while (  ) {
269
RECORD: while (  ) {
263
    my $record;
270
    my $record;
264
    # get records
271
    # get records
Lines 307-317 RECORD: while ( ) { Link Here
307
            $field->update('a' => $isbn);
314
            $field->update('a' => $isbn);
308
        }
315
        }
309
    }
316
    }
317
318
    # check for holdings records
319
    my $holdings_record = 0;
320
    if ($biblios && $marcFlavour eq 'MARC21') {
321
        my $leader = $record->leader();
322
        $holdings_record = $leader =~ /^.{6}[uvxy]/;
323
    }
324
310
    my $id;
325
    my $id;
311
    # search for duplicates (based on Local-number)
326
    # search for duplicates (based on Local-number)
312
    my $originalid;
327
    my $originalid;
313
    $originalid = GetRecordId( $record, $tagid, $subfieldid );
328
    $originalid = GetRecordId( $record, $tagid, $subfieldid );
314
    if ($match) {
329
    if ($match && !$holdings_record) {
315
        require C4::Search;
330
        require C4::Search;
316
        my $query = build_query( $match, $record );
331
        my $query = build_query( $match, $record );
317
        my $server = ( $authorities ? 'authorityserver' : 'biblioserver' );
332
        my $server = ( $authorities ? 'authorityserver' : 'biblioserver' );
Lines 429-436 RECORD: while ( ) { Link Here
429
            $yamlhash->{$originalid}->{'updated'} = 1;
444
            $yamlhash->{$originalid}->{'updated'} = 1;
430
            }
445
            }
431
        }
446
        }
447
        elsif ($holdings_record) {
448
            if ($import_holdings) {
449
                if (!defined $biblionumber) {
450
                    warn "ERROR: Encountered holdings record without preceding biblio record\n";
451
                } else {
452
                    if ($insert) {
453
                        my $holding = Koha::Holding->new({ biblionumber => $biblionumber });
454
                        $holding->set_marc({ record => $record });
455
                        my $branchcode = $holding->holdingbranch();
456
                        if (defined $branchcode && !Koha::Libraries->find({ branchcode => $branchcode})) {
457
                            printlog( { id => 0, op => 'insert', status => "warning : library $branchcode not defined, holdings record skipped" } ) if ($logfile);
458
                        } else {
459
                            $holding->store();
460
                            ++$holdings_count;
461
                            printlog( { id => $holding->holding_id(), op => 'insert', status => 'ok' } ) if ($logfile);
462
                        }
463
                    } else {
464
                        printlog( { id => 0, op => 'update', status => 'warning : not in database' } ) if ($logfile);
465
                    }
466
                }
467
            }
468
        }
432
        else {
469
        else {
433
            my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref );
470
            my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref );
434
            $biblionumber = $id;
471
            $biblionumber = $id;
435
            # check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter
472
            # check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter
436
            if (!$biblionumber && $isbn_check && $isbn) {
473
            if (!$biblionumber && $isbn_check && $isbn) {
Lines 566-572 delete $ENV{OVERRIDE_SYSPREF_CataloguingLog}; Link Here
566
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog};
603
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog};
567
604
568
my $timeneeded = gettimeofday - $starttime;
605
my $timeneeded = gettimeofday - $starttime;
569
print "\n$i MARC records done in $timeneeded seconds\n";
606
if ($import_holdings) {
607
    printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded);
608
} else {
609
    printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded);
610
}
570
if ($logfile){
611
if ($logfile){
571
  print $loghandle "file : $input_marc_file\n";
612
  print $loghandle "file : $input_marc_file\n";
572
  print $loghandle "$i MARC records done in $timeneeded seconds\n";
613
  print $loghandle "$i MARC records done in $timeneeded seconds\n";
Lines 687-692 Type of import: authority records Link Here
687
728
688
The I<FILE> to import
729
The I<FILE> to import
689
730
731
=item B<-holdings>
732
733
Import MARC 21 holdings records when interleaved with bibliographic records
734
(insert only, update not supported). Used only with -biblios.
735
690
=item  B<-v>
736
=item  B<-v>
691
737
692
Verbose mode. 1 means "some infos", 2 means "MARC dumping"
738
Verbose mode. 1 means "some infos", 2 means "MARC dumping"
Lines 732-738 I<UNIMARC> are supported. MARC21 by default. Link Here
732
=item B<-d>
778
=item B<-d>
733
779
734
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio,
780
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio,
735
biblioitems, items
781
biblioitems, items, holdings
736
782
737
=item B<-m>=I<FORMAT>
783
=item B<-m>=I<FORMAT>
738
784
(-)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;
41
use Koha::Holdings;
38
42
39
my $schema  = Koha::Database->new->schema;
43
my $schema  = Koha::Database->new->schema;
40
$schema->storage->txn_begin;
44
$schema->storage->txn_begin;
Lines 62-68 my $bad_biblio = Koha::Biblio->new()->store(); Link Here
62
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', schema => C4::Context->preference('marcflavour') } )->store();
66
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', schema => C4::Context->preference('marcflavour') } )->store();
63
my $bad_biblionumber = $bad_biblio->id;
67
my $bad_biblionumber = $bad_biblio->id;
64
68
69
# Add a framework for holdings
70
my $frameworkcode = 'HLD';
71
my $existing_mss = Koha::MarcSubfieldStructures->search({frameworkcode => $frameworkcode});
72
$existing_mss->delete() if $existing_mss;
73
my $existing_fw = Koha::BiblioFrameworks->find({frameworkcode => $frameworkcode});
74
$existing_fw->delete() if $existing_fw;
75
Koha::BiblioFramework->new({
76
    frameworkcode => $frameworkcode,
77
    frameworktext => 'Holdings'
78
})->store();
79
Koha::MarcSubfieldStructure->new({
80
    frameworkcode => $frameworkcode,
81
    tagfield => 852,
82
    tagsubfield => 'b',
83
    kohafield => 'holdings.holdingbranch'
84
})->store();
85
Koha::MarcSubfieldStructure->new({
86
    frameworkcode => $frameworkcode,
87
    tagfield => 852,
88
    tagsubfield => 'c',
89
    kohafield => 'holdings.location'
90
})->store();
91
Koha::MarcSubfieldStructure->new({
92
    frameworkcode => $frameworkcode,
93
    tagfield => 942,
94
    tagsubfield => 'n',
95
    kohafield => 'holdings.suppress'
96
})->store();
97
Koha::MarcSubfieldStructure->new({
98
    frameworkcode => $frameworkcode,
99
    tagfield => 999,
100
    tagsubfield => 'c',
101
    kohafield => 'biblio.biblionumber'
102
})->store();
103
Koha::MarcSubfieldStructure->new({
104
    frameworkcode => $frameworkcode,
105
    tagfield => 999,
106
    tagsubfield => 'e',
107
    kohafield => 'holdings.holding_id'
108
})->store();
109
65
my $builder = t::lib::TestBuilder->new;
110
my $builder = t::lib::TestBuilder->new;
111
my $holdingbranch = $builder->build({ source => 'Branch' });
112
113
my $holding_marc_1 = MARC::Record->new();
114
$holding_marc_1->leader('00202cx  a22000973  4500');
115
$holding_marc_1->append_fields(
116
    MARC::Field->new('852', '8', ' ', b => $holdingbranch->{branchcode}, c => 'Location', k => '1973', h => 'Tb', t => 'Copy 1')
117
);
118
my $holding = Koha::Holding->new();
119
$holding->biblionumber($biblionumber_1);
120
$holding->set_marc({ record => $holding_marc_1 });
121
$holding->store();
122
66
my $item_1_1 = $builder->build_sample_item(
123
my $item_1_1 = $builder->build_sample_item(
67
    {
124
    {
68
        biblionumber => $biblionumber_1,
125
        biblionumber => $biblionumber_1,
Lines 192-197 subtest 'export iso2709' => sub { Link Here
192
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
249
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
193
};
250
};
194
251
252
subtest 'export xml with holdings' => sub {
253
    plan tests => 3;
254
    my $generated_xml_file = '/tmp/test_export.xml';
255
    Koha::Exporter::Record::export(
256
        {   record_type     => 'bibs',
257
            record_ids      => [ $biblionumber_1, $biblionumber_2 ],
258
            format          => 'xml',
259
            output_filepath => $generated_xml_file,
260
            export_holdings => 1,
261
        }
262
    );
263
264
    my $generated_xml_content = read_file( $generated_xml_file );
265
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
266
    open my $fh, '<', $generated_xml_file;
267
    my $records = MARC::Batch->new( 'XML', $fh );
268
    my @records;
269
    # The following statement produces
270
    # Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/MARC/File/XML.pm line 398, <$fh> chunk 5.
271
    # Why?
272
    while ( my $record = $records->next ) {
273
        push @records, $record;
274
    }
275
    is( scalar( @records ), 3, 'Export XML with holdings: 3 records should have been exported' );
276
    my $holding_record = $records[1];
277
    my $branch = $holding_record->subfield('852', 'b');
278
    is( $branch, $holdingbranch->{branchcode}, 'Export XML with holdings: The holdings record contains correct branch code' );
279
    my $location = $holding_record->subfield('852', 'c');
280
    is( $location, 'Location', 'Export XML with holdings: The holdings record contains correct location' );
281
};
282
283
subtest 'export iso2709 with holdings' => sub {
284
    plan tests => 3;
285
    my $generated_mrc_file = '/tmp/test_export.mrc';
286
    # Get all item infos
287
    Koha::Exporter::Record::export(
288
        {   record_type     => 'bibs',
289
            record_ids      => [ $biblionumber_1, $biblionumber_2 ],
290
            format          => 'iso2709',
291
            output_filepath => $generated_mrc_file,
292
            export_holdings => 1,
293
        }
294
    );
295
296
    my $records = MARC::File::USMARC->in( $generated_mrc_file );
297
    my @records;
298
    while ( my $record = $records->next ) {
299
        push @records, $record;
300
    }
301
    is( scalar( @records ), 3, 'Export ISO2709 with holdings: 3 records should have been exported' );
302
    my $holding_record = $records[1];
303
    my $branch = $holding_record->subfield('852', 'b');
304
    is( $branch, $holdingbranch->{branchcode}, 'Export ISO2709 with holdings: The holdings record contains correct branch code' );
305
    my $location = $holding_record->subfield('852', 'c');
306
    is( $location, 'Location', 'Export ISO2709 with holdings: The holdings record contains correct location' );
307
};
308
195
subtest 'export without record_type' => sub {
309
subtest 'export without record_type' => sub {
196
    plan tests => 1;
310
    plan tests => 1;
197
311
(-)a/tools/export.pl (-1 / +2 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 210-215 if ( $op eq "export" ) { Link Here
210
                dont_export_fields => $export_remove_fields,
211
                dont_export_fields => $export_remove_fields,
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),
214
                export_holdings    => $export_holdings,
213
                only_export_items_for_branches => $only_export_items_for_branches,
215
                only_export_items_for_branches => $only_export_items_for_branches,
214
            }
216
            }
215
        );
217
        );
216
- 

Return to bug 20447