[Koha-patches] [PATCH] Bug 5724: Handling deleted records better, note this patch changes the reporting level of zebraidx too

Chris Cormack chrisc at catalyst.net.nz
Tue Feb 8 23:21:30 CET 2011


From: Paul Poulain <paul.poulain at biblibre.com>

MT3915: rebuild_zebra changes because deleted biblios would stick in zebra indexes

    Since the update of biblios would be done AFTER the deletion of biblios,
    and since biblios would be updated just before being deleted (in order to delete the items)
    update process would recreate the biblio.

    This patch fixes the order in order to do the deletion AFTER the update.
---
 misc/migration_tools/rebuild_zebra.pl |   27 ++++++++++++---------------
 1 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl
index bd11494..2bdcaa4 100755
--- a/misc/migration_tools/rebuild_zebra.pl
+++ b/misc/migration_tools/rebuild_zebra.pl
@@ -34,7 +34,7 @@ my $as_xml;
 my $process_zebraqueue;
 my $do_not_clear_zebraqueue;
 my $verbose_logging;
-my $zebraidx_log_opt = " -v none,fatal,warn ";
+my $zebraidx_log_opt = " -v none,fatal ";
 my $result = GetOptions(
     'd:s'           => \$directory,
     'reset'         => \$reset,
@@ -65,12 +65,6 @@ if (not $biblios and not $authorities) {
     die $msg;
 }
 
-if ($authorities and $as_xml) {
-    my $msg = "Cannot specify both -a and -x\n";
-    $msg   .= "Please do '$0 --help' to see usage.\n";
-    die $msg;
-}
-
 if ( !$as_xml and $nosanitize ) {
     my $msg = "Cannot specify both -no_xml and -nosanitize\n";
     $msg   .= "Please do '$0 --help' to see usage.\n";
@@ -237,10 +231,10 @@ sub index_records {
     }
 	my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ;
     if ($process_zebraqueue) {
-        do_indexing($record_type, 'delete', "$directory/del_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt) 
-            if $num_records_deleted;
         do_indexing($record_type, 'update', "$directory/upd_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
             if $num_records_exported;
+        do_indexing($record_type, 'delete', "$directory/del_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt) 
+            if $num_records_deleted;
     } else {
         do_indexing($record_type, 'update', "$directory/$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
             if ($num_records_exported or $skip_export);
@@ -424,7 +418,8 @@ sub get_raw_marc_record {
     my $marc; 
     if ($record_type eq 'biblio') {
         if ($noxml) {
-            my $fetch_sth = $dbh->prepare_cached("SELECT marc FROM biblioitems WHERE biblionumber = ?");
+            my $fetch_sth = $dbh->prepare_cached("SELECT marc FROM biblioitems WHERE biblionumber = ?
+                                                  UNION SELECT marc from deletedbiblioitems where biblionumber=?");
             $fetch_sth->execute($record_number);
             if (my ($blob) = $fetch_sth->fetchrow_array) {
                 $marc = MARC::Record->new_from_usmarc($blob);
@@ -435,7 +430,7 @@ sub get_raw_marc_record {
                         # trying to process a record update
             }
         } else {
-            eval { $marc = GetMarcBiblio($record_number); };
+            eval { $marc = GetMarcBiblio($record_number,"include_deleted_table"); };
             if ($@) {
                 # here we do warn since catching an exception
                 # means that the bib was found but failed
@@ -451,7 +446,7 @@ sub get_raw_marc_record {
             return;
         }
     }
-    return $marc;
+        return $marc;
 }
 
 sub fix_leader {
@@ -479,10 +474,11 @@ sub fix_biblio_ids {
     my $biblioitemnumber;
     if (@_) {
         $biblioitemnumber = shift;
-    } else {    
+    } else {
         my $sth = $dbh->prepare(
-            "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
-        $sth->execute($biblionumber);
+            "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?
+             UNION SELECT biblioitemnumber FROM deletedbiblioitems WHERE biblionumber=?");
+        $sth->execute($biblionumber,$biblionumber);
         ($biblioitemnumber) = $sth->fetchrow_array;
         $sth->finish;
         unless ($biblioitemnumber) {
@@ -515,6 +511,7 @@ sub fix_authority_id {
     }
 }
 
+
 sub fix_unimarc_100 {
     # FIXME - again, if this is necessary, it belongs in C4::AuthoritiesMarc.
     my $marc = shift;
-- 
1.7.1



More information about the Koha-patches mailing list