2 #-----------------------------------
3 # Script Name: rebuild_marc_newframework.pl
4 # Script Version: 0.1.0
6 ##If you change your framework for marc mapping use this script to recreate marc records in your db
7 ## Then drop the old framework and install the new one.New frameworks are being introduced with Koha3.0
8 ##Re-export all your marc and recreate Zebra db.
9 ##Writen by Tumer Garip tgarip@neu.edu.tr
18 use MARC::File::USMARC;
21 my $dbh=C4::Context->dbh;
22 use Time::HiRes qw(gettimeofday);
24 ##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
25 ##Adjust this mapping list to your own needs
28 '952abcdefpruvxyz'=>'95kkbcfazpw9d4ye',
31 my $starttime = gettimeofday;
32 my $sth=$dbh->prepare("SELECT biblionumber,marc FROM biblioitems ");
35 my $update=$dbh->prepare("update biblioitems set marc=?,marcxml=? where biblionumber=?");
39 while (my ($biblionumber, $marc) = $sth->fetchrow) {
41 my $record=MARC::File::USMARC::decode($marc);
43 foreach my $key (keys %mapping_list){
44 my $tag=substr($key,0,3);
45 my $newtag=substr($mapping_list{$key},0,3);
48 for (my $i=3; $i<length($key); $i++){
49 push @subf,substr($key,$i,1);
50 push @newsub,substr($mapping_list{$key},$i,1);
53 foreach my $field ($record->field($tag)){
56 for (my $r=0; $r<@subf; $r++){
57 if ($field->subfield($subf[$r]) && $notnew){
58 $addedfield=MARC::Field->new($newtag,$field->indicator(1),$field->indicator(2),$newsub[$r]=>$field->subfield($subf[$r]));
60 }elsif ($field->subfield($subf[$r])){
61 $addedfield->update($newsub[$r]=>$field->subfield($subf[$r]));
63 }## all subfields added
64 $record->delete_field($field);
65 $record->add_fields($addedfield);
66 }##foreach field found
68 $update->execute($record->as_usmarc,$record->as_xml_record,$biblionumber);
71 $timeneeded = gettimeofday - $starttime unless ($b % 10000);
72 print "$b in $timeneeded s\n" unless ($b % 10000);
73 print "." unless ($b % 500);
77 ##Dont forget to export all new marc records and build your zebra db
80 # $timeneeded = gettimeofday - $starttime unless ($i % 30000);
81 # print "$i in $timeneeded s\n" unless ($i % 30000);
82 # print "." unless ($i % 500);