fix for bug 1723. no auth on finishreceive.pl
[koha.git] / misc / commit_biblios_file.pl
blob4c8d8ac3d1de5d7076e07dfd9d9137ce7ee97f09
1 #!/usr/bin/perl
3 use strict;
4 BEGIN {
5 # find Koha's Perl modules
6 # test carefully before changing this
7 use FindBin;
8 eval { require "$FindBin::Bin/kohalib.pl" };
11 use C4::Context;
12 use C4::ImportBatch;
13 use Getopt::Long;
15 $| = 1;
17 # command-line parameters
18 my $batch_number = "";
19 my $list_batches = 0;
20 my $want_help = 0;
22 my $result = GetOptions(
23 'batch-number:s' => \$batch_number,
24 'list-batches' => \$list_batches,
25 'h|help' => \$want_help
28 if ($want_help or (not $batch_number and not $list_batches)) {
29 print_usage();
30 exit 0;
33 if ($list_batches) {
34 list_batches();
35 exit 0;
38 # FIXME dummy user so that logging won't fail
39 # in future, probably should tie to a real user account
40 C4::Context->set_userenv(0, 'batch', 0, 'batch', 'batch', 'batch', 'batch', 'batch');
42 if ($batch_number =~ /^\d+$/ and $batch_number > 0) {
43 my $batch = GetImportBatch($batch_number);
44 die "$0: import batch $batch_number does not exist in database\n" unless defined $batch;
45 die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
46 unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted";
47 process_batch($batch_number);
48 } else {
49 die "$0: please specify a numeric batch ID\n";
52 exit 0;
54 sub list_batches {
55 my $results = GetAllImportBatches();
56 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n", "#", "File name", "Batch comments", "Status");
57 print '-' x 5, ' ' , '-' x 25, ' ', '-' x 25, ' ', '-' x 10, "\n" ;
58 foreach my $batch (@{ $results}) {
59 if ($batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted") {
60 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n",
61 $batch->{'import_batch_id'},
62 $batch->{'file_name'},
63 $batch->{'comments'},
64 $batch->{'import_status'});
69 sub process_batch {
70 my ($import_batch_id) = @_;
72 print "... importing MARC records -- please wait\n";
73 my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) =
74 BatchCommitBibRecords($import_batch_id, 100, \&print_progress);
75 print "... finished importing MARC records\n";
77 print <<_SUMMARY_;
79 MARC record import report
80 ----------------------------------------
81 Batch number: $import_batch_id
82 Number of new bibs added: $num_added
83 Number of bibs replaced: $num_updated
84 Number of bibs ignored: $num_ignored
85 Number of items added: $num_items_added
86 Number of items ignored: $num_items_errored
88 Note: an item is ignored if its barcode is a
89 duplicate of one already in the database.
90 _SUMMARY_
93 sub print_progress {
94 my $recs = shift;
95 print "... processed $recs records\n";
98 sub print_usage {
99 print <<_USAGE_;
100 $0: import a batch of staged MARC records into database.
102 Use this batch job to complete the import of a batch of
103 MARC records that was staged either by the batch job
104 stage_biblios_file.pl or by the Koha Tools option
105 "Stage MARC Records for Import".
107 Parameters:
108 --batch-number <#> number of the record batch
109 to import
110 --list-batches print a list of record batches
111 available to commit
112 --help or -h show this message.
113 _USAGE_