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