Bug 20101: Cronjob automatic_item_modification_by_age.pl does not log run in action...
[koha.git] / misc / cronjobs / automatic_item_modification_by_age.pl
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use Getopt::Long;
6 use Pod::Usage;
7 use JSON;
8
9 use Koha::Script -cron;
10 use C4::Context;
11 use C4::Items;
12 use C4::Log;
13
14 # Getting options
15 my ( $verbose, $help, $confirm );
16 my $result = GetOptions(
17     'h|help'    => \$help,
18     'v|verbose' => \$verbose,
19     'c|confirm' => \$confirm,
20 );
21
22 pod2usage(1) if $help;
23 $verbose = 1 unless $confirm;
24
25 # Load configuration from the syspref
26 my $syspref_content = C4::Context->preference('automatic_item_modification_by_age_configuration');
27 my $rules = eval { JSON::from_json( $syspref_content ) };
28 pod2usage({ -message => "Unable to load the configuration : $@", -exitval => 1 })
29     if $@;
30
31 cronlogaction();
32
33 my $report = C4::Items::ToggleNewStatus( { rules => $rules, report_only => not $confirm } );
34
35 if ( $verbose ) {
36     if ( $report ) {
37         say "Item to modify:";
38         while ( my ( $itemnumber, $substitutions ) = each %$report ) {
39             for my $substitution ( @$substitutions ) {
40                 if ( defined $substitution->{value} and $substitution->{value} ne q|| ) {
41                    say "\titemnumber $itemnumber: $substitution->{field}=$substitution->{value}";
42                 } else {
43                    say "\titemnumber $itemnumber: field $substitution->{field} to delete";
44                 }
45             }
46         }
47     } else {
48         say "There is no item to modify";
49     }
50 }
51
52 exit(0);
53
54 __END__
55
56 =head1 NAME
57
58 automatic_item_modification_by_age.pl
59
60 =head1 SYNOPSIS
61
62 ./automatic_item_modification_by_age.pl -h
63
64 Toggle recent acquisitions status.
65 Use this script to delete "new" status for items.
66
67 =head1 OPTIONS
68
69 =over 8
70
71 =item B<-h|--help>
72
73 Prints this help message.
74
75 =item B<-v|--verbose>
76
77 Set the verbose flag.
78
79 =item B<-c|--confirm>
80
81 The script will modify the items.
82
83 =back
84
85 =head1 AUTHOR
86
87 Jonathan Druart <jonathan.druart@biblibre.com>
88
89 =head1 COPYRIGHT
90
91 Copyright 2013 BibLibre
92
93 =head1 LICENSE
94
95 This file is part of Koha.
96
97 Koha is free software; you can redistribute it and/or modify it
98 under the terms of the GNU General Public License as published by
99 the Free Software Foundation; either version 3 of the License, or
100 (at your option) any later version.
101
102 Koha is distributed in the hope that it will be useful, but
103 WITHOUT ANY WARRANTY; without even the implied warranty of
104 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105 GNU General Public License for more details.
106
107 You should have received a copy of the GNU General Public License
108 along with Koha; if not, see <http://www.gnu.org/licenses>.
109
110 =cut