From a3f084cdc730ca062d6a69f7f2d99e54407bdb19 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 23 Jul 2015 12:14:25 -0400 Subject: [PATCH] [SIGNED-OFF] 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 --- C4/ImportBatch.pm | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) 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 { -- 1.7.2.5