_really_rewrite_record() now checks whether the new ID has changed
authorMike Taylor <mike@indexdata.com>
Mon, 19 Mar 2007 18:52:20 +0000 (18:52 +0000)
committerMike Taylor <mike@indexdata.com>
Mon, 19 Mar 2007 18:52:20 +0000 (18:52 +0000)
from the old, and if so prepares to delete the old record -- but does
not attempt to actually do so, since it seems that Zebra can't service
the request.

lib/ZOOM/IRSpy.pm

index da29f02..0cdb7ed 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: IRSpy.pm,v 1.77 2007-03-15 11:36:58 mike Exp $
+# $Id: IRSpy.pm,v 1.78 2007-03-19 18:52:20 mike Exp $
 
 package ZOOM::IRSpy;
 
 
 package ZOOM::IRSpy;
 
@@ -16,7 +16,7 @@ use Net::Z3950::ZOOM 1.13;    # For the ZOOM version-check only
 use ZOOM::IRSpy::Node;
 use ZOOM::IRSpy::Connection;
 use ZOOM::IRSpy::Stats;
 use ZOOM::IRSpy::Node;
 use ZOOM::IRSpy::Connection;
 use ZOOM::IRSpy::Stats;
-use ZOOM::IRSpy::Utils qw(cql_target render_record);
+use ZOOM::IRSpy::Utils qw(cql_target render_record irspy_xpath_context);
 
 our @ISA = qw();
 our $VERSION = '0.02';
 
 our @ISA = qw();
 our $VERSION = '0.02';
@@ -242,7 +242,7 @@ sub _rewrite_record {
 
 
 sub _really_rewrite_record {
 
 
 sub _really_rewrite_record {
-    my($conn, $rec) = @_;
+    my($conn, $rec, $oldid) = @_;
 
     my $p = $conn->package();
     $p->option(action => "specialUpdate");
 
     my $p = $conn->package();
     $p->option(action => "specialUpdate");
@@ -251,6 +251,22 @@ sub _really_rewrite_record {
     $p->send("update");
     $p->destroy();
 
     $p->send("update");
     $p->destroy();
 
+    # This is the expression in the ID-making stylesheet
+    # ../../zebra/zeerex2id.xsl
+    my $xc = irspy_xpath_context($rec);
+    my $id = $xc->find("concat(e:serverInfo/e:host, ':',
+                               e:serverInfo/e:port, '/',
+                               e:serverInfo/e:database)");
+    if (0 && $id ne $oldid) {
+       # Delete old record;
+       warn "IDs differ (old='$oldid' new='$id')";
+       my $p = $conn->package();
+       $p->option(action => "recordDelete");
+       $p->option(recordIdOpaque => $oldid);
+       $p->send("update");
+       $p->destroy();
+    }
+
     $p = $conn->package();
     $p->send("commit");
     $p->destroy();
     $p = $conn->package();
     $p->send("commit");
     $p->destroy();