5 # find Koha's Perl modules
6 # test carefully before changing this
8 eval { require "$FindBin::Bin/kohalib.pl" };
17 # command-line parameters
18 my $batch_number = "";
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)) {
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 my $dbh = C4
::Context
->dbh;
43 $dbh->{AutoCommit
} = 0;
44 if ($batch_number =~ /^\d+$/ and $batch_number > 0) {
45 my $batch = GetImportBatch
($batch_number);
46 die "$0: import batch $batch_number does not exist in database\n" unless defined $batch;
47 die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
48 unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted";
49 process_batch
($batch_number);
52 die "$0: please specify a numeric batch ID\n";
58 my $results = GetAllImportBatches
();
59 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n", "#", "File name", "Batch comments", "Status");
60 print '-' x
5, ' ' , '-' x
25, ' ', '-' x
25, ' ', '-' x
10, "\n" ;
61 foreach my $batch (@
{ $results}) {
62 if ($batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted") {
63 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n",
64 $batch->{'import_batch_id'},
65 $batch->{'file_name'},
67 $batch->{'import_status'});
73 my ($import_batch_id) = @_;
75 print "... importing MARC records -- please wait\n";
76 my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) =
77 BatchCommitBibRecords
($import_batch_id, 100, \
&print_progress_and_commit
);
78 print "... finished importing MARC records\n";
82 MARC record import report
83 ----------------------------------------
84 Batch number
: $import_batch_id
85 Number of new bibs added
: $num_added
86 Number of bibs replaced
: $num_updated
87 Number of bibs ignored
: $num_ignored
88 Number of items added
: $num_items_added
89 Number of items ignored
: $num_items_errored
91 Note
: an item is ignored
if its barcode is a
92 duplicate of one already
in the database
.
96 sub print_progress_and_commit
{
98 print "... processed $recs records\n";
104 $0: import a batch of staged MARC records into database
.
106 Use this batch job to complete the import of a batch of
107 MARC records that was staged either by the batch job
108 stage_biblios_file
.pl
or by the Koha Tools option
109 "Stage MARC Records for Import".
112 --batch
-number
<#> number of the record batch
114 --list
-batches
print a list of record batches
116 --help
or -h show this message
.