4 #use warnings; FIXME - Bug 2505
6 # find Koha's Perl modules
7 # test carefully before changing this
9 eval { require "$FindBin::Bin/kohalib.pl" };
18 # command-line parameters
19 my $batch_number = "";
23 my $result = GetOptions(
24 'batch-number:s' => \$batch_number,
25 'list-batches' => \$list_batches,
26 'h|help' => \$want_help
29 if ($want_help or (not $batch_number and not $list_batches)) {
39 # FIXME dummy user so that logging won't fail
40 # in future, probably should tie to a real user account
41 C4::Context->set_userenv(0, 'batch', 0, 'batch', 'batch', 'batch', 'batch', 'batch');
43 my $dbh = C4::Context->dbh;
44 $dbh->{AutoCommit} = 0;
45 if ($batch_number =~ /^\d+$/ and $batch_number > 0) {
46 my $batch = GetImportBatch($batch_number);
47 die "$0: import batch $batch_number does not exist in database\n" unless defined $batch;
48 die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
49 unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted";
50 process_batch($batch_number);
53 die "$0: please specify a numeric batch ID\n";
59 my $results = GetAllImportBatches();
60 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n", "#", "File name", "Batch comments", "Status");
61 print '-' x 5, ' ' , '-' x 25, ' ', '-' x 25, ' ', '-' x 10, "\n" ;
62 foreach my $batch (@{ $results}) {
63 if ($batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted") {
64 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n",
65 $batch->{'import_batch_id'},
66 $batch->{'file_name'},
68 $batch->{'import_status'});
74 my ($import_batch_id) = @_;
76 print "... importing MARC records -- please wait\n";
77 my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) =
78 BatchCommitBibRecords($import_batch_id, '', 100, \&print_progress_and_commit);
79 print "... finished importing MARC records\n";
83 MARC record import report
84 ----------------------------------------
85 Batch number: $import_batch_id
86 Number of new bibs added: $num_added
87 Number of bibs replaced: $num_updated
88 Number of bibs ignored: $num_ignored
89 Number of items added: $num_items_added
90 Number of items ignored: $num_items_errored
92 Note: an item is ignored if its barcode is a
93 duplicate of one already in the database.
97 sub print_progress_and_commit {
99 print "... processed $recs records\n";
105 $0: import a batch of staged MARC records into database.
107 Use this batch job to complete the import of a batch of
108 MARC records that was staged either by the batch job
109 stage_biblios_file.pl or by the Koha Tools option
110 "Stage MARC Records for Import".
113 --batch-number <#> number of the record batch
115 --list-batches print a list of record batches
117 --help or -h show this message.