[Koha-cvs] koha/misc/migration_tools rebuild_zebra.pl [rel_3_0]

paul poulain paul at koha-fr.org
Wed Nov 15 15:48:06 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	paul poulain <tipaul>	06/11/15 14:48:06

Modified files:
	misc/migration_tools: rebuild_zebra.pl 

Log message:
	updating rebuild_zebra :
	- adding missing090.pl feature in the script
	- fixing zebra2.0 missing directive in .cfg
	
	still to do :
	- some unimarc/french tweaking (bib1_unimarc.att)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/misc/migration_tools/rebuild_zebra.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.4.2.1&r2=1.4.2.2

Patches:
Index: rebuild_zebra.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/rebuild_zebra.pl,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -u -b -r1.4.2.1 -r1.4.2.2
--- rebuild_zebra.pl	24 Oct 2006 12:31:57 -0000	1.4.2.1
+++ rebuild_zebra.pl	15 Nov 2006 14:48:06 -0000	1.4.2.2
@@ -11,11 +11,20 @@
 
 $|=1; # flushes output
 
-print "Zebra directory =>".C4::Context->zebraconfig('biblioserver')->{directory}."\n";
-print "Koha directory =>".C4::Context->config('intranetdir')."\n";
 
 my $zebradir = C4::Context->zebraconfig('biblioserver')->{directory};
 my $kohadir = C4::Context->config('intranetdir');
+my ($biblionumbertagfield,$biblionumbertagsubfield) = &MARCfind_marc_from_kohafield($dbh,"biblio.biblionumber","");
+my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &MARCfind_marc_from_kohafield($dbh,"biblioitems.biblioitemnumber","");
+
+print "some informations\n";
+print "=================\n";
+print "Zebra directory =>$zebradir\n";
+print "Koha directory =>$kohadir\n";
+print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n";
+print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
+print "=================\n";
+
 my $directory;
 my $skip_export;
 my $keep_export;
@@ -127,11 +136,12 @@
 attset: explain.att
 attset:gils.att
 
+modulePath:/usr/local/lib/idzebra-2.0/modules/
 systag sysno rank
 # Specify record type
 iso2709.recordType:grs.marcxml.record
 recordType:grs.xml
-recordId: (bib1,Identifier-standard)
+recordId: (bib1,Local-Number)
 storeKeys:1
 storeData:1
 
@@ -180,11 +190,46 @@
     open(OUT,">:utf8","$directory/export") or die $!;
     my $dbh=C4::Context->dbh;
     my $sth;
-    $sth=$dbh->prepare("select biblionumber from biblioitems where biblionumber <1000 order by biblionumber");
+    $sth=$dbh->prepare("select biblionumber from biblioitems where biblionumber <2000 order by biblionumber");
     $sth->execute();
     my $i=0;
     while (my ($biblionumber) = $sth->fetchrow) {
         my $record = MARCgetbiblio($dbh,$biblionumber);
+        # check that biblionumber & biblioitemnumber are stored in the MARC record, otherwise, add them & update the biblioitems.marcxml data.
+        my $record_correct=1;
+        unless ($record->subfield($biblionumbertagfield,$biblionumbertagsubfield)) {
+            $record_correct=0;
+#             warn "INCORRECT BIBLIONUMBER :".$record->as_formatted;
+            my $field;
+            # if the field where biblionumber is already exist, just update it, otherwise create it
+            if ($record->field($biblionumbertagfield)) {
+                $field =  $record->field($biblionumbertagfield);
+                $field->add_subfields($biblionumbertagsubfield => $biblionumber);
+            } else {
+                my $newfield = MARC::Field->new( $biblionumbertagfield,'','', $biblionumbertagsubfield => $biblionumber);
+                $record->append_fields($newfield);
+            }
+#             warn "FIXED BIBLIONUMBER".$record->as_formatted;
+        }
+        unless ($record->subfield($biblioitemnumbertagfield,$biblioitemnumbertagsubfield)) {
+            $record_correct=0;
+#             warn "INCORRECT BIBLIOITEMNUMBER :".$record->as_formatted;
+            my $field;
+            # if the field where biblionumber is already exist, just update it, otherwise create it
+            if ($record->field($biblioitemnumbertagfield)) {
+                $field =  $record->field($biblioitemnumbertagfield);
+                $field->add_subfields($biblioitemnumbertagsubfield => $biblionumber);
+            } else {
+                my $newfield = MARC::Field->new( $biblioitemnumbertagfield,'','', $biblioitemnumbertagsubfield => $biblionumber);
+                $record->insert_grouped_field($newfield);
+            }
+#             warn "FIXED BIBLIOITEMNUMBER".$record->as_formatted;
+        }
+        unless ($record_correct) {
+            my $update_xml = $dbh->prepare("update biblioitems set marcxml=? where biblionumber=?");
+            warn "UPDATING $biblionumber (missing biblionumber or biblioitemnumber in MARC record : ".$record->as_xml;
+            $update_xml->execute($record->as_xml,$biblionumber);
+        }
         print ".";
         print "\r$i" unless ($i++ %100);
         print OUT $record->as_usmarc();





More information about the Koha-cvs mailing list