97d619c362adf8cecfa55310140396b9a41d0f24
[koha.git] / misc / batchRepairMissingBiblionumbers.pl
1 #!/usr/bin/perl
2 # This script finds and fixes missing biblionumber/biblioitemnumber fields in Koha
3 #  Written by TG on 01/10/2005
4 #  Revised by Joshua Ferraro on 03/31/2006
5 use strict;
6 use warnings;
7
8 # Koha modules used
9 use Koha::Script;
10 use C4::Context;
11 use C4::Biblio qw( ModBiblioMarc );
12 use Koha::Biblios;
13
14
15 my $dbh = C4::Context->dbh;
16
17 my $sth=$dbh->prepare("SELECT biblio.biblionumber, biblioitemnumber, frameworkcode FROM biblio JOIN biblioitems USING (biblionumber)");
18 $sth->execute();
19
20 while (my ($biblionumber,$biblioitemnumber,$frameworkcode)=$sth->fetchrow ){
21     my $biblio = Koha::Biblios->find($biblionumber);
22     my $record = $biblio->metadata->record;
23     C4::Biblio::_koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
24     my $biblionumber = eval {ModBiblioMarc( $record, $biblionumber )};
25     if($@){
26         print "Problem with biblionumber : $biblionumber\n";
27         exit -1;
28     }else{
29         print "biblionumber : $biblionumber\r\r";
30     }
31 }
32
33 END;