Lucas Gass
5e06fd00ce
To test: 1. APPLY PATCH and restart all 2. Run the update_localuse_from_statistics.pl script without a confirm flag, nothing happens. 3. Run the script and add the --confirm flag, stuff happens. Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
96 lines
2.1 KiB
Perl
Executable file
96 lines
2.1 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
#
|
|
# Copyright (C) 2023 ByWater Solutions
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Koha::Script;
|
|
use C4::Context;
|
|
use Koha::Items;
|
|
use Koha::Statistics;
|
|
use Getopt::Long qw( GetOptions );
|
|
use Pod::Usage qw( pod2usage );
|
|
|
|
my ($params);
|
|
GetOptions(
|
|
'confirm' => \$params->{confirm}, 'help' => \$params->{help}, 'age:i' => \$params->{age},
|
|
);
|
|
if ( $params->{help} ) {
|
|
pod2usage( -verbose => 2 );
|
|
exit;
|
|
}
|
|
|
|
sub update_localuse {
|
|
|
|
my $dbh = C4::Context->dbh;
|
|
|
|
my $items = Koha::Items->search();
|
|
|
|
# Loop through each item and update it with statistics info
|
|
while ( my $item = $items->next ) {
|
|
my $itemnumber = $item->itemnumber;
|
|
|
|
my $localuse_count = Koha::Statistics->search( { itemnumber => $itemnumber, type => 'localuse' } )->count;
|
|
$item->localuse($localuse_count);
|
|
$item->store;
|
|
|
|
print "Updated item $itemnumber with localuse statistics info.\n";
|
|
}
|
|
}
|
|
|
|
my ($help);
|
|
my $result = GetOptions(
|
|
'help|h' => \$help,
|
|
);
|
|
|
|
usage() if $help;
|
|
|
|
if ( $params->{confirm} ) {
|
|
update_localuse();
|
|
}
|
|
|
|
=head1 NAME
|
|
|
|
update_local_use_from_statistics.pl
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
update_localuse_from_statistics.pl
|
|
update_localuse_from_statistics.pl --help
|
|
update_localuse_from_statistics.pl --confirm
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This script updates the items.localuse column with data from the statistics table to make sure the two tables are congruent.
|
|
|
|
=head1 OPTIONS
|
|
|
|
=over
|
|
|
|
=item B<-h--help>
|
|
|
|
Prints this help message
|
|
|
|
=item B<-c|--confirm>
|
|
|
|
Confirm to run the script.
|
|
|
|
=back
|
|
|
|
=cut
|