Merge branch 'master' of /home/jmf/repos/koha-rm-root.git/
[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
6 # Koha modules used
7
8 use C4::Context;
9 use C4::Biblio;
10 use MARC::Record;
11 use MARC::File::USMARC;
12 use MARC::File::XML;
13 use Time::HiRes qw(gettimeofday);
14
15 my $starttime = gettimeofday;
16 my $timeneeded;
17 my $dbh = C4::Context->dbh;
18 my $sth=$dbh->prepare("select biblionumber,marc from biblioitems ");
19         $sth->execute();
20   $dbh->do("LOCK TABLES biblioitems WRITE");
21 my $i=0;
22 my $sth2 = $dbh->prepare("UPDATE biblioitems  set marcxml=? where biblionumber=?" );
23    
24
25 while (my ($biblionumber,$marc)=$sth->fetchrow ){
26
27  my $record = MARC::File::USMARC::decode($marc);
28 my $xml=$record->as_xml_record();
29 $sth2->execute($xml,$biblionumber);
30
31         print "." unless ($i % 100);
32 $timeneeded = gettimeofday - $starttime unless ($i % 5000);
33         print "$i records in $timeneeded s\n"  unless ($i % 5000);
34         $i++;
35 }
36 $dbh->do("UNLOCK TABLES ");
37 $timeneeded = gettimeofday - $starttime ;
38         print "$i records in $timeneeded s\n" ;
39
40 END;