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>.
23 # find Koha's Perl modules
24 # test carefully before changing this
26 eval { require "$FindBin::Bin/../kohalib.pl" };
29 # possible modules to use
40 pod2usage
( -verbose
=> 2 );
45 my $dbh = C4
::Context
->dbh;
47 # Benchmarking variables
48 my $startime = time();
60 'o|output:s' => \
$outfile,
62 'where:s' => \
$whereclause,
69 $whereclause = "WHERE $whereclause";
72 # output log or STDOUT
74 if (defined $outfile) {
75 open ($fh, '>', $outfile) || die ("Cannot open output file");
77 open($fh, '>&', \
*STDOUT
) || die ("Couldn't duplicate STDOUT: $!");
80 # FIXME Would be better to call Koha::Items->search here
81 my $sth_fetch = $dbh->prepare("SELECT biblionumber, itemnumber, itemcallnumber FROM items $whereclause");
82 $sth_fetch->execute();
84 # fetch info from the search
85 while (my ($biblionumber, $itemnumber, $itemcallnumber) = $sth_fetch->fetchrow_array){
87 eval { Koha
::Items
->find($itemnumber)->itemcallnumber($itemcallnumber)->store; };
88 my $modok = $@ ?
0 : 1;
92 print $fh "Touched item $itemnumber\n" if (defined $verbose);
95 print $fh "ERROR WITH ITEM $itemnumber !!!!\n";
104 my $endtime = time();
105 my $time = $endtime-$startime;
106 my $accuracy = ($goodcount / $totalcount) * 100; # this is a percentage
108 $averagetime = $time / $totalcount if $totalcount;
109 print "Good: $goodcount, Bad: $badcount (of $totalcount) in $time seconds\n";
110 printf "Accuracy: %.2f%%\nAverage time per record: %.6f seconds\n", $accuracy, $averagetime if (defined $verbose);
119 touch_all_items.pl -v
120 touch_all_items.pl --where=STRING
124 When changes are made to ModItem (or the routines that are called by it), it is
125 sometimes necessary to run ModItem on all or some records in the catalog when
126 upgrading. This script does that.
136 Provide verbose log information.
140 Limits the search with a user-specified WHERE clause.