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