[Koha-cvs] koha/misc/migration_tools 22_to_30/move_marc_to... [rel_3_0]

paul poulain paul at koha-fr.org
Fri Dec 1 14:44:19 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	paul poulain <tipaul>	06/12/01 13:44:19

Modified files:
	misc/migration_tools/22_to_30: move_marc_to_authheader.pl 
	misc/migration_tools: rebuild_zebra.pl 

Log message:
	some improvements & fixes in 2.2 -> 3.0 migration and in zebra rebuild script.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/misc/migration_tools/22_to_30/move_marc_to_authheader.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.2&r2=1.1.2.3
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.4&r2=1.4.2.5

Patches:
Index: 22_to_30/move_marc_to_authheader.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/22_to_30/Attic/move_marc_to_authheader.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
--- 22_to_30/move_marc_to_authheader.pl	28 Nov 2006 17:48:26 -0000	1.1.2.2
+++ 22_to_30/move_marc_to_authheader.pl	1 Dec 2006 13:44:19 -0000	1.1.2.3
@@ -8,6 +8,7 @@
 use MARC::Record;
 use MARC::File::XML ( BinaryEncoding => 'utf8' );
 
+use strict;
 print "moving MARC record to marc_header table\n";
 
 my $dbh = C4::Context->dbh();
@@ -22,16 +23,17 @@
 $|=1; # flushes output
 
 # moving data from marc_subfield_value to biblio
-$sth = $dbh->prepare('select authid from auth_header');
+my $sth = $dbh->prepare('select authid,authtypecode from auth_header');
 $sth->execute;
 my $sth_update =
   $dbh->prepare(
     'update auth_header set marc=?,marcxml=? where authid=?');
 my $totaldone = 0;
-while ( my ( $authid) = $sth->fetchrow ) {
-    my $record = AUTHgetauthority( $dbh, $authid );
+while ( my ( $authid,$authtypecode ) = $sth->fetchrow ) {
+#     my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
+    my $record = old_AUTHgetauthority( $dbh, $authid );
     $record->leader('     nac  22     1u 4500');
-    my $string=$1 if $time=~m/([0-9\-]+)/;
+    my $string;
     $string=~s/\-//g;
     $string = sprintf("%-*s",26, $string);
     substr($string,9,6,"frey50");
@@ -53,9 +55,72 @@
 
     #Force UTF-8 in record leaded
     $record->encoding('UTF-8');
+#     warn "REC : ".$record->as_formatted;
     $sth_update->execute( $record->as_usmarc(),$record->as_xml("UNIMARCAUTH"),
         $authid );
     $totaldone++;
     print "\r$totaldone" unless ( $totaldone % 100 );
 }
 print "\rdone\n";
+
+#
+# copying the 2.2 getauthority function, to retrieve authority correctly
+# before moving it to marcxml field.
+#
+sub old_AUTHgetauthority {
+# Returns MARC::Record of the biblio passed in parameter.
+    my ($dbh,$authid)=@_;
+    my $record = MARC::Record->new();
+#---- TODO : the leader is missing
+	$record->leader('                        ');
+    my $sth=$dbh->prepare("select authid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue
+		 		 from auth_subfield_table
+		 		 where authid=? order by tag,tagorder,subfieldorder
+		 	 ");
+	$sth->execute($authid);
+	my $prevtagorder=1;
+	my $prevtag='XXX';
+	my $previndicator;
+	my $field; # for >=10 tags
+	my $prevvalue; # for <10 tags
+	while (my $row=$sth->fetchrow_hashref) {
+		if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
+			$previndicator.="  ";
+			if ($prevtag <10) {
+ 			$record->add_fields((sprintf "%03s",$prevtag),$prevvalue) unless $prevtag eq "XXX"; # ignore the 1st loop
+			} else {
+				$record->add_fields($field) unless $prevtag eq "XXX";
+			}
+			undef $field;
+			$prevtagorder=$row->{tagorder};
+			$prevtag = $row->{tag};
+			$previndicator=$row->{tag_indicator};
+			if ($row->{tag}<10) {
+				$prevvalue = $row->{subfieldvalue};
+			} else {
+				$field = MARC::Field->new((sprintf "%03s",$prevtag), substr($row->{tag_indicator}.'  ',0,1), substr($row->{tag_indicator}.'  ',1,1), $row->{'subfieldcode'}, $row->{'subfieldvalue'} );
+			}
+		} else {
+			if ($row->{tag} <10) {
+ 				$record->add_fields((sprintf "%03s",$row->{tag}), $row->{'subfieldvalue'});
+ 			} else {
+				$field->add_subfields($row->{'subfieldcode'}, $row->{'subfieldvalue'} );
+ 			}
+ 			$prevtag= $row->{tag};
+			$previndicator=$row->{tag_indicator};
+		}
+	}
+	# the last has not been included inside the loop... do it now !
+	if ($prevtag ne "XXX") { # check that we have found something. Otherwise, prevtag is still XXX and we
+						# must return an empty record, not make MARC::Record fail because we try to
+						# create a record with XXX as field :-(
+		if ($prevtag <10) {
+			$record->add_fields($prevtag,$prevvalue);
+		} else {
+	#  		my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
+			$record->add_fields($field);
+		}
+	}
+	return $record;
+}
+

Index: rebuild_zebra.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/rebuild_zebra.pl,v
retrieving revision 1.4.2.4
retrieving revision 1.4.2.5
diff -u -b -r1.4.2.4 -r1.4.2.5
--- rebuild_zebra.pl	28 Nov 2006 17:49:22 -0000	1.4.2.4
+++ rebuild_zebra.pl	1 Dec 2006 13:44:19 -0000	1.4.2.5
@@ -13,7 +13,8 @@
 
 $|=1; # flushes output
 
-
+# limit for database dumping
+my $limit = "LIMIT 10";
 my $directory;
 my $skip_export;
 my $keep_export;
@@ -95,10 +96,10 @@
 
 # getting tab directory
 my $tabdir;
-foreach (qw(/usr/local/share/idzebra-2.0/tab/explain.att
-            /usr/local/share/idzebra/tab/explain.att
-            /usr/share/idzebra-2.0/tab/explain.att
+foreach (qw(/usr/local/share/idzebra/tab/explain.att
+            /usr/local/share/idzebra-2.0/tab/explain.att
             /usr/share/idzebra/tab/explain.att
+            /usr/share/idzebra-2.0/tab/explain.att
         )) {
     if ( -f $_ ) {
         $tabdir=$_;
@@ -122,7 +123,7 @@
 #
 my $created_dir_or_file = 0;
 print "====================\n";
-print "checking directories & files\n";
+print "checking directories & files for authorities\n";
 print "====================\n";
 unless (-d "$authorityserverdir") {
     system("mkdir -p $authorityserverdir");
@@ -185,9 +186,9 @@
     print "Info: copied word-phase-utf.chr\n";
     $created_dir_or_file++;
 }
-unless (-f "$authorityserverdir/tab/bib1.att") {
-    system("cp -f $kohadir/misc/zebra/bib1_authorities.att $authorityserverdir/tab/bib1.att");
-    print "Info: copied bib1.att\n";
+unless (-f "$authorityserverdir/tab/auth1.att") {
+    system("cp -f $kohadir/misc/zebra/bib1_authorities.att $authorityserverdir/tab/auth1.att");
+    print "Info: copied auth1.att\n";
     $created_dir_or_file++;
 }
 unless (-f "$authorityserverdir/etc/ccl.properties") {
@@ -212,16 +213,16 @@
 
 encoding: UTF-8
 # Files that describe the attribute sets supported.
-attset: bib1.att
+attset: auth1.att
 attset: explain.att
-attset:gils.att
+attset: gils.att
 
 modulePath:$modulesdir/modules/
 systag sysno rank
 # Specify record type
 iso2709.recordType:grs.marcxml.record
 recordType:grs.xml
-recordId: (bib1,Local-Number)
+recordId: (auth1,Local-Number)
 storeKeys:1
 storeData:1
 
@@ -271,7 +272,7 @@
     open(OUT,">:utf8","$directory/authorities/authorities.iso2709") or die $!;
     my $dbh=C4::Context->dbh;
     my $sth;
-    $sth=$dbh->prepare("select authid from auth_header limit 100");
+    $sth=$dbh->prepare("select authid from auth_header $limit");
     $sth->execute();
     my $i=0;
     while (my ($authid) = $sth->fetchrow) {
@@ -292,11 +293,14 @@
 system("zebraidx -g iso2709 -c $authorityserverdir/etc/zebra-authorities.cfg -d authorities update $directory/authorities");
 system("zebraidx -g iso2709 -c $authorityserverdir/etc/zebra-authorities.cfg -d authorities commit");
 
-
 #################################################################################################################
 #                        BIBLIOS 
 #################################################################################################################
 
+print "====================\n";
+print "checking directories & files for biblios\n";
+print "====================\n";
+
 #
 # BIBLIOS : creating directory structure
 #
@@ -387,8 +391,8 @@
 
 encoding: UTF-8
 # Files that describe the attribute sets supported.
-attset: bib1.att
-attset: explain.att
+attset:bib1.att
+attset:explain.att
 attset:gils.att
 
 modulePath:$modulesdir/modules/
@@ -443,10 +447,11 @@
     print "exporting biblios\n";
     print "====================\n";
     mkdir "$directory" unless (-d $directory);
-    open(OUT,">:utf8","$directory/export") or die $!;
+    mkdir "$directory/biblios" unless (-d "$directory/biblios");
+    open(OUT,">:utf8","$directory/biblios/export") or die $!;
     my $dbh=C4::Context->dbh;
     my $sth;
-    $sth=$dbh->prepare("select biblionumber from biblioitems order by biblionumber limit 100");
+    $sth=$dbh->prepare("select biblionumber from biblioitems order by biblionumber $limit");
     $sth->execute();
     my $i=0;
     while (my ($biblionumber) = $sth->fetchrow) {
@@ -517,7 +522,7 @@
 print "====================\n";
 print "REINDEXING zebra\n";
 print "====================\n";
-system("zebraidx -g iso2709 -c $biblioserverdir/etc/zebra-biblios.cfg -d biblios update $directory");
+system("zebraidx -g iso2709 -c $biblioserverdir/etc/zebra-biblios.cfg -d biblios update $directory/biblios");
 system("zebraidx -g iso2709 -c $biblioserverdir/etc/zebra-biblios.cfg -d biblios commit");
 
 print "====================\n";





More information about the Koha-cvs mailing list