Bug 30518: Correct DateTime maths for needs_advancing
[koha.git] / Koha / Authority / MergeRequests.pm
1 package Koha::Authority::MergeRequests;
2
3 # Copyright Rijksmuseum 2017
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 Modern::Perl;
21 use MARC::File::XML;
22
23 use C4::Context;
24 use Koha::Authority::MergeRequest;
25 use Koha::Database;
26 use Koha::DateUtils qw( dt_from_string );
27
28 use parent qw(Koha::Objects);
29
30 =head1 NAME
31
32 Koha::Authority::MergeRequests - Koha::Objects class for need_merge_authorities
33
34 =head1 SYNOPSIS
35
36 use Koha::Authority::MergeRequests;
37
38 =head1 DESCRIPTION
39
40 Description
41
42 =head1 METHODS
43
44 =head2 CLASS METHODS
45
46 =head3 cron_cleanup
47
48     Koha::Authority::MergeRequests->cron_cleanup({
49         reset_hours => 24, remove_days => 90,
50     });
51
52     Removes all entries with status "done" older than remove_days.
53     Set all entries with status "in progress" back to 0 when the timestamp
54     is older than reset_hours.
55     Defaults: reset_hours = 1, remove_days = 30.
56
57 =cut
58
59 sub cron_cleanup {
60     my ( $class_or_self, $params ) = @_;
61     my $reset_hours = $params->{reset_hours} || 1;
62     my $remove_days = $params->{remove_days} || 30;
63     my $parser = Koha::Database->new->schema->storage->datetime_parser;
64
65     my $dt = dt_from_string;
66     $dt->subtract( hours => $reset_hours );
67     $class_or_self->search({
68         done => 2,
69         timestamp => { '<' => $parser->format_datetime($dt) },
70     })->update({ done => 0 });
71
72     $dt = dt_from_string;
73     $dt->subtract( days => $remove_days );
74     $class_or_self->search({
75         done => 1,
76         timestamp => { '<' => $parser->format_datetime($dt) },
77     })->delete;
78 }
79
80 =head3 _type
81
82 Returns name of corresponding DBIC resultset
83
84 =cut
85
86 sub _type {
87     return 'NeedMergeAuthority';
88 }
89
90 =head3 object_class
91
92 Returns name of corresponding Koha object class
93
94 =cut
95
96 sub object_class {
97     return 'Koha::Authority::MergeRequest';
98 }
99
100 =head1 AUTHOR
101
102 Marcel de Rooy (Rijksmuseum)
103
104 Koha Development Team
105
106 =cut
107
108 1;