ca1ad87ff3b55d50704f45ddd51d0b6a8e1bfa96
[koha_fer] / 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("/etc/koha.conf.tmpXX");
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 my $sth = $dbh->prepare("select * from systempreferences");
34 $sth->execute;
35 print "connecté\n";
36 die;
37 $dbh->do("delete from marc_biblio");
38 $dbh->do("delete from marc_blob_subfield");
39 $dbh->do("delete from marc_subfield_table");
40 $dbh->do("delete from marc_word");
41 my $sth=$dbh->prepare("select * from biblio left join biblioitems on biblioitems.biblionumber=biblio.biblionumber order by biblio.biblionumber");
42 my ($row,$row2);
43 my $sth2 = $dbh->prepare("select count(*) from biblio");
44 $sth2->execute;
45 my ($total) = $sth2->fetchrow_array;
46 my $rest = $total;
47 $sth->execute;
48 my $i=0;
49 while ($row=$sth->fetchrow_hashref) {
50     $i++;
51     $rest--;
52     if ($i>99) {
53         $i=0;
54         print "$rest / $total\n";
55     }
56     my $MARCbiblio = MARCkoha2marcBiblio($dbh,$row->{biblionumber},$row->{biblioitemnumber});
57     &MARCaddbiblio($dbh,$MARCbiblio,$row->{biblionumber});
58     my $sth_item = $dbh->prepare("select * from items where biblionumber=? and biblioitemnumber=?");
59     $sth_item->execute($row->{biblionumber},$row->{biblioitemnumber});
60     while ($row2=$sth_item->fetchrow_hashref) {
61         my $MARCitem = &MARCkoha2marcItem($dbh,$row2->{biblionumber},$row2->{itemnumber});
62         &MARCadditem($dbh,$MARCitem,$row2->{biblionumber});
63     }
64 }
65
66