Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2012 BibLibre |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it under the |
8 |
# terms of the GNU General Public License as published by the Free Software |
9 |
# Foundation; either version 2 of the License, or (at your option) any later |
10 |
# version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
15 |
# |
16 |
# You should have received a copy of the GNU General Public License along |
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
20 |
# Small script that checks if each biblio in the DB is properly indexed |
21 |
# if it is not and if you use -z the not-indexed biblios are inserted in zebraqueue |
22 |
# To test just ommit the -z option you will have the biblionumber of non-indexed biblios and the total |
23 |
|
24 |
use strict; |
25 |
|
26 |
BEGIN { |
27 |
|
28 |
# find Koha's Perl modules |
29 |
# test carefully before changing this |
30 |
use FindBin; |
31 |
eval { require "$FindBin::Bin/kohalib.pl" }; |
32 |
} |
33 |
|
34 |
# Koha modules used |
35 |
use MARC::Record; |
36 |
use C4::Context; |
37 |
use C4::Search; |
38 |
use Getopt::Long; |
39 |
|
40 |
my ( $help, $confirm, $zebraqueue, $silent,$stealth ); |
41 |
|
42 |
GetOptions( |
43 |
'c' => \$confirm, |
44 |
'h' => \$help, |
45 |
'z' => \$zebraqueue, |
46 |
's' => \$silent, |
47 |
'st' => \$stealth |
48 |
); |
49 |
|
50 |
if ( $help || ( !$confirm ) ) { |
51 |
print_usage(); |
52 |
exit 0; |
53 |
} |
54 |
|
55 |
my $dbh = C4::Context->dbh; |
56 |
my $i = 0; |
57 |
my $count = 0; |
58 |
|
59 |
# flushes output |
60 |
$| = 1; |
61 |
|
62 |
my $sth = $dbh->prepare("SELECT biblionumber FROM biblio"); |
63 |
my $sth_insert = $dbh->prepare("INSERT INTO zebraqueue (biblio_auth_number,operation,server,done) VALUES (?,'specialUpdate','biblioserver',0)"); |
64 |
|
65 |
# We get all biblios |
66 |
$sth->execute; |
67 |
my ($nbhits); |
68 |
|
69 |
# We check for each biblio |
70 |
while ( my ($biblionumber) = $sth->fetchrow ) { |
71 |
(undef,undef,$nbhits) = SimpleSearch("Local-number=$biblionumber"); |
72 |
print "biblionumber $biblionumber not indexed\n" unless $nbhits || $stealth; |
73 |
# If -z option we put the biblio in zebraqueue |
74 |
if ($zebraqueue && !$nbhits){ |
75 |
$sth_insert->execute($biblionumber); |
76 |
print "$biblionumber inserted in zebraqueue\n" unless $stealth; |
77 |
} |
78 |
$i++; |
79 |
print "$i done\n" unless $i % 1000 || $silent || $stealth; |
80 |
$count++ unless $nbhits; |
81 |
} |
82 |
|
83 |
if ($count > 0 && $zebraqueue){ |
84 |
print "\t$count bibliorecords not indexed and inserted in zebraqueue\n"; |
85 |
} |
86 |
else{ |
87 |
print "\t$count bibliorecords not indexed\n"; |
88 |
} |
89 |
|
90 |
sub print_usage { |
91 |
print <<_USAGE_; |
92 |
$0: This script takes all biblios and checks if they are indexed in zebra using biblionumber search. |
93 |
|
94 |
parameters: |
95 |
\th this help screen |
96 |
\tc confirm (without this parameter, you get the help screen) |
97 |
\tz inserts a signal in zebraqueue to force indexing of non indexed biblios otherwise you have only the check |
98 |
\ts silent throws no warnings except for non indexed records. Otherwise throws a warn every 1000 biblios to show progress |
99 |
\tst stealth do not print warnings for non indexed records and do not warn every 1000 |
100 |
|
101 |
Syntax: |
102 |
\t./batchCheckNonIndexedBiblios.pl -h (or without arguments => shows this screen) |
103 |
\t./batchCheckNonIndexedBiblios.pl -c (c like confirm => checks all records (may be long) |
104 |
\t./batchCheckNonIndexedBiblios.pl -z (z like zebraqueue => inserts in zebraqueue. Without => test only, changes nothing in DB just warns) |
105 |
\t./batchCheckNonIndexedBiblios.pl -s (s like silent => don't throws a warn every 1000 biblios to show progress) |
106 |
\t./batchCheckNonIndexedBiblios.pl -st (s like stealth => don't throws a warn every 1000 biblios to show progress and no warn for the non indexed biblionumbers, just the total) |
107 |
_USAGE_ |
108 |
} |