koha-cvs
[Top][All Lists]
Advanced

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

[Koha-cvs] koha/misc update_items.pl [dev_week]


From: Joshua Ferraro
Subject: [Koha-cvs] koha/misc update_items.pl [dev_week]
Date: Mon, 23 Oct 2006 14:30:09 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         dev_week
Changes by:     Joshua Ferraro <kados>  06/10/23 14:30:09

Modified files:
        misc           : update_items.pl 

Log message:
        adds an -all parameter to reindex the whole set as well as -today which 
only
        indexes the todays changes. You can also specify -biblionumber 9999 to 
just
        update the index for one biblionumber.

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

Patches:
Index: update_items.pl
===================================================================
RCS file: /sources/koha/koha/misc/Attic/update_items.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
--- update_items.pl     11 Oct 2006 13:51:48 -0000      1.1.2.2
+++ update_items.pl     23 Oct 2006 14:30:09 -0000      1.1.2.3
@@ -2,6 +2,7 @@
 use strict;
 use warnings;
 use C4::Context;
+use C4::Biblio;
 use MARC::Record;
 
 use Getopt::Long;
@@ -9,6 +10,7 @@
 USAGE: update_items.pl -[options]
 
 OPTIONS:
+ -all                                          Update all records and items
  -today                                Items with a modified timestamp today
  -biblionumber <integer>       One biblionumber to update
  -itemnumber <integer>         One itemnumber to update
@@ -22,8 +24,9 @@
 \$ ./update_items.pl -biblionumber 2
 [ update items for biblionumber 2 ]
 ";
-my ($today_only,$biblionumber_to_update,$itemnumber_to_update);
+my ($all,$today_only,$biblionumber_to_update,$itemnumber_to_update);
 GetOptions(
+       'all' => \$all,
        'today' => \$today_only,
        'biblionumber:o' => \$biblionumber_to_update,
        'itemnumber:o' => \$itemnumber_to_update
@@ -40,14 +43,15 @@
 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
 $year +=1900;
 $mon +=1;
+
 # nice to zero-pad these dates
 my $pad_mday= sprintf("%0*d", "2",$mday);
 my $pad_mon = sprintf("%0*d", "2",$mon);
 
 # FIXME: we should define a syspref for 'how often to run this script'
 my $period = "$year-$pad_mon-$pad_mday%"; # today only - you'll want to 
customize this bit
-print "period: $period\n";
-my $date = "$year$mon$mday$hour$min$sec";
+print "period: $period\n" if $today_only;
+my $date = "$year-$mon-$mday-$hour$min$sec";
 
 # This is the file that zebra will use to update the index at the end of this 
script
 my $filename = "records.$date.iso2709";
@@ -68,11 +72,16 @@
 # get all the relevant biblionumbers, we're gonna update every item in these 
biblionumbers
 print "finding biblionumbers\n";
 my $biblionumber_sth;
-if ($today_only) {
+if ($all) {
+       $biblionumber_sth = $dbh->prepare("SELECT DISTINCT biblionumber from 
biblioitems WHERE marc IS NOT NULL");
+       $biblionumber_sth->execute() or die "problem with query\n";
+}
+elsif ($today_only) {
        $biblionumber_sth = $dbh->prepare("SELECT DISTINCT 
biblioitems.biblionumber FROM biblioitems LEFT JOIN items ON 
(biblioitems.biblionumber=items.biblionumber) WHERE items.timestamp LIKE ? AND 
biblioitems.marc IS NOT NULL");
        $biblionumber_sth->execute($period) or die "problem with query\n";
 }
 elsif ($biblionumber_to_update) {
+       warn "biblio : $biblionumber_to_update\n";
        $biblionumber_sth = $dbh->prepare("SELECT biblionumber FROM biblioitems 
WHERE marc IS NOT NULL AND biblionumber=?");
        $biblionumber_sth->execute($biblionumber_to_update) or die "problem 
with query\n";
 }
@@ -81,7 +90,7 @@
 print "fetching marc and items data, updating\n";
 # for each itemnumber, find the biblionumber, get all the items data for that 
biblio,
 # update all the items data in biblioitems.marc, and finally, index it in zebra
-while (my $biblionumber=$biblionumber_sth->fetchrow) {
+while (my $biblionumber=$biblionumber_sth->fetchrow()) {
        $count++;
 
        # get this biblio's MARC record
@@ -90,12 +99,46 @@
 
        # FIXME: we need better error handling here
        # transform this data into a MARC::Record object
-       my $record = MARC::Record->new_from_usmarc($marc_sth->fetchrow());
+       my $record;
+
+       eval {
+               $record = MARC::Record->new_from_usmarc($marc_sth->fetchrow());
+       };
+       if ($@) {
+               warn "problem with record #$count, biblionumber $biblionumber";
+               next;
+       }
+       my ($tagfield,$biblionumtagsubfield) = 
&MARCfind_marc_from_kohafield($dbh,"biblio.biblionumber","");
+       my @tags = $record->field($tagfield);
+       my $problem = 0;
+       if (@tags) {
+        my $subfield = 
$record->field($tagfield)->subfield($biblionumtagsubfield);
+        if ($subfield) {        
+                       # we're golden :-)
+               }
+       # has the tag, but not the subfield
+               else {
+                       $problem = 1;
+               }
+       }
+       else {
+               $problem=1;
+       }
+    my @warnings = $record->warnings();
+    if ((@warnings) || ($problem)) {
+       warn "missing tag or subfield for biblionumber, skipping biblionumber 
$biblionumber\n" if $problem;
+        foreach my $warn(@warnings) {
+            warn "warning:".$warn;
+        }
+               warn "problems: skipping biblionumber $biblionumber\n";
+               next;
+
+    }
 
        # delete all existing items data from this record FIXME: 952 shouldn't 
be hardcoded
        for my $field_to_del ($record->field("952")) {
                my $del_count = $record->delete_field($field_to_del);
-               print "deleted $del_count fields";
+               #print "deleted $del_count fields";
        }
        # Find out the itemnumbers this biblio has
        my $itemnumbers_sth = $dbh->prepare("SELECT itemnumber FROM items WHERE 
biblionumber=?");
@@ -125,12 +168,12 @@
                                my ($tag,$subfield) = 
$find_tag_subfield_sth->fetchrow;
                                if ($tag) {
                                        $items_field->add_subfields($subfield 
=> $item_data_hashref->{$label} ) unless (!$item_data_hashref->{$label});
-                                       print "added: $label ($tag $subfield): 
$item_data_hashref->{$label}";
+                                       #print "added: $label ($tag $subfield): 
$item_data_hashref->{$label}";
                                }
                                else {
                                        # You probably want to update your 
mappings if you see anything here ... but
                                        # in some cases it's safe to ignore 
these warnings
-                                       print "WARN: no items.$label mapping 
found: $item_data_hashref->{$label}\n";
+                                       #print "WARN: no items.$label mapping 
found: $item_data_hashref->{$label}\n";
                                }
                        }
                }
@@ -150,7 +193,13 @@
 # now we're ready to index this change in Zebra and commit it
 # FIXME: these dirs shouldn't be hardcoded and sudo probably isn't what you use
 chdir "/koha/zebradb/biblios/tab";
-my $error = system("sudo zebraidx -g iso2709 -c /koha/etc/zebra-biblios.cfg -d 
biblios update $outfile");
+my $error;
+# warning, this will stop all searches
+$error = system("zebraidx -g iso2709 -c /koha/etc/zebra-biblios.cfg -d biblios 
init") if $all;
+if ($error) {
+       die "init operation failed";
+}
+$error = system("zebraidx -g iso2709 -c /koha/etc/zebra-biblios.cfg -d biblios 
update $outfile");
 if ($error) {
        die "update operation failed";
 }




reply via email to

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