Reverting to previous version, kohastructure.sql file didn't work for me, I got an...
[koha.git] / misc / migration_tools / rebuild_zebra_idx.pl
1 #!/usr/bin/perl
2 # small script that import an iso2709 file into koha 2.0
3
4 use strict;
5
6 # Koha modules used
7 use MARC::File::USMARC;
8 use MARC::Record;
9 use MARC::Batch;
10 use C4::Context;
11 use C4::Biblio;
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 write files for zebra DB reindexing. Once it's done, run zebraidx update biblios
25
26 run the script with -c to confirm the reindexing.
27
28 EOF
29 ;#'
30 die;
31 }
32
33 $|=1; # flushes output
34
35 my $dbh = C4::Context->dbh;
36 my $cgidir = C4::Context->intranetdir ."/cgi-bin";
37 unless (opendir(DIR, "$cgidir")) {
38                 $cgidir = C4::Context->intranetdir."/";
39
40
41 my $starttime = gettimeofday;
42 my $sth = $dbh->prepare("select biblionumber from biblio");
43 $sth->execute;
44 my $i=0;
45 while ((my $biblionumber) = $sth->fetchrow) {
46         my $record = GetMarcBiblio($biblionumber);
47         my $filename = $cgidir."/zebra/biblios/BIBLIO".$biblionumber."iso2709";
48         open F,"> $filename";
49         print F $record->as_xml();
50         close F;
51         $i++;
52         print "\r$i" unless ($i % 100);
53 }
54 my $timeneeded = gettimeofday - $starttime;
55 print "\n$i MARC record done in $timeneeded seconds\n";