5 # find Koha's Perl modules
6 # test carefully before changing this
8 eval { require "$FindBin::Bin/kohalib.pl" };
18 # command-line parameters
22 my $batch_comment = "";
25 my $result = GetOptions(
26 'file:s' => \$input_file,
27 'match-bibs:s' => \$match_bibs,
28 'add-items' => \$add_items,
29 'comment:s' => \$batch_comment,
30 'h|help' => \$want_help
33 if (not $result or $input_file eq "" or $want_help) {
38 unless (-r $input_file) {
39 die "$0: cannot open input file $input_file: $!\n";
42 my $dbh = C4::Context->dbh;
43 $dbh->{AutoCommit} = 0;
44 process_batch($input_file, $match_bibs, $add_items, $batch_comment);
50 my ($input_file, $match_bibs, $add_items, $batch_comment) = @_;
52 open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
53 my $marc_records = "";
55 my $num_input_records = 0;
59 next unless $_; # skip if record has only whitespace, as might occur
60 # if file includes newlines between each MARC record
61 $marc_records .= $_; # FIXME - this sort of string concatenation
62 # is probably rather inefficient
67 my $marc_flavor = C4::Context->preference('marcflavour');
69 print "... staging MARC records -- please wait\n";
70 my ($batch_id, $num_valid, $num_items, @import_errors) =
71 BatchStageMarcRecords($marc_flavor, $marc_records, $input_file, $batch_comment, '', $add_items, 0,
72 100, \&print_progress_and_commit);
73 print "... finished staging MARC records\n";
75 my $num_with_matches = 0;
77 my $matcher = C4::Matcher->fetch($match_bibs) ;
78 if( ! defined $matcher) {
79 $matcher = C4::Matcher->new('biblio');
80 $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
81 $matcher->add_simple_required_check('245', 'a', -1, 0, '',
82 '245', 'a', -1, 0, '');
84 SetImportBatchMatcher($batch_id, $match_bibs);
86 print "... looking for matches with records already in database\n";
87 $num_with_matches = BatchFindBibDuplicates($batch_id, $matcher, 10, 100, \&print_progress_and_commit);
88 print "... finished looking for matches\n";
91 my $num_invalid_bibs = scalar(@import_errors);
94 MARC record staging report
95 ------------------------------------
96 Input file: $input_file
97 Number of input bibs: $num_input_records
98 Number of valid bibs: $num_valid
99 Number of invalid bibs: $num_invalid_bibs
102 print "Number of bibs matched: $num_with_matches\n";
104 print "Incoming bibs not matched against existing bibs (--match-bibs option not supplied)\n";
107 print "Number of items parsed: $num_items\n";
109 print "No items parsed (--add-items option not supplied)\n";
113 print "Batch number assigned: $batch_id\n";
117 sub print_progress_and_commit {
120 print "... processed $recs records\n";
125 $0: stage MARC bib file into reservoir.
127 Use this batch job to load a file of MARC bibliographic records
128 (with optional item information) into the Koha reservoir.
130 After running this program to stage your file, you can use
131 either the batch job commit_biblios_file.pl or the Koha
132 Tools option "Manage Staged MARC Records" to load the
133 records into the main Koha database.
136 --file <file_name> name of input MARC bib file
137 --match-bibs <match_id> use this option to match bibs
138 in the file with bibs already in
139 the database for future overlay.
140 If <match_id> isn't defined, a default
141 MARC21 ISBN & title match rule will be applied.
142 --add-items use this option to specify that
143 item data is embedded in the MARC
144 bibs and should be parsed.
145 --comment <comment> optional comment to describe
146 the record batch; if the comment
147 has spaces in it, surround the
148 comment with quotation marks.
149 --help or -h show this message.