From 3ece1b0847100ed0412531fc9c1e5670a0225547 Mon Sep 17 00:00:00 2001 From: tgarip1957 Date: Thu, 20 Apr 2006 10:55:18 +0000 Subject: [PATCH] If you change your framework for MARC mapping use this script to remap your marc record first. Drop the old framework and install the new one. Re export all your marc and recreate ZEBRA. The script has to be manually edited to reflect your new mappings. KOHA 3.0 is expected to have new frameworks --- misc/rebuild_marc_newframework.pl | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 misc/rebuild_marc_newframework.pl diff --git a/misc/rebuild_marc_newframework.pl b/misc/rebuild_marc_newframework.pl new file mode 100644 index 0000000000..d8dcdc01aa --- /dev/null +++ b/misc/rebuild_marc_newframework.pl @@ -0,0 +1,86 @@ +#!/usr/bin/perl +#----------------------------------- +# Script Name: rebuild_marc_newframework.pl +# Script Version: 0.1.0 +# Date: 20/04/2006 +##If you change your framework for marc mapping use this script to recreate marc records in your db +## Then drop the old framework and install the new one.New frameworks are being introduced with Koha3.0 +##Re-export all your marc and recreate Zebra db. +##Writen by Tumer Garip tgarip@neu.edu.tr + + + +use strict; + +use C4::Context; +use C4::Biblio; +use MARC::Record; +use MARC::File::USMARC; +use MARC::File::XML; + +my $dbh=C4::Context->dbh; +use Time::HiRes qw(gettimeofday); + +##Write the corresponding new mappings below. this one maps old 090$c$d to new 09o$c$d and 952 holdings of NEU to 95k values +##Adjust this mapping list to your own needs +my %mapping_list = ( + '090cd' =>'09ocd', + '952abcdefpruvxyz'=>'95kkbcfazpw9d4ye', + ); + +my $starttime = gettimeofday; +my $sth=$dbh->prepare("SELECT biblionumber,marc FROM biblioitems "); +$sth->execute; + +my $update=$dbh->prepare("update biblioitems set marc=?,marcxml=? where biblionumber=?"); + +my $b=0; +my $timeneeded; +while (my ($biblionumber, $marc) = $sth->fetchrow) { + +my $record=MARC::File::USMARC::decode($marc); + +foreach my $key (keys %mapping_list){ +my $tag=substr($key,0,3); +my $newtag=substr($mapping_list{$key},0,3); +my @subf; +my @newsub; + for (my $i=3; $ifield($tag)){ +my $notnew=1; +my $addedfield; + for (my $r=0; $r<@subf; $r++){ + if ($field->subfield($subf[$r]) && $notnew){ + $addedfield=MARC::Field->new($newtag,$field->indicator(1),$field->indicator(2),$newsub[$r]=>$field->subfield($subf[$r])); + $notnew=0; + }elsif ($field->subfield($subf[$r])){ + $addedfield->update($newsub[$r]=>$field->subfield($subf[$r])); + }## a subfield exists + }## all subfields added +$record->delete_field($field); +$record->add_fields($addedfield); +}##foreach field found +##Now update-db +$update->execute($record->as_usmarc,$record->as_xml_record,$biblionumber); + +}##foreach $key + $timeneeded = gettimeofday - $starttime unless ($b % 10000); + print "$b in $timeneeded s\n" unless ($b % 10000); + print "." unless ($b % 500); + $b++; +}##while biblionumber + +##Dont forget to export all new marc records and build your zebra db + + +# $timeneeded = gettimeofday - $starttime unless ($i % 30000); +# print "$i in $timeneeded s\n" unless ($i % 30000); +# print "." unless ($i % 500); +# $i++; + + +$dbh->disconnect(); -- 2.39.5