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 <gmcharlt@gmail.com>
This commit is contained in:
Galen Charlton 2009-08-10 00:18:08 -04:00
parent f202faba18
commit ae5b76c89b
4 changed files with 49 additions and 2 deletions

View file

@ -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

View file

@ -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>

View file

@ -27,6 +27,7 @@ sub routines : Test( 1 ) {
BatchCommitItems
BatchRevertBibRecords
BatchRevertItems
CleanBatch
GetAllImportBatches
GetImportBatchRangeDesc
GetItemNumbersFromImportBatch

View file

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