@@ -, +, @@ --- C4/Breeding.pm | 7 ++++--- C4/ImportBatch.pm | 6 ++++++ acqui/z3950_search.pl | 32 ++++++++++++++++++++++++++++++-- cataloguing/z3950_search.pl | 30 +++++++++++++++++++++++++++++- 4 files changed, 69 insertions(+), 6 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; @@ -137,7 +138,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++; @@ -145,7 +146,7 @@ sub ImportBreeding { } } } - return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid); + return ( $notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid, $batch_id ); } --- a/C4/ImportBatch.pm +++ a/C4/ImportBatch.pm @@ -73,6 +73,8 @@ BEGIN { SetImportRecordStatus GetImportRecordMatches SetImportRecordMatches + + UpdateBatchRecordCounts ); } @@ -1310,6 +1312,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) = @_; --- a/acqui/z3950_search.pl +++ a/acqui/z3950_search.pl @@ -32,6 +32,7 @@ use C4::Koha; use C4::Charset; use C4::Bookseller qw/ GetBookSellerFromId /; use ZOOM; +use List::MoreUtils qw(uniq); my $input = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -230,6 +231,7 @@ warn "query ".$query if $DEBUG; warn "# nremaining = $nremaining\n" if $DEBUG; + my @batch_id; while ( $nremaining-- ) { my $k; @@ -289,9 +291,13 @@ warn "query ".$query if $DEBUG; $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn}; my ( $notmarcrecord, $alreadyindb, $alreadyinfarm, - $imported, $breedingid + $imported, $breedingid, $batch_id ) - = ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' ); + = 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}; @@ -320,4 +326,26 @@ breeding_loop => \@breeding_loop, numberpending => $nremaining > 0 ? $nremaining : 0, 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) { + C4::ImportBatch::UpdateBatchRecordCounts::UpdateBatchRecordCounts($bid); + } + + exit; +} + output_html_with_http_headers $input, $cookie, $template->output; --- a/cataloguing/z3950_search.pl +++ a/cataloguing/z3950_search.pl @@ -30,6 +30,8 @@ use C4::Context; use C4::Breeding; use C4::Koha; use C4::Charset; +use List::MoreUtils qw(uniq); + use ZOOM; my $input = new CGI; @@ -70,6 +72,7 @@ my @serverloop = (); my @serverhost; my @servername; my @breeding_loop = (); +my @batch_id; my ( $start_run, $end_run ); @@ -287,10 +290,14 @@ else { $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn}; my ( $notmarcrecord, $alreadyindb, $alreadyinfarm, - $imported, $breedingid + $imported, $breedingid, $batch_id, ) = ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' ); + + # 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}; @@ -329,6 +336,27 @@ else { 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) { + C4::ImportBatch::UpdateBatchRecordCounts($bid); + } + + exit; + } + if ( $numberpending == 0 ) { $end_run = time(); $template->param( run_time => $end_run - $start_run ); --