|
Lines 4-9
Link Here
|
| 4 |
# |
4 |
# |
| 5 |
# Copyright (C) 2007 LibLime |
5 |
# Copyright (C) 2007 LibLime |
| 6 |
# Parts Copyright BSZ 2011 |
6 |
# Parts Copyright BSZ 2011 |
|
|
7 |
# Parts Copyright C & P Bibliography Services 2012 |
| 7 |
# |
8 |
# |
| 8 |
# Koha is free software; you can redistribute it and/or modify it under the |
9 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 9 |
# terms of the GNU General Public License as published by the Free Software |
10 |
# terms of the GNU General Public License as published by the Free Software |
|
Lines 35-42
use Getopt::Long;
Link Here
|
| 35 |
$| = 1; |
36 |
$| = 1; |
| 36 |
|
37 |
|
| 37 |
# command-line parameters |
38 |
# command-line parameters |
|
|
39 |
my $record_type = "biblio"; |
| 38 |
my $encoding = ""; |
40 |
my $encoding = ""; |
| 39 |
my $match_bibs = 0; |
41 |
my $authorities = 0; |
|
|
42 |
my $match = 0; |
| 40 |
my $add_items = 0; |
43 |
my $add_items = 0; |
| 41 |
my $input_file = ""; |
44 |
my $input_file = ""; |
| 42 |
my $batch_comment = ""; |
45 |
my $batch_comment = ""; |
|
Lines 46-58
my $no_replace ;
Link Here
|
| 46 |
my $result = GetOptions( |
49 |
my $result = GetOptions( |
| 47 |
'encoding:s' => \$encoding, |
50 |
'encoding:s' => \$encoding, |
| 48 |
'file:s' => \$input_file, |
51 |
'file:s' => \$input_file, |
| 49 |
'match-bibs:s' => \$match_bibs, |
52 |
'match|match-bibs:s' => \$match, |
| 50 |
'add-items' => \$add_items, |
53 |
'add-items' => \$add_items, |
| 51 |
'no-replace' => \$no_replace, |
54 |
'no-replace' => \$no_replace, |
| 52 |
'comment:s' => \$batch_comment, |
55 |
'comment:s' => \$batch_comment, |
|
|
56 |
'authorities' => \$authorities, |
| 53 |
'h|help' => \$want_help |
57 |
'h|help' => \$want_help |
| 54 |
); |
58 |
); |
| 55 |
|
59 |
|
|
|
60 |
$record_type = 'auth' if ($authorities); |
| 61 |
|
| 56 |
if ($encoding eq "") { |
62 |
if ($encoding eq "") { |
| 57 |
$encoding = "utf8"; |
63 |
$encoding = "utf8"; |
| 58 |
} |
64 |
} |
|
Lines 68-80
unless (-r $input_file) {
Link Here
|
| 68 |
|
74 |
|
| 69 |
my $dbh = C4::Context->dbh; |
75 |
my $dbh = C4::Context->dbh; |
| 70 |
$dbh->{AutoCommit} = 0; |
76 |
$dbh->{AutoCommit} = 0; |
| 71 |
process_batch($input_file, $match_bibs, $add_items, $batch_comment); |
77 |
process_batch($input_file, $record_type, $match, $add_items, $batch_comment); |
| 72 |
$dbh->commit(); |
78 |
$dbh->commit(); |
| 73 |
|
79 |
|
| 74 |
exit 0; |
80 |
exit 0; |
| 75 |
|
81 |
|
| 76 |
sub process_batch { |
82 |
sub process_batch { |
| 77 |
my ($input_file, $match_bibs, $add_items, $batch_comment) = @_; |
83 |
my ($input_file, $record_type, $match, $add_items, $batch_comment) = @_; |
| 78 |
|
84 |
|
| 79 |
open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n"; |
85 |
open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n"; |
| 80 |
my $marc_records = ""; |
86 |
my $marc_records = ""; |
|
Lines 92-141
sub process_batch {
Link Here
|
| 92 |
close IN; |
98 |
close IN; |
| 93 |
|
99 |
|
| 94 |
print "... staging MARC records -- please wait\n"; |
100 |
print "... staging MARC records -- please wait\n"; |
| 95 |
my ($batch_id, $num_valid, $num_items, @import_errors) = |
101 |
my ($batch_id, $num_valid_records, $num_items, @import_errors) = |
| 96 |
BatchStageMarcRecords($encoding, $marc_records, $input_file, $batch_comment, '', $add_items, 0, |
102 |
BatchStageMarcRecords($record_type, $encoding, $marc_records, $input_file, $batch_comment, '', $add_items, 0, |
| 97 |
100, \&print_progress_and_commit); |
103 |
100, \&print_progress_and_commit); |
| 98 |
print "... finished staging MARC records\n"; |
104 |
print "... finished staging MARC records\n"; |
| 99 |
|
105 |
|
| 100 |
my $num_with_matches = 0; |
106 |
my $num_with_matches = 0; |
| 101 |
if ($match_bibs) { |
107 |
if ($match) { |
| 102 |
my $matcher = C4::Matcher->fetch($match_bibs) ; |
108 |
my $matcher = C4::Matcher->fetch($match) ; |
| 103 |
if (! defined $matcher) { |
109 |
if (defined $matcher) { |
| 104 |
$matcher = C4::Matcher->new('biblio'); |
110 |
SetImportBatchMatcher($batch_id, $match); |
|
|
111 |
} elsif ($record_type eq 'biblio') { |
| 112 |
$matcher = C4::Matcher->new($record_type); |
| 105 |
$matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, ''); |
113 |
$matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, ''); |
| 106 |
$matcher->add_simple_required_check('245', 'a', -1, 0, '', |
114 |
$matcher->add_simple_required_check('245', 'a', -1, 0, '', |
| 107 |
'245', 'a', -1, 0, ''); |
115 |
'245', 'a', -1, 0, ''); |
| 108 |
} else { |
|
|
| 109 |
SetImportBatchMatcher($batch_id, $match_bibs); |
| 110 |
} |
116 |
} |
| 111 |
# set default record overlay behavior |
117 |
# set default record overlay behavior |
| 112 |
SetImportBatchOverlayAction($batch_id, ($no_replace) ? 'ignore' : 'replace'); |
118 |
SetImportBatchOverlayAction($batch_id, ($no_replace) ? 'ignore' : 'replace'); |
| 113 |
SetImportBatchNoMatchAction($batch_id, 'create_new'); |
119 |
SetImportBatchNoMatchAction($batch_id, 'create_new'); |
| 114 |
SetImportBatchItemAction($batch_id, 'always_add'); |
120 |
SetImportBatchItemAction($batch_id, 'always_add'); |
| 115 |
print "... looking for matches with records already in database\n"; |
121 |
print "... looking for matches with records already in database\n"; |
| 116 |
$num_with_matches = BatchFindBibDuplicates($batch_id, $matcher, 10, 100, \&print_progress_and_commit); |
122 |
$num_with_matches = BatchFindDuplicates($batch_id, $matcher, 10, 100, \&print_progress_and_commit); |
| 117 |
print "... finished looking for matches\n"; |
123 |
print "... finished looking for matches\n"; |
| 118 |
} |
124 |
} |
| 119 |
|
125 |
|
| 120 |
my $num_invalid_bibs = scalar(@import_errors); |
126 |
my $num_invalid_records = scalar(@import_errors); |
| 121 |
print <<_SUMMARY_; |
127 |
print <<_SUMMARY_; |
| 122 |
|
128 |
|
| 123 |
MARC record staging report |
129 |
MARC record staging report |
| 124 |
------------------------------------ |
130 |
------------------------------------ |
| 125 |
Input file: $input_file |
131 |
Input file: $input_file |
| 126 |
Number of input bibs: $num_input_records |
132 |
Record type: $record_type |
| 127 |
Number of valid bibs: $num_valid |
133 |
Number of input records: $num_input_records |
| 128 |
Number of invalid bibs: $num_invalid_bibs |
134 |
Number of valid records: $num_valid_records |
|
|
135 |
Number of invalid records: $num_invalid_records |
| 129 |
_SUMMARY_ |
136 |
_SUMMARY_ |
| 130 |
if ($match_bibs) { |
137 |
if ($match) { |
| 131 |
print "Number of bibs matched: $num_with_matches\n"; |
138 |
print "Number of records matched: $num_with_matches\n"; |
| 132 |
} else { |
139 |
} else { |
| 133 |
print "Incoming bibs not matched against existing bibs (--match-bibs option not supplied)\n"; |
140 |
print "Incoming records not matched against existing records (--match option not supplied)\n"; |
| 134 |
} |
141 |
} |
| 135 |
if ($add_items) { |
142 |
if ($record_type eq 'biblio') { |
| 136 |
print "Number of items parsed: $num_items\n"; |
143 |
if ($add_items) { |
| 137 |
} else { |
144 |
print "Number of items parsed: $num_items\n"; |
| 138 |
print "No items parsed (--add-items option not supplied)\n"; |
145 |
} else { |
|
|
146 |
print "No items parsed (--add-items option not supplied)\n"; |
| 147 |
} |
| 139 |
} |
148 |
} |
| 140 |
|
149 |
|
| 141 |
print "\n"; |
150 |
print "\n"; |
|
Lines 151-181
sub print_progress_and_commit {
Link Here
|
| 151 |
|
160 |
|
| 152 |
sub print_usage { |
161 |
sub print_usage { |
| 153 |
print <<_USAGE_; |
162 |
print <<_USAGE_; |
| 154 |
$0: stage MARC bib file into reservoir. |
163 |
$0: stage MARC file into reservoir. |
| 155 |
|
164 |
|
| 156 |
Use this batch job to load a file of MARC bibliographic records |
165 |
Use this batch job to load a file of MARC bibliographic |
| 157 |
(with optional item information) into the Koha reservoir. |
166 |
(with optional item information) or authority records into |
|
|
167 |
the Koha reservoir. |
| 158 |
|
168 |
|
| 159 |
After running this program to stage your file, you can use |
169 |
After running this program to stage your file, you can use |
| 160 |
either the batch job commit_biblios_file.pl or the Koha |
170 |
either the batch job commit_file.pl or the Koha |
| 161 |
Tools option "Manage Staged MARC Records" to load the |
171 |
Tools option "Manage Staged MARC Records" to load the |
| 162 |
records into the main Koha database. |
172 |
records into the main Koha database. |
| 163 |
|
173 |
|
| 164 |
Parameters: |
174 |
Parameters: |
| 165 |
--file <file_name> name of input MARC bib file |
175 |
--file <file_name> name of input MARC bib file |
|
|
176 |
--authorities stage authority records instead of bibs |
| 166 |
--encoding <encoding> encoding of MARC records, default is utf8. |
177 |
--encoding <encoding> encoding of MARC records, default is utf8. |
| 167 |
Other possible options are: MARC-8, |
178 |
Other possible options are: MARC-8, |
| 168 |
ISO_5426, ISO_6937, ISO_8859-1, EUC-KR |
179 |
ISO_5426, ISO_6937, ISO_8859-1, EUC-KR |
| 169 |
--match-bibs <match_id> use this option to match bibs |
180 |
--match <match_id> use this option to match records |
| 170 |
in the file with bibs already in |
181 |
in the file with records already in |
| 171 |
the database for future overlay. |
182 |
the database for future overlay. |
| 172 |
If <match_id> isn't defined, a default |
183 |
If <match_id> isn't defined, a default |
| 173 |
MARC21 ISBN & title match rule will be applied. |
184 |
MARC21 ISBN & title match rule will be applied |
|
|
185 |
for bib imports. |
| 174 |
--add-items use this option to specify that |
186 |
--add-items use this option to specify that |
| 175 |
item data is embedded in the MARC |
187 |
item data is embedded in the MARC |
| 176 |
bibs and should be parsed. |
188 |
bibs and should be parsed. |
| 177 |
--no-replace overlay action for bib record: default is to |
189 |
--no-replace overlay action for record: default is to |
| 178 |
replace extant bib with the imported record. |
190 |
replace extant with the imported record. |
| 179 |
--comment <comment> optional comment to describe |
191 |
--comment <comment> optional comment to describe |
| 180 |
the record batch; if the comment |
192 |
the record batch; if the comment |
| 181 |
has spaces in it, surround the |
193 |
has spaces in it, surround the |