export.tmpl was not the good one. :)
[koha.git] / misc / migration_tools / rebuild_zebra.pl
1 #!/usr/bin/perl
2
3 use strict;
4
5 # Koha modules used
6 use MARC::File::USMARC;
7 use MARC::Record;
8 use MARC::Batch;
9 use C4::Context;
10 use C4::Biblio;
11 use ZOOM;
12 use Time::HiRes qw(gettimeofday);
13
14 use Getopt::Long;
15 my ( $input_marc_file, $number) = ('',0);
16 my ($confirm);
17 GetOptions(
18     'c' => \$confirm,
19 );
20
21 unless ($confirm) {
22         print <<EOF
23
24 Script to create the zebra DB from a Koha DB
25
26 EOF
27 ;#'
28 die;
29 }
30
31 $|=1; # flushes output
32
33 my $dbh = C4::Context->dbh;
34 my $Zconn;
35 eval {
36         $Zconn = new ZOOM::Connection('localhost','2100');
37 };
38 if ($@) {
39         print "Error ", $@->code()," : ",$@->message()."\n";
40         die;
41 }
42
43 # first, drop Zebra DB
44 # eval {
45 #       my $Zpackage = $Zconn->package();
46 #       $Zpackage->option(databaseName => 'Koha');
47 # #     $Zpackage->send("drop");
48 # };
49
50 eval {
51         my $Zpackage = $Zconn->package();
52         $Zpackage->option(databaseName => 'Koha');
53         $Zpackage->send("create");
54 };
55 my $cgidir = C4::Context->intranetdir ."/cgi-bin";
56 unless (opendir(DIR, "$cgidir")) {
57                 $cgidir = C4::Context->intranetdir."/";
58
59 my $starttime = gettimeofday;
60 my $sth = $dbh->prepare("select biblionumber from biblio");
61 $sth->execute;
62 my $i=0;
63 while ((my $biblionumber) = $sth->fetchrow) {
64         my $record = XMLgetbiblio($dbh,$biblionumber);
65 #       warn "\n==============\n$record\n==================\n";
66         my $Zpackage = $Zconn->package();
67         $Zpackage->option(databaseName => 'Koha');
68         $Zpackage->option(action => "specialUpdate");
69 #       $Zpackage->option(recordIdNumber => $biblionumber);
70         $Zpackage->option(record => $record);
71         $Zpackage->send("update");
72 #       $Zpackage->destroy;
73         $i++;
74         print '.';
75         print "$i\r" unless ($i % 100);
76 #       exit if $i>100;
77 }
78 my $Zpackage = $Zconn->package();
79 $Zpackage->option(databaseName => 'Koha');
80 $Zpackage->send("commit");
81 my $timeneeded = gettimeofday - $starttime;
82 print "\n\n$i MARC record done in $timeneeded seconds\n";