From 3e6e92ad6621fb0fb470bbfd67434000396bf604 Mon Sep 17 00:00:00 2001 From: Aleisha Date: Tue, 29 Mar 2016 00:04:36 +0000 Subject: [PATCH] Bug 9259: Ability to delete a staged file once it has been cleaned MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit To test: 1) Go to Tools -> Staged MARC Management and clean a file. If you have no files to clean, go to 'Stage MARC for import' and upload one to clean following the necessary steps. 2) Confirm that once the file has been cleaned, the Action column now shows a Delete button. Confirm this button only shows for cleaned files. 3) Click the Delete button. 4) Confirm that clicking Cancel exits the pop-up message and does not delete the file. 5) Confirm that clicking OK refreshes the list of staged records and the one you just deleted is no longer on it (has been deleted). You can confirm this by checking for the file in mysql (SELECT * FROM import_batches WHERE import_batch_id = X;) 6) Run prove -v t/db_dependent/ImportBatch.t (have written unit tests for CleanBatch and DeleteBatch) Sponsored-by: Catalyst IT Signed-off-by: Liz Rea Catalyst sign off, so needs another one but YAY this is great. Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall (cherry picked from commit 08e448ee4bfbd7a85dfbfd6d0d77f8d59dd93b8e) Signed-off-by: Frédéric Demians --- C4/ImportBatch.pm | 19 ++++++++++++ .../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(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 1d387e138b..4d63e8d3fe 100644 --- a/C4/ImportBatch.pm +++ b/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(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt index 3a786e9edf..e6bf9501f5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt +++ b/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 ) %] +
Import batch deleted successfully
+[% END %] + [% UNLESS ( batch_list ) %] [% UNLESS ( batch_info ) %]
@@ -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 %] diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t index 661cd339d1..8cb84cedd3 100644 --- a/t/db_dependent/ImportBatch.t +++ b/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"); diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl index b0d4f8886f..83abc91513 100755 --- a/tools/manage-marc-import.pl +++ b/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'); -- 2.39.5