Bug 25460: Add unit test for change to C4::OAI::Sets->UpdateOAISetsBiblio()
[koha.git] / misc / maintenance / touch_all_biblios.pl
blob8d65f21eedb8b25d5feca87c5872723dbe19c71c
1 #!/usr/bin/perl
3 # Copyright (C) 2011 ByWater Solutions
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 use strict;
21 use warnings;
22 BEGIN {
23 # find Koha's Perl modules
24 # test carefully before changing this
25 use FindBin;
26 eval { require "$FindBin::Bin/../kohalib.pl" };
29 # possible modules to use
30 use Getopt::Long;
32 use Koha::Script;
33 use C4::Context;
34 use C4::Biblio;
35 use Pod::Usage;
38 sub usage {
39 pod2usage( -verbose => 2 );
40 exit;
43 # Database handle
44 my $dbh = C4::Context->dbh;
46 # Benchmarking variables
47 my $startime = time();
48 my $goodcount = 0;
49 my $badcount = 0;
50 my $totalcount = 0;
52 # Options
53 my $verbose;
54 my $whereclause = '';
55 my $help;
56 my $outfile;
58 GetOptions(
59 'o|output:s' => \$outfile,
60 'v' => \$verbose,
61 'where:s' => \$whereclause,
62 'help|h' => \$help,
65 usage() if $help;
67 if ($whereclause) {
68 $whereclause = "WHERE $whereclause";
71 # output log or STDOUT
72 my $fh;
73 if (defined $outfile) {
74 open ($fh, '>', $outfile) || die ("Cannot open output file");
75 } else {
76 open($fh, '>&', \*STDOUT) || die ("Couldn't duplicate STDOUT: $!");
79 my $sth1 = $dbh->prepare("SELECT biblionumber, frameworkcode FROM biblio $whereclause");
80 $sth1->execute();
82 # fetch info from the search
83 while (my ($biblionumber, $frameworkcode) = $sth1->fetchrow_array){
84 my $record = GetMarcBiblio({ biblionumber => $biblionumber });
86 my $modok = ModBiblio($record, $biblionumber, $frameworkcode);
88 if ($modok) {
89 $goodcount++;
90 print $fh "Touched biblio $biblionumber\n" if (defined $verbose);
91 } else {
92 $badcount++;
93 print $fh "ERROR WITH BIBLIO $biblionumber !!!!\n";
96 $totalcount++;
99 close($fh);
101 # Benchmarking
102 my $endtime = time();
103 my $time = $endtime-$startime;
104 my $accuracy = ($goodcount / $totalcount) * 100; # this is a percentage
105 my $averagetime = 0;
106 $averagetime = $time / $totalcount if $totalcount;
107 print "Good: $goodcount, Bad: $badcount (of $totalcount) in $time seconds\n";
108 printf "Accuracy: %.2f%%\nAverage time per record: %.6f seconds\n", $accuracy, $averagetime if (defined $verbose);
110 =head1 NAME
112 touch_all_biblios.pl
114 =head1 SYNOPSIS
116 touch_all_biblios.pl
117 touch_all_biblios.pl -v
118 touch_all_biblios.pl --where=STRING
120 =head1 DESCRIPTION
122 When changes are made to ModBiblio (or the routines that are called by those),
123 it is sometimes necessary to run ModBiblio on all or some records in the catalog
124 when upgrading. This script does this.
126 =over 8
128 =item B<--help>
130 Prints this help
132 =item B<-v>
134 Provide verbose log information.
136 =item B<--where>
138 Limits the search with a user-specified WHERE clause.
140 =back
142 =cut