From 87ebf23ea988dc684aa863027c4e6d1e3cd8a0f0 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 10 Aug 2009 00:18:08 -0400 Subject: [PATCH] bug 2157: add ability to 'clean' staged record batches batches, it is now possible to 'clean' a batch by removing all bib and item records staged in the batch. This has the effect of helping to reduce database space used by old import batches as well as removing staged records from the cataloging reservoir search. Note that 'cleaning' a batch affects only the copies of the records that were staged; if the batch was committed, cleaning the batch does not affect any bibs and items that were committed into the catalog. Also note that once you clean a committed batch of records, it is impossible to undo the previous commit operation. Signed-off-by: Galen Charlton Signed-off-by: Henri-Damien LAURENT --- C4/ImportBatch.pm | 24 +++++++++++++++++++ .../en/modules/tools/manage-marc-import.tmpl | 13 ++++++++++ t/lib/KohaTest/ImportBatch.pm | 1 + tools/manage-marc-import.pl | 13 ++++++++-- 4 files changed, 49 insertions(+), 2 deletions(-) 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); -- 2.39.5