Bug 30007: Make ->anonymize methods throw an exception if AnonymousPatron is not set
[koha.git] / Koha / Old / Hold.pm
1 package Koha::Old::Hold;
2
3 # Copyright ByWater Solutions 2014
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
22 use base qw(Koha::Hold);
23
24 use C4::Context;
25 use Koha::Exceptions::SysPref;
26
27 =head1 NAME
28
29 Koha::Old::Hold - Koha Old Hold object class
30
31 This object represents a hold that has been filled or canceled
32
33 =head1 API
34
35 =head2 Class methods
36
37 =head3 anonymize
38
39     $old_hold->anonymize();
40
41 Anonymize the given I<Koha::Old::Hold> object.
42
43 =cut
44
45 sub anonymize {
46     my ($self) = @_;
47
48     my $anonymous_id = C4::Context->preference('AnonymousPatron');
49
50     Koha::Exceptions::SysPref::NotSet->throw( syspref => 'AnonymousPatron' )
51         unless $anonymous_id;
52
53     return $self->update( { borrowernumber => $anonymous_id } );
54 }
55
56 =head2 Internal methods
57
58 =head3 _type
59
60 =cut
61
62 sub _type {
63     return 'OldReserve';
64 }
65
66 =head1 AUTHOR
67
68 Kyle M Hall <kyle@bywatersolutions.com>
69
70 =cut
71
72 1;