Bug 14597: Reverting a batch where a record overlaid is now deleted record will fail
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 23 Jul 2015 16:14:25 +0000 (12:14 -0400)
committerTomas Cohen Arazi <tomascohen@unc.edu.ar>
Mon, 28 Sep 2015 15:20:41 +0000 (12:20 -0300)
If batch of records is used to overlay existing records, and one of
those records is deleted, any attempt to revert this batch will fail.

The unanimous consensus is that deleted records should stay deleted (
 https://lists.katipo.co.nz/public/koha/2015-June/043048.html ).

Test Plan:
1) Import a batch of records
2) Import the same batch again, using ISBN as a matcher for overlay
3) Find a record that overlayed a previous record and delete it
   ( the match type will be "match applied" and there will be a link in
     "match details" )
4) Attempt to revert the second batch ( that overlayed the first )
5) The progress will stop at some point and never complete
6) Apply this patch
7) Attempt to revert the second batch again
8) This time it should succeed!

Signed-off-by: Do, Tam T <tdo@albright.edu>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
C4/ImportBatch.pm

index 29a1f94..9f9c91c 100644 (file)
@@ -28,6 +28,7 @@ use C4::Charset;
 use C4::AuthoritiesMarc;
 use C4::MarcModificationTemplates;
 use Koha::Plugins::Handler;
+use Koha::Logger;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
@@ -812,6 +813,9 @@ sub BatchCommitItems {
 sub BatchRevertRecords {
     my $batch_id = shift;
 
+    my $logger = Koha::Logger->get( { category => 'C4.ImportBatch.BatchRevertRecords' } );
+    $logger->trace("C4::ImportBatch::BatchRevertRecords( $batch_id )");
+
     my $record_type;
     my $num_deleted = 0;
     my $num_errors = 0;
@@ -867,6 +871,10 @@ sub BatchRevertRecords {
             if ($record_type eq 'biblio') {
                 my $biblionumber = $rowref->{'matched_biblionumber'};
                 my $oldbiblio = GetBiblio($biblionumber);
+
+                $logger->info("Biblio record $biblionumber does not exist, restoration of this record was skipped") unless $oldbiblio;
+                next unless $oldbiblio; # Record has since been deleted. Deleted records should stay deleted.
+
                 $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
                 ModBiblio($old_record, $biblionumber, $oldbiblio->{'frameworkcode'});
             } else {