View | Details | Raw Unified | Return to bug 5987
Collapse All | Expand All

(-)a/misc/maintenance/touch_all_biblios.pl (+139 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# Copyright (C) 2011 ByWater Solutions
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
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" };
27
}
28
29
# possible modules to use
30
use Getopt::Long;
31
use C4::Context;
32
use C4::Biblio;
33
use Pod::Usage;
34
35
36
sub usage {
37
    pod2usage( -verbose => 2 );
38
    exit;
39
}
40
41
# Database handle
42
my $dbh = C4::Context->dbh;
43
44
# Benchmarking variables
45
my $startime = time();
46
my $goodcount = 0;
47
my $badcount = 0;
48
my $totalcount = 0;
49
50
# Options
51
my $verbose;
52
my $whereclause = '';
53
my $help;
54
my $outfile;
55
56
GetOptions(
57
  'o|output:s' => \$outfile,
58
  'v' => \$verbose,
59
  'where:s' => \$whereclause,
60
  'help|h'   => \$help,
61
);
62
63
usage() if $help;
64
65
if ($whereclause) {
66
   $whereclause = "WHERE $whereclause";
67
}
68
69
# output log or STDOUT
70
if (defined $outfile) {
71
   open (OUT, ">$outfile") || die ("Cannot open output file");
72
} else {
73
   open(OUT, ">&STDOUT") || die ("Couldn't duplicate STDOUT: $!");
74
}
75
76
my $sth1 = $dbh->prepare("SELECT biblionumber, frameworkcode FROM biblio $whereclause");
77
$sth1->execute();
78
79
# fetch info from the search
80
while (my ($biblionumber, $frameworkcode) = $sth1->fetchrow_array){
81
  my $record = GetMarcBiblio($biblionumber);
82
 
83
  my $modok = ModBiblio($record, $biblionumber, $frameworkcode);
84
85
  if ($modok) {
86
     $goodcount++;
87
     print OUT "Touched biblio $biblionumber\n" if (defined $verbose);
88
  } else {
89
     $badcount++;
90
     print OUT "ERROR WITH BIBLIO $biblionumber !!!!\n";
91
  }
92
93
  $totalcount++;
94
95
}
96
97
# Benchmarking
98
my $endtime = time();
99
my $time = $endtime-$startime;
100
my $accuracy = ($goodcount / $totalcount) * 100; # this is a percentage
101
my $averagetime = 0;
102
unless ($time == 0) { $averagetime = $totalcount / $time; };
103
print "Good: $goodcount, Bad: $badcount (of $totalcount) in $time seconds\n";
104
printf "Accuracy: %.2f%%\nAverage time per record: %.6f seconds\n", $accuracy, $averagetime if (defined $verbose);
105
106
=head1 NAME
107
108
touch_all_biblios.pl
109
110
=head1 SYNOPSIS
111
112
  touch_all_biblios.pl
113
  touch_all_biblios.pl -v
114
  touch_all_biblios.pl --where=STRING
115
116
=head1 DESCRIPTION
117
118
When changes are made to ModBiblio (or the routines that are called by those),
119
it is sometimes necessary to run ModBiblio on all or some records in the catalog
120
when upgrading. This script does this.
121
122
=over 8
123
124
=item B<--help>
125
126
Prints this help
127
128
=item B<-v>
129
130
Provide verbose log information.
131
132
=item B<--where>
133
134
Limits the search with a user-specified WHERE clause.
135
136
=back
137
138
=cut
139
(-)a/misc/maintenance/touch_all_items.pl (-1 / +138 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# Copyright (C) 2011 ByWater Solutions
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
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" };
27
}
28
29
# possible modules to use
30
use Getopt::Long;
31
use C4::Context;
32
use C4::Items;
33
use Pod::Usage;
34
35
36
sub usage {
37
    pod2usage( -verbose => 2 );
38
    exit;
39
}
40
41
# Database handle
42
my $dbh = C4::Context->dbh;
43
44
# Benchmarking variables
45
my $startime = time();
46
my $goodcount = 0;
47
my $badcount = 0;
48
my $totalcount = 0;
49
50
# Options
51
my $verbose;
52
my $whereclause = '';
53
my $help;
54
my $outfile;
55
56
GetOptions(
57
  'o|output:s' => \$outfile,
58
  'v' => \$verbose,
59
  'where:s' => \$whereclause,
60
  'help|h'   => \$help,
61
);
62
63
usage() if $help;
64
65
if ($whereclause) {
66
   $whereclause = "WHERE $whereclause";
67
}
68
69
# output log or STDOUT
70
if (defined $outfile) {
71
   open (OUT, ">$outfile") || die ("Cannot open output file");
72
} else {
73
   open(OUT, ">&STDOUT") || die ("Couldn't duplicate STDOUT: $!");
74
}
75
76
my $sth_fetch = $dbh->prepare("SELECT biblionumber, itemnumber, itemcallnumber FROM items $whereclause");
77
$sth_fetch->execute();
78
79
# fetch info from the search
80
while (my ($biblionumber, $itemnumber, $itemcallnumber) = $sth_fetch->fetchrow_array){
81
   
82
  my $modok = ModItem({itemcallnumber => $itemcallnumber}, $biblionumber, $itemnumber);
83
84
  if ($modok) {
85
     $goodcount++;
86
     print OUT "Touched item $itemnumber\n" if (defined $verbose);
87
  } else {
88
     $badcount++;
89
     print OUT "ERROR WITH ITEM $itemnumber !!!!\n";
90
  }
91
92
  $totalcount++;
93
94
}
95
96
# Benchmarking
97
my $endtime = time();
98
my $time = $endtime-$startime;
99
my $accuracy = ($goodcount / $totalcount) * 100; # this is a percentage
100
my $averagetime = 0;
101
unless ($time == 0) {$averagetime = $totalcount / $time;};
102
print "Good: $goodcount, Bad: $badcount (of $totalcount) in $time seconds\n";
103
printf "Accuracy: %.2f%%\nAverage time per record: %.6f seconds\n", $accuracy, $averagetime if (defined $verbose);
104
105
=head1 NAME
106
107
touch_all_items.pl
108
109
=head1 SYNOPSIS
110
111
  touch_all_items.pl
112
  touch_all_items.pl -v
113
  touch_all_items.pl --where=STRING
114
115
=head1 DESCRIPTION
116
117
When changes are made to ModItem (or the routines that are called by it), it is
118
sometimes necessary to run ModItem on all or some records in the catalog when
119
upgrading. This script does that.
120
121
=over 8
122
123
=item B<--help>
124
125
Prints this help
126
127
=item B<-v>
128
129
Provide verbose log information.
130
131
=item B<--where>
132
133
Limits the search with a user-specified WHERE clause.
134
135
=back
136
137
=cut
138

Return to bug 5987