@@ -, +, @@
cleaned
---
C4/ImportBatch.pm | 19 +++++++++++++
.../prog/en/modules/tools/manage-marc-import.tt | 15 +++++++++--
t/db_dependent/ImportBatch.t | 31 +++++++++++++++++++++-
tools/manage-marc-import.pl | 6 +++++
4 files changed, 68 insertions(+), 3 deletions(-)
--- a/C4/ImportBatch.pm
+++ a/C4/ImportBatch.pm
@@ -53,6 +53,7 @@ BEGIN {
BatchCommitRecords
BatchRevertRecords
CleanBatch
+ DeleteBatch
GetAllImportBatches
GetStagedWebserviceBatches
@@ -959,6 +960,24 @@ sub CleanBatch {
SetImportBatchStatus($batch_id, 'cleaned');
}
+=head2 DeleteBatch
+
+ DeleteBatch($batch_id)
+
+Deletes the record from the database. This can only be done
+once the batch has been cleaned.
+
+=cut
+
+sub DeleteBatch {
+ my $batch_id = shift;
+ return unless defined $batch_id;
+
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare('DELETE FROM import_batches WHERE import_batch_id = ?');
+ $sth->execute( $batch_id );
+}
+
=head2 GetAllImportBatches
my $results = GetAllImportBatches();
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt
@@ -39,6 +39,7 @@
//Cleaned import batch #[% import_batch_id %]
[% END %]
+[% IF ( did_delete ) %]
+
@@ -449,11 +454,17 @@ Page
[% batch_lis.upload_timestamp %] |
[% batch_lis.num_records %] |
[% batch_lis.num_items %][% IF ( batch_lis.num_items ) %] (Create label batch)[% END %] |
-
[% IF ( batch_lis.can_clean ) %]
+ | [% IF ( batch_lis.can_clean ) %]
+ [% ELSIF ( batch_lis.import_status == 'cleaned' ) %]
+
[% END %]
|
--- a/t/db_dependent/ImportBatch.t
+++ a/t/db_dependent/ImportBatch.t
@@ -4,7 +4,7 @@ use Modern::Perl;
use C4::Context;
-use Test::More tests => 7;
+use Test::More tests => 9;
BEGIN {
use_ok('C4::ImportBatch');
@@ -117,3 +117,32 @@ $original_record->delete_fields($original_record->field($item_tag)); #Remove ite
my $record_from_import_biblio_without_items = C4::ImportBatch::GetRecordFromImportBiblio( $import_record_id );
$original_record->leader($record_from_import_biblio_without_items->leader());
is_deeply( $record_from_import_biblio_without_items, $original_record, 'GetRecordFromImportBiblio should return the record without items by default' );
+
+# fresh data
+my $sample_import_batch3 = {
+ matcher_id => 3,
+ template_id => 3,
+ branchcode => 'QRT',
+ overlay_action => 'create_new',
+ nomatch_action => 'create_new',
+ item_action => 'always_add',
+ import_status => 'staged',
+ batch_type => 'z3950',
+ file_name => 'test.mrc',
+ comments => 'test',
+ record_type => 'auth',
+};
+
+my $id_import_batch3 = C4::ImportBatch::AddImportBatch($sample_import_batch3);
+
+# Test CleanBatch
+C4::ImportBatch::CleanBatch( $id_import_batch3 );
+my $batch3_clean = $dbh->do('SELECT * FROM import_records WHERE import_batch_id = "$id_import_batch3"');
+is_deeply( $batch3_clean, "0E0",
+ "Batch 3 has been cleaned" );
+
+# Test DeleteBatch
+C4::ImportBatch::DeleteBatch( $id_import_batch3 );
+my $batch3_results = $dbh->do('SELECT * FROM import_batches WHERE import_batch_id = "$id_import_batch3"');
+is_deeply( $batch3_results, "0E0", # 0E0 == 0
+ "Batch 3 has been deleted");
--- a/tools/manage-marc-import.pl
+++ a/tools/manage-marc-import.pl
@@ -123,6 +123,12 @@ if ($op eq "") {
did_clean => 1,
import_batch_id => $import_batch_id,
);
+} elsif ($op eq "delete-batch") {
+ DeleteBatch($import_batch_id);
+ import_batches_list($template, $offset, $results_per_page);
+ $template->param(
+ did_delete => 1,
+ );
} elsif ($op eq "redo-matching") {
my $new_matcher_id = $input->param('new_matcher_id');
my $current_matcher_id = $input->param('current_matcher_id');
--