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
6 #use warnings; FIXME - Bug 2505
8 # find Koha's Perl modules
9 # test carefully before changing this
11 eval { require "$FindBin::Bin/../../kohalib.pl" };
19 use MARC::File::USMARC;
22 my $dbh = C4::Context->dbh;
24 my $sth=$dbh->prepare("select m.biblionumber,b.biblioitemnumber from biblio m left join biblioitems b on b.biblionumber=m.biblionumber");
28 while (my ($biblionumber,$biblioitemnumber)=$sth->fetchrow ){
29 my $record = GetMarcBiblio($biblionumber);
31 print "\r$i" unless $i %100;
32 MARCmodbiblionumber($biblionumber,$biblioitemnumber,$record);
35 sub MARCmodbiblionumber{
36 my ($biblionumber,$biblioitemnumber,$record)=@_;
38 my ($tagfield,$biblionumtagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
39 my ($tagfield2,$biblioitemtagsubfield) = &GetMarcFromKohaField("biblio.biblioitemnumber","");
42 if (defined $record) {
43 my $tag = $record->field($tagfield);
44 #warn "ICI : ".$record->as_formatted if $record->subfield('090','a') eq '11546';
46 # check that we have biblionumber at the right place, otherwise, update or create the field.
48 unless ($tag && $tag->data() == $biblionumber) {
50 $tag->update($biblionumber);
52 my $newrec = MARC::Field->new( $tagfield, $biblionumber);
53 $record->insert_fields_ordered($newrec);
58 unless ($tag && $tag->subfield($biblionumtagsubfield) == $biblionumber) {
60 $tag->update($tagfield => $biblionumber);
62 my $newrec = MARC::Field->new( $tagfield,'','', $biblionumtagsubfield => $biblionumber,$biblioitemtagsubfield=>$biblioitemnumber);
63 $record->insert_fields_ordered($newrec);
69 warn "problem with :".$biblionumber." , record undefined";
74 &ModBiblioMarc($record,$biblionumber,'');
75 print "\n modified : $biblionumber \n";