6 # find Koha's Perl modules
7 # test carefully before changing this
9 eval { require "$FindBin::Bin/kohalib.pl" };
14 use C4::ImportBatch qw( GetAllImportBatches GetImportBatch BatchCommitRecords BatchRevertRecords );
15 use Getopt::Long qw( GetOptions );
19 # command-line parameters
20 my $batch_number = "";
26 my $result = GetOptions(
27 'batch-number:s' => \$batch_number,
28 'list-batches' => \$list_batches,
29 'framework:s' => \$framework,
31 'h|help' => \$want_help
34 if ($want_help or (not $batch_number and not $list_batches)) {
44 # FIXME dummy user so that logging won't fail
45 # in future, probably should tie to a real user account
46 C4::Context->set_userenv(0, 'batch', 0, 'batch', 'batch', 'batch', 'batch');
48 if ($batch_number =~ /^\d+$/ and $batch_number > 0) {
49 my $batch = GetImportBatch($batch_number);
50 die "$0: import batch $batch_number does not exist in database\n" unless defined $batch;
52 die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
53 unless $batch->{'import_status'} eq "imported";
54 revert_batch($batch_number);
56 die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
57 unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted";
58 process_batch($batch_number);
61 die "$0: please specify a numeric batch ID\n";
67 my $results = GetAllImportBatches();
68 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n", "#", "File name", "Batch comments", "Status");
69 print '-' x 5, ' ' , '-' x 25, ' ', '-' x 25, ' ', '-' x 10, "\n" ;
70 foreach my $batch (@{ $results}) {
71 if ($batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted") {
72 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n",
73 $batch->{'import_batch_id'},
74 $batch->{'file_name'},
76 $batch->{'import_status'});
82 my ($import_batch_id) = @_;
84 print "... importing MARC records -- please wait\n";
85 my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) =
87 batch_id => $import_batch_id,
88 framework => $framework,
89 progress_interval => 100,
90 progress_callback => \&print_progress
92 print "... finished importing MARC records\n";
96 MARC record import report
97 ----------------------------------------
98 Batch number: $import_batch_id
99 Number of new records added: $num_added
100 Number of records replaced: $num_updated
101 Number of records ignored: $num_ignored
102 Number of items added: $num_items_added
103 Number of items replaced: $num_items_replaced
104 Number of items ignored: $num_items_errored
106 Note: an item is ignored if its barcode is a
107 duplicate of one already in the database.
112 my ($import_batch_id) = @_;
114 print "... reverting batch -- please wait\n";
115 my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored) =
116 BatchRevertRecords( $import_batch_id );
117 print "... finished reverting batch\n";
121 MARC record import report
122 ----------------------------------------
123 Batch number: $import_batch_id
124 Number of records deleted: $num_deleted
125 Number of errors: $num_errors
126 Number of records reverted: $num_reverted
127 Number of records ignored: $num_ignored
128 Number of items deleted: $num_items_deleted
136 print "... processed $recs records\n";
141 $0: import a batch of staged MARC records into database.
143 Use this batch job to complete the import of a batch of
144 MARC records that was staged either by the batch job
145 stage_file.pl or by the Koha Tools option
146 "Stage MARC Records for Import".
149 --batch-number <#> number of the record batch
151 --framework <code> add new records using this framework. If
152 omitted, the default framework is used.
153 --list-batches print a list of record batches
155 --revert revert a batch instead of importing it
156 --help or -h show this message.