rel_3_0 moved to HEAD (introducing new files)
[koha.git] / misc / migration_tools / 22_to_30 / rebuild_unimarc_100.pl
1 #!/usr/bin/perl
2 # This script finds and fixes missing 090 fields in Koha for MARC21
3 #  Written by TG on 01/10/2005
4 #  Revised by Joshua Ferraro on 03/31/2006
5 use strict;
6
7 # Koha modules used
8
9 use C4::Context;
10 use C4::Biblio;
11 use MARC::Record;
12 use MARC::File::USMARC;
13
14
15 my $dbh = C4::Context->dbh;
16
17 my $sth=$dbh->prepare("select biblionumber,timestamp from biblioitems");
18         $sth->execute();
19
20 while (my ($biblionumber,$time)=$sth->fetchrow ){
21 #   my $record;
22   my $record = GetMarcBiblio($biblionumber);
23 #print $record->as_marc;
24                 MARCmodrecord($biblionumber,$record,$time);
25 #
26 }
27
28 sub MARCmodrecord {
29     my ($biblionumber,$record,$time)=@_;
30 #     warn "AVANT : ".$record->as_formatted;
31     my $update=0;
32         $record->leader('     nac  22     1u 4500');
33         $update=1;
34         my $string;
35         if ($record->subfield(100,"a")) {
36             $string = $record->subfield(100,"a");
37             my $f100 = $record->field(100);
38             $record->delete_field($f100);
39         } else {
40             $string = POSIX::strftime("%Y%m%d", localtime);
41             $string=~s/\-//g;
42             $string = sprintf("%-*s",35, $string);
43         }
44         substr($string,22,6,"frey50");
45         unless ($record->subfield(100,"a")){
46             $record->insert_fields_ordered(MARC::Field->new(100,"","","a"=>$string));
47         }
48 #     warn "APRES : ".$record->as_formatted;
49     # delete all items related fields
50     foreach ($record->field('995')) {
51         $record->delete_field($_);
52     }
53     if ($update){       
54         &MARCmodbiblio($dbh,$biblionumber,$record,'',0);
55         print "$biblionumber \n";       
56     }
57
58 }
59 END;