From 5c882558a429dd994abdef7d036b40d56f4a5cf4 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 12 Nov 2007 17:13:45 -0600 Subject: [PATCH] bugfixes for reindexing problems * now properly deletes deleted authorities from index * now actually ignores duplicate work * standardized on recordDelete instead of delete_record for bibs and recordDelete for authorities Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Biblio.pm | 2 +- misc/cronjobs/zebraqueue_start.pl | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index c655cbf7ae..bcc2409c60 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -563,7 +563,7 @@ sub DelBiblio { # - we need to read the biblio if NoZebra is set (to remove it from the indexes # - if something goes wrong, the biblio may be deleted from Koha but not from zebra # and we would have no way to remove it (except manually in zebra, but I bet it would be very hard to handle the problem) - ModZebra($biblionumber, "delete_record", "biblioserver", undef); + ModZebra($biblionumber, "recordDelete", "biblioserver", undef); # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems $sth = diff --git a/misc/cronjobs/zebraqueue_start.pl b/misc/cronjobs/zebraqueue_start.pl index 5d4046324e..b79aeaaa45 100755 --- a/misc/cronjobs/zebraqueue_start.pl +++ b/misc/cronjobs/zebraqueue_start.pl @@ -13,7 +13,12 @@ use utf8; ### ZEBRA SERVER UPDATER ##Uses its own database handle my $dbh=C4::Context->dbh; -my $readsth=$dbh->prepare("SELECT id,biblio_auth_number,operation,server FROM zebraqueue WHERE done=0"); +my $readsth=$dbh->prepare("SELECT id,biblio_auth_number,operation,server FROM zebraqueue WHERE done=0 + ORDER BY id DESC"); # NOTE - going in reverse order to catch deletes that + # occur after a string of updates (e.g., user deletes + # the items attached to a bib, then the items. + # Having a specialUpdate occur after a recordDelete + # should not occur. #my $delsth=$dbh->prepare("delete from zebraqueue where id =?"); @@ -33,7 +38,10 @@ while (($id,$biblionumber,$operation,$server)=$readsth->fetchrow){ # if the operation is a deletion, zebra requires that we give it the xml. # as it is no more in the SQL db, retrieve it from zebra itself. # may sound silly, but that's the way zebra works ;-) - if ($operation =~ /delete/) { + if ($operation =~ /delete/i) { # NOTE depending on version, delete operation + # was coded 'delete_record' or 'recordDelete'. + # 'recordDelete' is the preferred one, as that's + # what the ZOOM API wants. # 1st read the record in zebra my $Zconn=C4::Context->Zconn($server, 0, 1,'','xml'); my $query = $Zconn->search_pqf( '@attr 1=Local-Number '.$biblionumber); @@ -80,10 +88,12 @@ while (($id,$biblionumber,$operation,$server)=$readsth->fetchrow){ # did a modif (or item deletion) just before biblio deletion, there are some specialUpdage # that are pending and can't succeed, as we don't have the XML anymore # so, delete everything for this biblionumber - if ($operation eq 'delete_record') { + my $reset_readsth = 0; + if ($operation eq 'recordDelete') { print "deleting biblio deletion $biblionumber\n" if $verbose; $delsth =$dbh->prepare("UPDATE zebraqueue SET done=1 WHERE biblio_auth_number =?"); $delsth->execute($biblionumber); + $reset_readsth = 1 if $delsth->rows() > 0; # if it's not a deletion, delete every pending specialUpdate for this biblionumber # in case the user add biblio, then X items, before this script runs # this avoid indexing X+1 times where just 1 is enough. @@ -91,6 +101,13 @@ while (($id,$biblionumber,$operation,$server)=$readsth->fetchrow){ print "deleting special date for $biblionumber\n" if $verbose; $delsth =$dbh->prepare("UPDATE zebraqueue SET done=1 WHERE biblio_auth_number =? and operation='specialUpdate'"); $delsth->execute($biblionumber); + $reset_readsth = 1 if $delsth->rows() > 0; + } + if ($reset_readsth) { + # if we can ignore rows in zebraqueue because we've already + # touched a record, reset the query. + $readsth->finish(); + $readsth->execute(); } } } -- 2.39.2