No subject


Wed May 27 13:54:03 CEST 2009


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.
---
 C4/ImportBatch.pm                                  |   24 ++++++++++++++++++++
 .../prog/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 a8bd2cb..d0bfc72 100644
--- a/C4/ImportBatch.pm
+++ b/C4/ImportBatch.pm
@@ -45,6 +45,7 @@ BEGIN {
     BatchFindBibDuplicates
     BatchCommitBibRecords
     BatchRevertBibRecords
+    CleanBatch
 
     GetAllImportBatches
     GetImportBatchRangeDesc
@@ -700,6 +701,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 b3cda3a..9330775 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 @@
 </div>
 <!-- /TMPL_IF -->
 
+<!-- TMPL_IF name="did_clean" -->
+  <div class="dialog message">Cleaned import batch #<!-- TMPL_VAR name="import_batch_id" --></div>
+<!-- /TMPL_IF -->
+
 <!-- TMPL_UNLESS name="batch_list" -->
    <!-- TMPL_UNLESS name="batch_info" -->
      <span class="problem">No records have been staged.</span>
@@ -196,6 +200,7 @@ Page
     <th>Staged</th>
     <th># Bibs</th>
     <th># Items</th>
+    <th>Action</th>
   </tr>
   <!-- TMPL_LOOP name="batch_list" -->
   <tr>
@@ -206,6 +211,14 @@ Page
     <td><!-- TMPL_VAR name="upload_timestamp" --></td>
     <td><!-- TMPL_VAR name="num_biblios" --></td>
     <td><!-- TMPL_VAR name="num_items" --><!-- TMPL_IF NAME="num_items" --> <a href="<!-- TMPL_VAR name="script_name" -->?import_batch_id=<!-- TMPL_VAR name="import_batch_id" -->&amp;op=create_labels">(Create Label Batch)</a><!-- /TMPL_IF --></td>
+    <td><!-- TMPL_IF name="can_clean" -->
+          <form method="POST" action="<!-- TMPL_VAR name="script_name" -->" name="clean_batch_<!-- TMPL_VAR name='import_batch_id'-->" id="clean_batch_<!-- TMPL_VAR name='import_batch_id'-->" >
+            <input type="hidden" name="import_batch_id" value="<!-- TMPL_VAR name="import_batch_id" -->" />
+            <input type="hidden" name="op" value="clean-batch" />
+            <input type="submit" class="button" value="Clean" onclick="return confirm(_('Clear all reservoir records staged in this batch?  This cannot be undone.'));" />
+          </form>
+        <!-- /TMPL_IF -->
+    </td>
   </tr>
   <!-- /TMPL_LOOP -->
 </table>
diff --git a/t/lib/KohaTest/ImportBatch.pm b/t/lib/KohaTest/ImportBatch.pm
index 35f2b2e..a8fefaa 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 c9946f3..43fed13 100755
--- a/tools/manage-marc-import.pl
+++ b/tools/manage-marc-import.pl
@@ -95,7 +95,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');
@@ -179,7 +184,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); 
@@ -373,6 +379,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);
-- 
1.5.6.5



More information about the Koha-patches mailing list