@@ -, +, @@ --- C4/Breeding.pm | 35 +++++++++++++++++++++++++++++++---- C4/ImportBatch.pm | 6 ++++++ 2 files changed, 37 insertions(+), 4 deletions(-) --- a/C4/Breeding.pm +++ a/C4/Breeding.pm @@ -25,6 +25,7 @@ use C4::Koha; use C4::Charset; use MARC::File::USMARC; use C4::ImportBatch; +use List::MoreUtils qw(uniq); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -71,7 +72,7 @@ C4::Breeding : module to add biblios to import_records via =cut sub ImportBreeding { - my ($marcrecords,$overwrite_biblio,$filename,$encoding,$z3950random,$batch_type) = @_; + my ( $marcrecords, $overwrite_biblio, $filename, $encoding, $z3950random, $batch_type, $update_counts ) = @_; my @marcarray = split /\x1D/, $marcrecords; my $dbh = C4::Context->dbh; @@ -140,7 +141,7 @@ sub ImportBreeding { if ($breedingid && $overwrite_biblio eq '1') { ModBiblioInBatch($breedingid, $marcrecord); } else { - my $import_id = AddBiblioToBatch($batch_id, $imported, $marcrecord, $encoding, $z3950random); + my $import_id = AddBiblioToBatch($batch_id, $imported, $marcrecord, $encoding, $z3950random, $update_counts); $breedingid = $import_id; } $imported++; @@ -148,7 +149,7 @@ sub ImportBreeding { } } } - return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid); + return ( $notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid, $batch_id ); } @@ -341,6 +342,7 @@ sub Z3950Search { $oResult[$z] = $oConnection[$z]->search_pqf($query); } + my @batch_id; while ( $nremaining-- ) { my $k; my $event; @@ -382,7 +384,13 @@ sub Z3950Search { # pad | and ( with spaces to allow line breaks in the HTML $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn}; $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn}; - my ($notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid)= ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' ); + + my ( $notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid, $batch_id ) = + ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950', 0 ); + + # Delay the updating of batch record counts until the very end + push( @batch_id, $batch_id ); + my %row_data; $row_data{server} = $servername[$k]; $row_data{isbn} = $oldbiblio->{isbn}; @@ -427,6 +435,25 @@ sub Z3950Search { servers => \@servers, errconn => \@errconn ); + + # Process the delayed batch record count updates + my $pid; + if ( $pid = fork ) { + # Parent, continue on as usual + + # prevent parent exiting from + # destroying the kid's database handle + # FIXME: according to DBI doc, this may not work for Oracle + $dbh->{InactiveDestroy} = 1; + } else { + close STDOUT; + close STDERR; + + @batch_id = uniq(@batch_id); + foreach my $bid (@batch_id) { + UpdateBatchRecordCounts($bid); + } + } } 1; --- a/C4/ImportBatch.pm +++ a/C4/ImportBatch.pm @@ -76,6 +76,8 @@ BEGIN { SetImportRecordStatus GetImportRecordMatches SetImportRecordMatches + + UpdateBatchRecordCounts ); } @@ -1446,6 +1448,10 @@ sub _update_batch_record_counts { $sth->finish(); } +sub UpdateBatchRecordCounts { + return _update_batch_record_counts( @_ ); +} + sub _get_commit_action { my ($overlay_action, $nomatch_action, $item_action, $overlay_status, $import_record_id, $record_type) = @_; --