|
Lines 29-68
use Pod::Usage qw( pod2usage );
Link Here
|
| 29 |
|
29 |
|
| 30 |
my ($params); |
30 |
my ($params); |
| 31 |
GetOptions( |
31 |
GetOptions( |
| 32 |
'confirm' => \$params->{confirm}, 'help' => \$params->{help}, 'age:i' => \$params->{age}, |
32 |
'c|confirm' => \$params->{confirm}, |
|
|
33 |
'v|verbose' => \$params->{verbose}, |
| 34 |
'help' => \$params->{help}, |
| 33 |
); |
35 |
); |
| 34 |
if ( $params->{help} ) { |
36 |
if ( $params->{help} ) { |
| 35 |
pod2usage( -verbose => 2 ); |
37 |
pod2usage( -verbose => 2 ); |
| 36 |
exit; |
38 |
exit; |
| 37 |
} |
39 |
} |
| 38 |
|
40 |
|
|
|
41 |
my $updated; |
| 42 |
|
| 43 |
if ( $params->{confirm} ) { |
| 44 |
$updated = update_localuse( { verbose => $params->{verbose} } ); |
| 45 |
} |
| 46 |
|
| 47 |
print "Updated $updated items.\n"; |
| 48 |
|
| 39 |
sub update_localuse { |
49 |
sub update_localuse { |
|
|
50 |
my $params = shift; |
| 51 |
my $verbose = $params->{verbose}; |
| 40 |
|
52 |
|
| 41 |
my $dbh = C4::Context->dbh; |
53 |
my $dbh = C4::Context->dbh; |
| 42 |
|
54 |
|
| 43 |
my $items = Koha::Items->search(); |
55 |
my $items = Koha::Items->search(); |
|
|
56 |
my $updated = 0; |
| 44 |
|
57 |
|
| 45 |
# Loop through each item and update it with statistics info |
58 |
# Loop through each item and update it with statistics info |
| 46 |
while ( my $item = $items->next ) { |
59 |
while ( my $item = $items->next ) { |
| 47 |
my $itemnumber = $item->itemnumber; |
60 |
my $itemnumber = $item->itemnumber; |
| 48 |
|
61 |
|
| 49 |
my $localuse_count = Koha::Statistics->search( { itemnumber => $itemnumber, type => 'localuse' } )->count; |
62 |
my $localuse_count = Koha::Statistics->search( { itemnumber => $itemnumber, type => 'localuse' } )->count; |
|
|
63 |
my $item_localuse = $item->localuse // 0; |
| 64 |
next if $item_localuse == $localuse_count; |
| 50 |
$item->localuse($localuse_count); |
65 |
$item->localuse($localuse_count); |
| 51 |
$item->store; |
66 |
$item->store( { skip_record_index => 1, skip_holds_queue => 1 } ); |
|
|
67 |
$updated++; |
| 52 |
|
68 |
|
| 53 |
print "Updated item $itemnumber with localuse statistics info.\n"; |
69 |
print "Updated item $itemnumber with localuse statistics info. Was $item_localuse, now $localuse_count\n" |
|
|
70 |
if $verbose; |
| 54 |
} |
71 |
} |
| 55 |
} |
72 |
return $updated; |
| 56 |
|
|
|
| 57 |
my ($help); |
| 58 |
my $result = GetOptions( |
| 59 |
'help|h' => \$help, |
| 60 |
); |
| 61 |
|
| 62 |
usage() if $help; |
| 63 |
|
| 64 |
if ( $params->{confirm} ) { |
| 65 |
update_localuse(); |
| 66 |
} |
73 |
} |
| 67 |
|
74 |
|
| 68 |
=head1 NAME |
75 |
=head1 NAME |
|
Lines 74-83
update_local_use_from_statistics.pl
Link Here
|
| 74 |
update_localuse_from_statistics.pl |
81 |
update_localuse_from_statistics.pl |
| 75 |
update_localuse_from_statistics.pl --help |
82 |
update_localuse_from_statistics.pl --help |
| 76 |
update_localuse_from_statistics.pl --confirm |
83 |
update_localuse_from_statistics.pl --confirm |
|
|
84 |
update_localuse_from_statistics.pl --verbose |
| 77 |
|
85 |
|
| 78 |
=head1 DESCRIPTION |
86 |
=head1 DESCRIPTION |
| 79 |
|
87 |
|
| 80 |
This script updates the items.localuse column with data from the statistics table to make sure the two tables are congruent. |
88 |
This script updates the items.localuse column with data from the statistics table to make sure the two tables are congruent. |
|
|
89 |
NOTE: If you have mapped the items.localuse field in your search engine you must reindex your records after running this script. |
| 81 |
|
90 |
|
| 82 |
=head1 OPTIONS |
91 |
=head1 OPTIONS |
| 83 |
|
92 |
|
|
Lines 91-96
Prints this help message
Link Here
|
| 91 |
|
100 |
|
| 92 |
Confirm to run the script. |
101 |
Confirm to run the script. |
| 93 |
|
102 |
|
|
|
103 |
=item B<-v|--verbose> |
| 104 |
|
| 105 |
Add verbosity to output. |
| 106 |
|
| 94 |
=back |
107 |
=back |
| 95 |
|
108 |
|
| 96 |
=cut |
109 |
=cut |
| 97 |
- |
|
|