From 38e1dd9b1fcd7c9e961ce1031453db5df916d267 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 23 Jul 2015 12:14:25 -0400 Subject: [PATCH] Bug 14597 - Reverting a batch where a record overlaid is now deleted record will fail 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 Signed-off-by: Jonathan Druart --- C4/ImportBatch.pm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 29a1f94..9f9c91c 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -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 { -- 2.1.0