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

(-)a/misc/maintenance/update_localuse_from_statistics.pl (-1 / +84 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# Copyright (C) 2023 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
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.
11
#
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.
16
#
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>.
19
20
use strict;
21
use warnings;
22
23
use Koha::Script;
24
use C4::Context;
25
use Koha::Items;
26
use Koha::Statistics;
27
use Getopt::Long qw( GetOptions );
28
use Pod::Usage qw( pod2usage );
29
30
31
sub usage {
32
    pod2usage( -verbose => 2 );
33
    exit;
34
}
35
36
sub update_localuse {
37
38
    my $dbh = C4::Context->dbh;
39
40
    my $items = Koha::Items->search();
41
42
    # Loop through each item and update it with statistics info
43
    while( my $item = $items->next ){
44
      my $itemnumber = $item->itemnumber;
45
46
      my $localuse_count = Koha::Statistics->search( { itemnumber => $itemnumber, type => 'localuse' } )->count;
47
      $item->localuse( $localuse_count );
48
      $item->store;
49
50
      print "Updated item $itemnumber with localuse statistics info.\n";
51
    }
52
}
53
54
my ( $help );
55
my $result = GetOptions(
56
    'help|h'      => \$help,
57
);
58
59
usage() if $help;
60
61
update_localuse();
62
63
=head1 NAME
64
65
update_local_use_from_statistics.pl
66
67
=head1 SYNOPSIS
68
69
  update_localuse_from_statistics.pl
70
  update_localuse_from_statistics.pl --help
71
72
=head1 DESCRIPTION
73
74
This script updates the items.localuse column with data from the statistics table to make sure the two tables are congruent.
75
76
=over 8
77
78
=item B<--help>
79
80
Prints this help
81
82
=back
83
84
=cut

Return to bug 16122