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 <tdo@albright.edu>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
This commit is contained in:
Kyle Hall 2015-07-23 12:14:25 -04:00 committed by Tomas Cohen Arazi
parent c57fb17f07
commit 9b0f065392

View 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 {