8 use C4::ImportBatch qw( GetAllImportBatches GetImportBatch BatchCommitRecords BatchRevertRecords );
9 use Getopt::Long qw( GetOptions );
13 # command-line parameters
14 my $batch_number = "";
20 my $result = GetOptions(
21 'batch-number:s' => \$batch_number,
22 'list-batches' => \$list_batches,
23 'framework:s' => \$framework,
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');
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;
48 die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
49 unless $batch->{'import_status'} eq "imported";
50 revert_batch($batch_number);
52 die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
53 unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted";
54 process_batch($batch_number);
58 die "$0: please specify a numeric batch ID\n";
64 my $results = GetAllImportBatches();
65 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n", "#", "File name", "Batch comments", "Status");
66 print '-' x 5, ' ' , '-' x 25, ' ', '-' x 25, ' ', '-' x 10, "\n" ;
67 foreach my $batch (@{ $results}) {
68 if ($batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted") {
69 print sprintf("%5.5s %-25.25s %-25.25s %-10.10s\n",
70 $batch->{'import_batch_id'},
71 $batch->{'file_name'},
73 $batch->{'import_status'});
79 my ($import_batch_id) = @_;
81 print "... importing MARC records -- please wait\n";
82 my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) =
83 BatchCommitRecords($import_batch_id, $framework, 100, \&print_progress_and_commit);
84 print "... finished importing MARC records\n";
88 MARC record import report
89 ----------------------------------------
90 Batch number: $import_batch_id
91 Number of new records added: $num_added
92 Number of records replaced: $num_updated
93 Number of records ignored: $num_ignored
94 Number of items added: $num_items_added
95 Number of items replaced: $num_items_replaced
96 Number of items ignored: $num_items_errored
98 Note: an item is ignored if its barcode is a
99 duplicate of one already in the database.
104 my ($import_batch_id) = @_;
106 print "... reverting batch -- please wait\n";
107 my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored) =
108 BatchRevertRecords($import_batch_id, 100, \&print_progress_and_commit);
109 print "... finished reverting batch\n";
113 MARC record import report
114 ----------------------------------------
115 Batch number: $import_batch_id
116 Number of records deleted: $num_deleted
117 Number of errors: $num_errors
118 Number of records reverted: $num_reverted
119 Number of records ignored: $num_ignored
120 Number of items added: $num_items_deleted
126 sub print_progress_and_commit {
128 print "... processed $recs records\n";
134 $0: import a batch of staged MARC records into database.
136 Use this batch job to complete the import of a batch of
137 MARC records that was staged either by the batch job
138 stage_file.pl or by the Koha Tools option
139 "Stage MARC Records for Import".
142 --batch-number <#> number of the record batch
144 --framework <code> add new records using this framework. If
145 omitted, the default framework is used.
146 --list-batches print a list of record batches
148 --revert revert a batch instead of importing it
149 --help or -h show this message.