koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/misc/cronjobs zebraqueue_start.pl [rel_3_0]


From: paul poulain
Subject: [Koha-cvs] koha/misc/cronjobs zebraqueue_start.pl [rel_3_0]
Date: Wed, 17 Jan 2007 11:42:39 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         rel_3_0
Changes by:     paul poulain <tipaul>   07/01/17 11:42:39

Modified files:
        misc/cronjobs  : zebraqueue_start.pl 

Log message:
        updating zebraqueue_start to :
        - make biblio deletion work (we must choose between recordIdOpaque or 
"internal" record ID. we have choosen "internal", so recordIdOpaque don't work 
for us.
        - remove daemon behaviour : it's better to put the script in a crontab 
: this avoid problems if the script fails.
        - improve zebraqueue table deletion to avoid having forever pending 
specialUpdate that occurs just before a deletion, and can't be run (as the 
biblioitems.marcxml don't exist anymore)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/misc/cronjobs/zebraqueue_start.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.2&r2=1.1.2.3

Patches:
Index: zebraqueue_start.pl
===================================================================
RCS file: /sources/koha/koha/misc/cronjobs/Attic/zebraqueue_start.pl,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- zebraqueue_start.pl 16 Jan 2007 08:50:20 -0000      1.1.2.2
+++ zebraqueue_start.pl 17 Jan 2007 11:42:39 -0000      1.1.2.3
@@ -6,6 +6,7 @@
 
 use C4::Context;
 use C4::Biblio;
+use C4::Search;
 use C4::AuthoritiesMarc;
 use XML::Simple;
 use utf8;
@@ -13,19 +14,34 @@
 ##Uses its own database handle
 my $dbh=C4::Context->dbh;
 my $readsth=$dbh->prepare("select id,biblio_auth_number,operation,server from 
zebraqueue");
-my $delsth=$dbh->prepare("delete from zebraqueue where id =?");
+#my $delsth=$dbh->prepare("delete from zebraqueue where id =?");
 
 
 #AGAIN:
 
 #my $wait=C4::Context->preference('zebrawait') || 120;
-my $verbose = 0;
+my $verbose = 1;
+print "starting with verbose=$verbose\n" if $verbose;
 
 my ($id,$biblionumber,$operation,$server,$marcxml);
 
 $readsth->execute;
 while (($id,$biblionumber,$operation,$server)=$readsth->fetchrow){
     print "read in queue : $id : biblio $biblionumber for $operation on 
$server\n" if $verbose;
+    my $ok;
+    eval{
+        # 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/) {
+              # 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);
+            # then, delete the record
+               
$ok=zebrado($query->record(0)->render(),$operation,$server,$biblionumber);
+        # if it's an add or a modif
+        } else {
+            # get the XML
     if ($server eq "biblioserver") {
         my $marc =GetMarcBiblio($biblionumber);
         $marcxml = $marc->as_xml_record() if $marc;
@@ -34,34 +50,51 @@
     }
     if ($verbose) {
         if ($marcxml) {
-            print "XML read : $marcxml\n" if $verbose;
+                    print "XML read : $marcxml\n" if $verbose >1;
         } else {
+                # workaround for zebra bug needing a XML even for deletion
+                $marcxml= "<dummy/>";
             print "unable to read MARCxml\n" if $verbose;
         }
     }
-    
+            # check it's XML, just in case
     eval {
         my $hashed=XMLin($marcxml);
     }; ### is it a proper xml? broken xml may crash ZEBRA- slow but safe
-    
+            ## it's Broken XML-- Should not reach here-- but if it does -lets 
protect ZEBRA
     if ($@){
         warn $@;
-        ## Broken XML-- Should not reach here-- but if it does -lets protect 
ZEBRA
+                my $delsth=$dbh->prepare("delete from zebraqueue where id =?");
         $delsth->execute($id);
         next;
     }
-    my $ok;
-    eval{
+            # ok, we have everything, do the operation in zebra !
         $ok=zebrado($marcxml,$operation,$server);
+        }
     };
     print "ZEBRAopserver returned : $ok \n" if $verbose;
-    $delsth->execute($id) if ($ok==1);
+    if (0 && $ok ==1) {
+        $dbh=C4::Context->dbh;
+        my $delsth;
+        # if it's a deletion, we can delete every request on this biblio : in 
case the user
+        # 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') {
+            print "deleting biblio deletion $biblionumber\n" if $verbose;
+            $delsth =$dbh->prepare("delete from zebraqueue where 
biblio_auth_number =?");
+            $delsth->execute($biblionumber);
+        # 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.
+        } else {
+            print "deleting special date for $biblionumber\n" if $verbose;
+            $delsth =$dbh->prepare("delete from zebraqueue where 
biblio_auth_number =? and operation='specialUpdate'");
+            $delsth->execute($biblionumber);
+        }
+    }
 }
 
-#print "sleeping for $wait seconds now\n" if $verbose;
-#sleep $wait;
-#goto AGAIN;
-
 sub zebrado {
     
     ###Accepts a $server variable thus we can use it to update  biblios, 
authorities or other zebra dbs
@@ -74,15 +107,16 @@
     my $reconnect=0;
 #     $record=Encode::encode("UTF-8",$record);
     my $shadow=$server."shadow";
+    $op = 'recordDelete' if $op eq 'delete_record';
 reconnect:
     
     my $Zconn=C4::Context->Zconn($server, 0, 1);
     if ($record){
-        print "updating\n" if $verbose;
+        print "updating $op on $biblionumber for server $server\n $record\n" 
if $verbose;
         my $Zpackage = $Zconn->package();
         $Zpackage->option(action => $op);
         $Zpackage->option(record => $record);
-        $Zpackage->option(recordIdOpaque => $biblionumber);
+#          $Zpackage->option(recordIdOpaque => $biblionumber) if $biblionumber;
 retry:
         $Zpackage->send("update");
         my($error, $errmsg, $addinfo, $diagset) = $Zconn->error_x();
@@ -113,7 +147,6 @@
         $Zpackage->send('commit');
 #     $Zpackage->destroy();
 #     $Zconn->destroy();
-    print "HERE\n" if $verbose;
     return 1;
     }
     return 0;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]