Bug 16911: ->get_expiry_date accepts strings
[koha.git] / Koha / Patron / Modification.pm
1 package Koha::Patron::Modification;
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use Carp;
23
24 use Koha::Database;
25
26 use base qw(Koha::Object);
27
28 =head1 NAME
29
30 Koha::Patron::Modification - Class represents a request to modify or create a patron
31
32 =head2 Class Methods
33
34 =cut
35
36 =head2 approve
37
38 $m->approve();
39
40 Commits the pending modifications to the borrower record and removes
41 them from the modifications table.
42
43 =cut
44
45 sub approve {
46     my ($self) = @_;
47
48     my $data = $self->unblessed();
49
50     delete $data->{timestamp};
51     delete $data->{verification_token};
52
53     foreach my $key ( keys %$data ) {
54         delete $data->{$key} unless ( defined( $data->{$key} ) );
55     }
56
57     my $patron = Koha::Patrons->find( $self->borrowernumber );
58
59     return unless $patron;
60
61     $patron->set($data);
62
63     if ( $patron->store() ) {
64         return $self->delete();
65     }
66 }
67
68 =head3 type
69
70 =cut
71
72 sub _type {
73     return 'BorrowerModification';
74 }
75
76 =head1 AUTHOR
77
78 Kyle M Hall <kyle@bywatersolutions.com>
79
80 =cut
81
82 1;