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
15 # find Koha's Perl modules
16 # test carefully before changing this
18 eval { require "$FindBin::Bin/kohalib.pl" };
24 use MARC
::File
::USMARC
;
27 my $dbh=C4
::Context
->dbh;
28 use Time
::HiRes
qw(gettimeofday);
30 ##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
31 ##Adjust this mapping list to your own needs
34 '952abcdefpruvxyz'=>'95kkbcfazpw9d4ye',
37 my $starttime = gettimeofday
;
38 my $sth=$dbh->prepare("SELECT biblionumber,marc FROM biblioitems ");
41 my $update=$dbh->prepare("update biblioitems set marc=?,marcxml=? where biblionumber=?");
45 while (my ($biblionumber, $marc) = $sth->fetchrow) {
47 my $record=MARC
::File
::USMARC
::decode
($marc);
49 foreach my $key (keys %mapping_list){
50 my $tag=substr($key,0,3);
51 my $newtag=substr($mapping_list{$key},0,3);
54 for (my $i=3; $i<length($key); $i++){
55 push @subf,substr($key,$i,1);
56 push @newsub,substr($mapping_list{$key},$i,1);
59 foreach my $field ($record->field($tag)){
62 for (my $r=0; $r<@subf; $r++){
63 if ($field->subfield($subf[$r]) && $notnew){
64 $addedfield=MARC
::Field
->new($newtag,$field->indicator(1),$field->indicator(2),$newsub[$r]=>$field->subfield($subf[$r]));
66 }elsif ($field->subfield($subf[$r])){
67 $addedfield->update($newsub[$r]=>$field->subfield($subf[$r]));
69 }## all subfields added
70 $record->delete_field($field);
71 $record->add_fields($addedfield);
72 }##foreach field found
74 $update->execute($record->as_usmarc,$record->as_xml_record,$biblionumber);
77 $timeneeded = gettimeofday
- $starttime unless ($b % 10000);
78 print "$b in $timeneeded s\n" unless ($b % 10000);
79 print "." unless ($b % 500);
83 ##Dont forget to export all new marc records and build your zebra db
86 # $timeneeded = gettimeofday - $starttime unless ($i % 30000);
87 # print "$i in $timeneeded s\n" unless ($i % 30000);
88 # print "." unless ($i % 500);