Merged with arensb-context branch: use C4::Context->dbh instead of
[koha.git] / marc / updatedb2marc.pl
1 #!/usr/bin/perl
2 # migrate koha-biblios to MARCbiblios
3
4 package C4::test;
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 require Exporter;
25 use C4::Context;
26 use C4::Catalogue;
27 use C4::Biblio;
28 use MARC::Record;
29 use MARC::File::USMARC;
30
31 #die;
32 my $dbh = C4::Context->dbh;
33 $dbh->do("delete from marc_biblio");
34 $dbh->do("delete from marc_blob_subfield");
35 $dbh->do("delete from marc_subfield_table");
36 $dbh->do("delete from marc_word");
37 my $sth=$dbh->prepare("select * from biblio left join biblioitems on biblioitems.biblionumber=biblio.biblionumber order by biblio.biblionumber");
38 my ($row,$row2);
39 my $sth2 = $dbh->prepare("select count(*) from biblio");
40 $sth2->execute;
41 my ($total) = $sth2->fetchrow_array;
42 my $rest = $total;
43 $sth->execute;
44 my $i=0;
45 while ($row=$sth->fetchrow_hashref) {
46     $i++;
47     $rest--;
48     if ($i>99) {
49         $i=0;
50         print "$rest / $total\n";
51     }
52     my $MARCbiblio = MARCkoha2marcBiblio($dbh,$row->{biblionumber},$row->{biblioitemnumber});
53     &MARCaddbiblio($dbh,$MARCbiblio,$row->{biblionumber});
54     my $sth_item = $dbh->prepare("select * from items where biblionumber=? and biblioitemnumber=?");
55     $sth_item->execute($row->{biblionumber},$row->{biblioitemnumber});
56     while ($row2=$sth_item->fetchrow_hashref) {
57         my $MARCitem = &MARCkoha2marcItem($dbh,$row2->{biblionumber},$row2->{itemnumber});
58         &MARCadditem($dbh,$MARCitem,$row2->{biblionumber});
59     }
60 }
61
62