View | Details | Raw Unified | Return to bug 42051
Collapse All | Expand All

(-)a/misc/cronjobs/serialsMod.pl (-1 / +152 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2024 BibLibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use strict;
21
use warnings;
22
23
use Koha::Script -cron;
24
use C4::Context;
25
use C4::Serials  qw( ModSerialStatus );
26
use C4::Log      qw( cronlogaction );
27
use Getopt::Long qw( GetOptions );
28
use Pod::Usage   qw( pod2usage );
29
30
=head1 NAME
31
32
serialsMod.pl - change serial status
33
34
=head1 SYNOPSIS
35
36
serialsMod.pl
37
38
Changes the status of serials
39
40
 Options:
41
   --h --help -?       Help message
42
   --verbose -v        Verbose mode
43
   --confirm -c        Confirm: without this option, the script will report on affected serial
44
                       issues without modifying database
45
   --where -w          Adds "WHERE" SQL condition
46
   --from_status -f    Serial status (repeatable). See list below.
47
   --to_status -t      Change issue to given status.
48
   --biblionumber -b   Consider the given biblio
49
   --subscriptionid -s Consider the given subscription
50
51
 Status list:
52
53
    EXPECTED               => 1,
54
    ARRIVED                => 2,
55
    LATE                   => 3,
56
    MISSING                => 4,
57
    MISSING_NEVER_RECIEVED => 41,
58
    MISSING_SOLD_OUT       => 42,
59
    MISSING_DAMAGED        => 43,
60
    MISSING_LOST           => 44,
61
    NOT_ISSUED             => 5,
62
    DELETED                => 6,
63
    CLAIMED                => 7,
64
    STOPPED                => 8,
65
66
Examples:
67
68
perl misc/cronjobs/serialsMod.pl -v --from_status 2 --from_status 1 --to_status=6 --confirm
69
70
perl misc/cronjobs/serialsMod.pl -v --where="planneddate >= NOW()" --to_status=3 --confirm
71
72
=cut
73
74
my $dbh = C4::Context->dbh;
75
76
my $help    = 0;
77
my $confirm = 0;
78
my $verbose = 0;
79
my $where   = '';
80
my $biblionumber;
81
my $subscriptionid;
82
my @from_status;
83
my $to_status;
84
85
my $command_line_options = join( " ", @ARGV );
86
87
GetOptions(
88
    'help|h|?'           => \$help,
89
    'v|verbose'          => \$verbose,
90
    'c|confirm'          => \$confirm,
91
    'b|biblionumber=i'   => \$biblionumber,
92
    's|subscriptionid=i' => \$subscriptionid,
93
    'w|where=s'          => \$where,
94
    't|to_status=i',     => \$to_status,
95
    'f|from_status=i',   => \@from_status,
96
) or pod2usage(2);
97
98
pod2usage(1) if $help;
99
100
cronlogaction( { info => $command_line_options } );
101
102
$verbose and !$confirm and print "### Database will not be modified ###\n";
103
104
my $query = q{
105
     SELECT
106
       serial.serialid,
107
       serial.serialseq,
108
       serial.subscriptionid,
109
       serial.planneddate,
110
       serial.publisheddate,
111
       serial.notes,
112
       serial.status
113
     FROM serial
114
     WHERE 1=1
115
    };
116
117
$query .= " AND $where"                                       if ($where);
118
$query .= " AND biblionumber=$biblionumber"                   if ($biblionumber);
119
$query .= " AND subscriptionid=$subscriptionid"               if ($subscriptionid);
120
$query .= " AND status IN(" . join( ',', @from_status ) . ")" if (@from_status);
121
122
my $sth = $dbh->prepare($query);
123
$sth->execute();
124
125
while ( my $issue = $sth->fetchrow_hashref ) {
126
127
    if ($confirm) {
128
        if ( $issue->{status} == $to_status ) {
129
            $verbose and print "Serial issue with id=" . $issue->{serialid} . " has already status $to_status\n";
130
        } else {
131
            ModSerialStatus(
132
                $issue->{serialid},    $issue->{serialseq},
133
                $issue->{planneddate}, $issue->{publisheddate}, $issue->{publisheddatetext}, $to_status, $issue->{notes}
134
            );
135
            $verbose
136
                and print "Serial issue status with id="
137
                . $issue->{serialid}
138
                . " went from "
139
                . $issue->{status}
140
                . " to $to_status\n";
141
        }
142
    } else {
143
        $verbose
144
            and print "Serial issue status with id="
145
            . $issue->{serialid}
146
            . " would have gone from "
147
            . $issue->{status}
148
            . " to $to_status\n";
149
    }
150
}
151
152
cronlogaction( { action => 'End', info => "COMPLETED" } );

Return to bug 42051