Bug 9259: Ability to delete a staged file once it has been cleaned

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 <liz@catalyst.net.nz>
Catalyst sign off, so needs another one but YAY this is great.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Aleisha 2016-03-29 00:04:36 +00:00 committed by Kyle M Hall
parent 46b7d5e4c6
commit 08e448ee4b
4 changed files with 68 additions and 3 deletions

View file

@ -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();

View file

@ -39,6 +39,7 @@
//<![CDATA[
var MSG_CONFIRM_CLEAN = _("Clear all reservoir records staged in this batch? This cannot be undone.");
var MSG_CONFIRM_UNDO_IMPORT = _("Are you sure you want to undo the import of this batch into the catalog?");
var MSG_CONFIRM_DELETE = _("Are you sure you want to permanently delete this batch?");
$(document).ready(function(){
$("#staged-record-matching-rules select").change(function(){
@ -195,6 +196,10 @@ $(document).ready(function(){
<div class="dialog message">Cleaned import batch #[% import_batch_id %]</div>
[% END %]
[% IF ( did_delete ) %]
<div class="dialog message">Import batch deleted successfully</div>
[% END %]
[% UNLESS ( batch_list ) %]
[% UNLESS ( batch_info ) %]
<div class="dialog message">
@ -449,11 +454,17 @@ Page
<td>[% batch_lis.upload_timestamp %]</td>
<td>[% batch_lis.num_records %]</td>
<td>[% batch_lis.num_items %][% IF ( batch_lis.num_items ) %] <a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]&amp;op=create_labels">(Create label batch)</a>[% END %]</td>
<td>[% IF ( batch_lis.can_clean ) %]
<td class="actions">[% IF ( batch_lis.can_clean ) %]
<form method="post" action="[% batch_lis.script_name %]" name="clean_batch_[% batch_lis.import_batch_id %]" id="clean_batch_[% batch_lis.import_batch_id %]" >
<input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id %]" />
<input type="hidden" name="op" value="clean-batch" />
<button class="btn btn-small" onclick="return confirm(MSG_CONFIRM_CLEAN);">Clean</button>
<button class="btn btn-mini" onclick="return confirm(MSG_CONFIRM_CLEAN);"><i class="fa fa-eraser"></i> Clean</button>
</form>
[% ELSIF ( batch_lis.import_status == 'cleaned' ) %]
<form method="post" action="/cgi-bin/koha/tools/manage-marc-import.pl" name="delete_batch_[% batch_lis.import_batch_id %]" id="delete_batch_[% batch_lis.import_batch_id %]">
<input type="hidden" name="import_batch_id" value="[% batch_lis.import_batch_id %]" />
<input type="hidden" name="op" value="delete-batch" />
<button class="btn btn-mini" onclick="return confirm(MSG_CONFIRM_DELETE);"><i class="fa fa-trash"></i> Delete</button>
</form>
[% END %]
</td>

View file

@ -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");

View file

@ -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');