diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 9ceb15a4a6..f67cdfe695 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -43,6 +43,7 @@ BEGIN { BatchFindBibDuplicates BatchCommitBibRecords BatchRevertBibRecords + CleanBatch GetAllImportBatches GetImportBatchRangeDesc @@ -698,6 +699,29 @@ sub BatchRevertItems { return $num_items_deleted; } +=head2 CleanBatch + +=over 4 + +CleanBatch($batch_id) + +=back + +Deletes all staged records from the import batch +and sets the status of the batch to 'cleaned'. Note +that deleting a stage record does *not* affect +any record that has been committed to the database. + +=cut + +sub CleanBatch { + my $batch_id = shift; + return unless defined $batch_id; + + C4::Context->dbh->do('DELETE FROM import_records WHERE import_batch_id = ?', {}, $batch_id); + SetImportBatchStatus($batch_id, 'cleaned'); +} + =head2 GetAllImportBatches =over 4 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl index b3cda3af57..933077538e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl @@ -43,6 +43,10 @@ + +
Cleaned import batch #
+ + No records have been staged. @@ -196,6 +200,7 @@ Page Staged # Bibs # Items + Action @@ -206,6 +211,14 @@ Page ?import_batch_id=&op=create_labels">(Create Label Batch) + +
" name="clean_batch_" id="clean_batch_" > + " /> + + +
+ + diff --git a/t/lib/KohaTest/ImportBatch.pm b/t/lib/KohaTest/ImportBatch.pm index 35f2b2edfc..a8fefaac9b 100644 --- a/t/lib/KohaTest/ImportBatch.pm +++ b/t/lib/KohaTest/ImportBatch.pm @@ -27,6 +27,7 @@ sub routines : Test( 1 ) { BatchCommitItems BatchRevertBibRecords BatchRevertItems + CleanBatch GetAllImportBatches GetImportBatchRangeDesc GetItemNumbersFromImportBatch diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl index 8ed03caf70..df4da462d9 100755 --- a/tools/manage-marc-import.pl +++ b/tools/manage-marc-import.pl @@ -96,7 +96,12 @@ if ($op eq "") { } import_biblios_list($template, $import_batch_id, $offset, $results_per_page); } elsif ($op eq "clean-batch") { - ; + CleanBatch($import_batch_id); + import_batches_list($template, $offset, $results_per_page); + $template->param( + did_clean => 1, + import_batch_id => $import_batch_id, + ); } elsif ($op eq "redo-matching") { my $new_matcher_id = $input->param('new_matcher_id'); my $current_matcher_id = $input->param('current_matcher_id'); @@ -180,7 +185,8 @@ sub import_batches_list { upload_timestamp => $batch->{'upload_timestamp'}, import_status => $batch->{'import_status'}, file_name => $batch->{'file_name'}, - comments => $batch->{'comments'} + comments => $batch->{'comments'}, + can_clean => ($batch->{'import_status'} ne 'cleaned') ? 1 : 0, }; } $template->param(batch_list => \@list); @@ -374,6 +380,9 @@ sub batch_info { $template->param(upload_timestamp => $batch->{'upload_timestamp'}); $template->param(num_biblios => $batch->{'num_biblios'}); $template->param(num_items => $batch->{'num_biblios'}); + if ($batch->{'import_status'} ne 'cleaned') { + $template->param(can_clean => 1); + } if ($batch->{'num_biblios'} > 0) { if ($batch->{'import_status'} eq 'staged' or $batch->{'import_status'} eq 'reverted') { $template->param(can_commit => 1);