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