Generating index for authorities on AUTHtypecode from table auth_header
[koha.git] / misc / xmlintobiblioitems.pl
1 #!/usr/bin/perl
2 # script that correct the marcxml  from in biblioitems 
3 #  Written by TG on 10/04/2006
4 use strict;
5 BEGIN {
6     # find Koha's Perl modules
7     # test carefully before changing this
8     use FindBin;
9     eval { require "$FindBin::Bin/kohalib.pl" };
10 }
11
12 # Koha modules used
13
14 use C4::Context;
15 use C4::Biblio;
16 use MARC::Record;
17 use MARC::File::USMARC;
18 use MARC::File::XML;
19 use Time::HiRes qw(gettimeofday);
20
21 my $starttime = gettimeofday;
22 my $timeneeded;
23 my $dbh = C4::Context->dbh;
24 my $sth=$dbh->prepare("select biblionumber,marc from biblioitems ");
25         $sth->execute();
26   $dbh->do("LOCK TABLES biblioitems WRITE");
27 my $i=0;
28 my $sth2 = $dbh->prepare("UPDATE biblioitems  set marcxml=? where biblionumber=?" );
29    
30
31 while (my ($biblionumber,$marc)=$sth->fetchrow ){
32
33  my $record = MARC::File::USMARC::decode($marc);
34 my $xml=$record->as_xml_record();
35 $sth2->execute($xml,$biblionumber);
36
37         print "." unless ($i % 100);
38 $timeneeded = gettimeofday - $starttime unless ($i % 5000);
39         print "$i records in $timeneeded s\n"  unless ($i % 5000);
40         $i++;
41 }
42 $dbh->do("UNLOCK TABLES ");
43 $timeneeded = gettimeofday - $starttime ;
44         print "$i records in $timeneeded s\n" ;
45
46 END;