Bug 24584: Rewrite optional/patron_atributes to YAML
[koha.git] / misc / migration_tools / checkNonIndexedBiblios.pl
blobd03acbfc7a47b6e97e64f81071ef540783944fc2
1 #!/usr/bin/perl
3 # Copyright 2012 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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
24 use strict;
26 BEGIN {
28 # find Koha's Perl modules
29 # test carefully before changing this
30 use FindBin;
31 eval { require "$FindBin::Bin/kohalib.pl" };
34 # Koha modules used
35 use MARC::Record;
36 use Koha::Script;
37 use C4::Context;
38 use Getopt::Long;
40 use Koha::SearchEngine::Search;
42 my ( $help, $confirm, $zebraqueue, $silent,$stealth );
44 GetOptions(
45 'c' => \$confirm,
46 'h' => \$help,
47 'z' => \$zebraqueue,
48 's' => \$silent,
49 'st' => \$stealth
52 if ( $help || ( !$confirm ) ) {
53 print_usage();
54 exit 0;
57 my $dbh = C4::Context->dbh;
58 my $i = 0;
59 my $count = 0;
61 # flushes output
62 $| = 1;
64 my $sth = $dbh->prepare("SELECT biblionumber FROM biblio");
65 my $sth_insert = $dbh->prepare("INSERT INTO zebraqueue (biblio_auth_number,operation,server,done) VALUES (?,'specialUpdate','biblioserver',0)");
67 my $searcher = Koha::SearchEngine::Search->new({index => 'biblios'});
69 # We get all biblios
70 $sth->execute;
71 my ($nbhits);
72 # We check for each biblio
73 while ( my ($biblionumber) = $sth->fetchrow ) {
74 (undef,undef,$nbhits) = $searcher->simple_search_compat("Local-number=$biblionumber");
75 print "biblionumber $biblionumber not indexed\n" unless $nbhits || $stealth;
76 # If -z option we put the biblio in zebraqueue
77 if ($zebraqueue && !$nbhits){
78 $sth_insert->execute($biblionumber);
79 print "$biblionumber inserted in zebraqueue\n" unless $stealth;
81 $i++;
82 print "$i done\n" unless $i % 1000 || $silent || $stealth;
83 $count++ unless $nbhits;
86 if ($count > 0 && $zebraqueue){
87 print "\t$count bibliorecords not indexed and inserted in zebraqueue\n";
89 else{
90 print "\t$count bibliorecords not indexed\n";
93 sub print_usage {
94 print <<_USAGE_;
95 $0: This script takes all biblios and checks if they are indexed in zebra using biblionumber search.
97 parameters:
98 \th this help screen
99 \tc confirm (without this parameter, you get the help screen)
100 \tz inserts a signal in zebraqueue to force indexing of non indexed biblios otherwise you have only the check
101 \ts silent throws no warnings except for non indexed records. Otherwise throws a warn every 1000 biblios to show progress
102 \tst stealth do not print warnings for non indexed records and do not warn every 1000
104 Syntax:
105 \t./batchCheckNonIndexedBiblios.pl -h (or without arguments => shows this screen)
106 \t./batchCheckNonIndexedBiblios.pl -c (c like confirm => checks all records (may be long)
107 \t./batchCheckNonIndexedBiblios.pl -z (z like zebraqueue => inserts in zebraqueue. Without => test only, changes nothing in DB just warns)
108 \t./batchCheckNonIndexedBiblios.pl -s (s like silent => don't throws a warn every 1000 biblios to show progress)
109 \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)
110 _USAGE_