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