|
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 $itemsth = $dbh->prepare("SELECT * FROM items"); |
| 41 |
$itemsth->execute(); |
| 42 |
|
| 43 |
# Loop through each item and update it with statistics info |
| 44 |
while (my $item = $itemsth->fetchrow_hashref) { |
| 45 |
my $itemnumber = $item->{'itemnumber'}; |
| 46 |
|
| 47 |
# Update the item with statistics info |
| 48 |
my $item_obj = Koha::Items->find($itemnumber); |
| 49 |
|
| 50 |
my $localuse_count = Koha::Statistics->search( { itemnumber => $itemnumber, type => 'localuse' } )->count; |
| 51 |
$item_obj->localuse( $localuse_count ); |
| 52 |
$item_obj->store; |
| 53 |
|
| 54 |
print "Updated item $itemnumber with localuse statistics info.\n"; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
my ( $help ); |
| 59 |
my $result = GetOptions( |
| 60 |
'help|h' => \$help, |
| 61 |
); |
| 62 |
|
| 63 |
usage() if $help; |
| 64 |
|
| 65 |
update_localuse(); |
| 66 |
|
| 67 |
=head1 NAME |
| 68 |
|
| 69 |
update_local_use_from_statistics.pl |
| 70 |
|
| 71 |
=head1 SYNOPSIS |
| 72 |
|
| 73 |
update_localuse_from_statistics.pl |
| 74 |
update_localuse_from_statistics.pl --help |
| 75 |
|
| 76 |
=head1 DESCRIPTION |
| 77 |
|
| 78 |
This script updates the items.localuse column with data from the statistics table to make sure the two tables are congruent. |
| 79 |
|
| 80 |
=over 8 |
| 81 |
|
| 82 |
=item B<--help> |
| 83 |
|
| 84 |
Prints this help |
| 85 |
|
| 86 |
=back |
| 87 |
|
| 88 |
=cut |