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

(-)a/Koha/Exporter/Record.pm (-17 / +67 lines)
Lines 84-110 sub _get_record_for_export { Link Here
84
        }
84
        }
85
    }
85
    }
86
86
87
    if ($dont_export_fields) {
87
    _strip_unwanted_fields($record, $dont_export_fields) if $dont_export_fields;
88
        for my $f ( split / /, $dont_export_fields ) {
88
    C4::Biblio::RemoveAllNsb($record) if $clean;
89
            if ( $f =~ m/^(\d{3})(.)?$/ ) {
89
    return $record;
90
                my ( $field, $subfield ) = ( $1, $2 );
90
}
91
91
92
                # skip if this record doesn't have this field
92
sub _strip_unwanted_fields {
93
                if ( defined $record->field($field) ) {
93
    my ($record, $dont_export_fields) = @_;
94
                    if ( defined $subfield ) {
94
95
                        my @tags = $record->field($field);
95
    for my $f ( split / /, $dont_export_fields ) {
96
                        foreach my $t (@tags) {
96
        if ( $f =~ m/^(\d{3})(.)?$/ ) {
97
                            $t->delete_subfields($subfield);
97
            my ( $field, $subfield ) = ( $1, $2 );
98
                        }
98
99
                    } else {
99
            # skip if this record doesn't have this field
100
                        $record->delete_fields( $record->field($field) );
100
            if ( defined $record->field($field) ) {
101
                if ( defined $subfield ) {
102
                    my @tags = $record->field($field);
103
                    foreach my $t (@tags) {
104
                        $t->delete_subfields($subfield);
101
                    }
105
                    }
106
                } else {
107
                    $record->delete_fields( $record->field($field) );
102
                }
108
                }
103
            }
109
            }
104
        }
110
        }
105
    }
111
    }
106
    C4::Biblio::RemoveAllNsb($record) if $clean;
107
    return $record;
108
}
112
}
109
113
110
sub _get_authority_for_export {
114
sub _get_authority_for_export {
Lines 130-136 sub _get_biblio_for_export { Link Here
130
        C4::Biblio::EmbedItemsInMarcBiblio({
134
        C4::Biblio::EmbedItemsInMarcBiblio({
131
            marc_record  => $record,
135
            marc_record  => $record,
132
            biblionumber => $biblionumber,
136
            biblionumber => $biblionumber,
133
            item_numbers => $itemnumbers });
137
            item_numbers => $itemnumbers,
138
            skip_holdings => 1 });
134
        if ($only_export_items_for_branches && @$only_export_items_for_branches) {
139
        if ($only_export_items_for_branches && @$only_export_items_for_branches) {
135
            my %export_items_for_branches = map { $_ => 1 } @$only_export_items_for_branches;
140
            my %export_items_for_branches = map { $_ => 1 } @$only_export_items_for_branches;
136
            my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField( 'items.homebranch' );
141
            my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField( 'items.homebranch' );
Lines 146-151 sub _get_biblio_for_export { Link Here
146
    return $record;
151
    return $record;
147
}
152
}
148
153
154
sub _get_holdings_for_export {
155
    my ($params)           = @_;
156
    my $dont_export_fields = $params->{dont_export_fields};
157
    my $clean              = $params->{clean};
158
    my $biblionumber       = $params->{biblionumber};
159
160
    my @records;
161
    my $holdings = Koha::Holdings->search({ biblionumber => $biblionumber, deleted_on => undef });
162
    while (my $holding = $holdings->next()) {
163
        my $record = $holding->metadata()->record();
164
        _strip_unwanted_fields($record, $dont_export_fields) if $dont_export_fields;
165
        C4::Biblio::RemoveAllNsb($record) if $clean;
166
        C4::Biblio::UpsertMarcControlField($record, '004', $biblionumber);
167
        my $leader = $record->leader();
168
        if ($leader !~ /^.{6}[uvxy]/) {
169
            $leader =~ s/^(.{6})./$1u/;
170
            $record->leader($leader);
171
        }
172
        push @records, $record;
173
    }
174
    return \@records;
175
}
176
149
sub export {
177
sub export {
150
    my ($params) = @_;
178
    my ($params) = @_;
151
179
Lines 157-162 sub export { Link Here
157
    my $dont_export_fields = $params->{dont_export_fields};
185
    my $dont_export_fields = $params->{dont_export_fields};
158
    my $csv_profile_id     = $params->{csv_profile_id};
186
    my $csv_profile_id     = $params->{csv_profile_id};
159
    my $output_filepath    = $params->{output_filepath};
187
    my $output_filepath    = $params->{output_filepath};
188
    my $export_holdings    = $params->{export_holdings} // 0;
160
189
161
    if( !$record_type ) {
190
    if( !$record_type ) {
162
        Koha::Logger->get->warn( "No record_type given." );
191
        Koha::Logger->get->warn( "No record_type given." );
Lines 186-191 sub export { Link Here
186
                next;
215
                next;
187
            }
216
            }
188
            print $record->as_usmarc();
217
            print $record->as_usmarc();
218
            if ($export_holdings && $record_type eq 'bibs') {
219
                my $holdings = _get_holdings_for_export( { %$params, biblionumber => $record_id } );
220
                foreach my $holding (@$holdings) {
221
                    my $errorcount_on_decode = eval { scalar( MARC::File::USMARC->decode( $holding->as_usmarc )->warnings() ) };
222
                    if ( $errorcount_on_decode or $@ ) {
223
                        my $msg = "Holdings record for biblio $record_id could not be exported. " .
224
                            ( $@ // '' );
225
                        chomp $msg;
226
                        Koha::Logger->get->info( $msg );
227
                        next;
228
                    }
229
                    print $holding->as_usmarc();
230
                }
231
            }
189
        }
232
        }
190
    } elsif ( $format eq 'xml' ) {
233
    } elsif ( $format eq 'xml' ) {
191
        my $marcflavour = C4::Context->preference("marcflavour");
234
        my $marcflavour = C4::Context->preference("marcflavour");
Lines 198-203 sub export { Link Here
198
            next unless $record;
241
            next unless $record;
199
            print MARC::File::XML::record($record);
242
            print MARC::File::XML::record($record);
200
            print "\n";
243
            print "\n";
244
            if ($export_holdings && $record_type eq 'bibs') {
245
                my $holdings = _get_holdings_for_export( { %$params, biblionumber => $record_id } );
246
                foreach my $holding (@$holdings) {
247
                    print MARC::File::XML::record($holding);
248
                    print "\n";
249
                }
250
            }
201
        }
251
        }
202
        print MARC::File::XML::footer();
252
        print MARC::File::XML::footer();
203
        print "\n";
253
        print "\n";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt (-1 / +9 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; Tools &rsaquo; Koha</title>
7
<title>Export data &rsaquo; Tools &rsaquo; Koha</title>
Lines 142-148 Link Here
142
            </fieldset>
143
            </fieldset>
143
            <fieldset class="rows">
144
            <fieldset class="rows">
144
            <legend> Options</legend>
145
            <legend> Options</legend>
145
        <ol>        <li>
146
                <ol>
147
                [% IF ( Koha.Preference('SummaryHoldings') ) %]
148
                <li>
149
                <label for="export_holdings">Export holdings records (MARC 21 biblios only):</label>
150
                <input id="export_holdings" type="checkbox" name="export_holdings" />
151
                </li>
152
                [% END %]
153
                <li>
146
                <label for="dont_export_item">Don't export items:</label>
154
                <label for="dont_export_item">Don't export items:</label>
147
                <input id="dont_export_item" type="checkbox" name="dont_export_item" />
155
                <input id="dont_export_item" type="checkbox" name="dont_export_item" />
148
                </li>
156
                </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 / +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 / +114 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
my $schema  = Koha::Database->new->schema;
42
my $schema  = Koha::Database->new->schema;
40
$schema->storage->txn_begin;
43
$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();
65
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;
66
my $bad_biblionumber = $bad_biblio->id;
64
67
68
# Add a framework for holdings
69
my $frameworkcode = 'HLD';
70
my $existing_mss = Koha::MarcSubfieldStructures->search({frameworkcode => $frameworkcode});
71
$existing_mss->delete() if $existing_mss;
72
my $existing_fw = Koha::BiblioFrameworks->find({frameworkcode => $frameworkcode});
73
$existing_fw->delete() if $existing_fw;
74
Koha::BiblioFramework->new({
75
    frameworkcode => $frameworkcode,
76
    frameworktext => 'Holdings'
77
})->store();
78
Koha::MarcSubfieldStructure->new({
79
    frameworkcode => $frameworkcode,
80
    tagfield => 852,
81
    tagsubfield => 'b',
82
    kohafield => 'holdings.holdingbranch'
83
})->store();
84
Koha::MarcSubfieldStructure->new({
85
    frameworkcode => $frameworkcode,
86
    tagfield => 852,
87
    tagsubfield => 'c',
88
    kohafield => 'holdings.location'
89
})->store();
90
Koha::MarcSubfieldStructure->new({
91
    frameworkcode => $frameworkcode,
92
    tagfield => 942,
93
    tagsubfield => 'n',
94
    kohafield => 'holdings.suppress'
95
})->store();
96
Koha::MarcSubfieldStructure->new({
97
    frameworkcode => $frameworkcode,
98
    tagfield => 999,
99
    tagsubfield => 'c',
100
    kohafield => 'biblio.biblionumber'
101
})->store();
102
Koha::MarcSubfieldStructure->new({
103
    frameworkcode => $frameworkcode,
104
    tagfield => 999,
105
    tagsubfield => 'e',
106
    kohafield => 'holdings.holding_id'
107
})->store();
108
65
my $builder = t::lib::TestBuilder->new;
109
my $builder = t::lib::TestBuilder->new;
110
my $holdingbranch = $builder->build({ source => 'Branch' });
111
112
my $holding_marc_1 = MARC::Record->new();
113
$holding_marc_1->leader('00202cx  a22000973  4500');
114
$holding_marc_1->append_fields(
115
    MARC::Field->new('852', '8', ' ', b => $holdingbranch->{branchcode}, c => 'Location', k => '1973', h => 'Tb', t => 'Copy 1')
116
);
117
my $holding = Koha::Holding->new();
118
$holding->biblionumber($biblionumber_1);
119
$holding->set_marc({ record => $holding_marc_1 });
120
$holding->store();
121
66
my $item_1_1 = $builder->build_sample_item(
122
my $item_1_1 = $builder->build_sample_item(
67
    {
123
    {
68
        biblionumber => $biblionumber_1,
124
        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' );
248
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
193
};
249
};
194
250
251
subtest 'export xml with holdings' => sub {
252
    plan tests => 3;
253
    my $generated_xml_file = '/tmp/test_export.xml';
254
    Koha::Exporter::Record::export(
255
        {   record_type     => 'bibs',
256
            record_ids      => [ $biblionumber_1, $biblionumber_2 ],
257
            format          => 'xml',
258
            output_filepath => $generated_xml_file,
259
            export_holdings => 1,
260
        }
261
    );
262
263
    my $generated_xml_content = read_file( $generated_xml_file );
264
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
265
    open my $fh, '<', $generated_xml_file;
266
    my $records = MARC::Batch->new( 'XML', $fh );
267
    my @records;
268
    # The following statement produces
269
    # Use of uninitialized value in concatenation (.) or string at /usr/share/perl5/MARC/File/XML.pm line 398, <$fh> chunk 5.
270
    # Why?
271
    while ( my $record = $records->next ) {
272
        push @records, $record;
273
    }
274
    is( scalar( @records ), 3, 'Export XML with holdings: 3 records should have been exported' );
275
    my $holding_record = $records[1];
276
    my $branch = $holding_record->subfield('852', 'b');
277
    is( $branch, $holdingbranch->{branchcode}, 'Export XML with holdings: The holdings record contains correct branch code' );
278
    my $location = $holding_record->subfield('852', 'c');
279
    is( $location, 'Location', 'Export XML with holdings: The holdings record contains correct location' );
280
};
281
282
subtest 'export iso2709 with holdings' => sub {
283
    plan tests => 3;
284
    my $generated_mrc_file = '/tmp/test_export.mrc';
285
    # Get all item infos
286
    Koha::Exporter::Record::export(
287
        {   record_type     => 'bibs',
288
            record_ids      => [ $biblionumber_1, $biblionumber_2 ],
289
            format          => 'iso2709',
290
            output_filepath => $generated_mrc_file,
291
            export_holdings => 1,
292
        }
293
    );
294
295
    my $records = MARC::File::USMARC->in( $generated_mrc_file );
296
    my @records;
297
    while ( my $record = $records->next ) {
298
        push @records, $record;
299
    }
300
    is( scalar( @records ), 3, 'Export ISO2709 with holdings: 3 records should have been exported' );
301
    my $holding_record = $records[1];
302
    my $branch = $holding_record->subfield('852', 'b');
303
    is( $branch, $holdingbranch->{branchcode}, 'Export ISO2709 with holdings: The holdings record contains correct branch code' );
304
    my $location = $holding_record->subfield('852', 'c');
305
    is( $location, 'Location', 'Export ISO2709 with holdings: The holdings record contains correct location' );
306
};
307
195
subtest 'export without record_type' => sub {
308
subtest 'export without record_type' => sub {
196
    plan tests => 1;
309
    plan tests => 1;
197
310
(-)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 209-214 if ( $op eq "export" ) { Link Here
209
                dont_export_fields => $export_remove_fields,
210
                dont_export_fields => $export_remove_fields,
210
                csv_profile_id     => $csv_profile_id,
211
                csv_profile_id     => $csv_profile_id,
211
                export_items       => (not $dont_export_items),
212
                export_items       => (not $dont_export_items),
213
                export_holdings    => $export_holdings,
212
                only_export_items_for_branches => $only_export_items_for_branches,
214
                only_export_items_for_branches => $only_export_items_for_branches,
213
            }
215
            }
214
        );
216
        );
215
- 

Return to bug 20447