Lines 23-33
use Carp;
Link Here
|
23 |
|
23 |
|
24 |
use Koha::Database; |
24 |
use Koha::Database; |
25 |
use Koha::Exceptions::Patron::Modification; |
25 |
use Koha::Exceptions::Patron::Modification; |
|
|
26 |
use Koha::Patron::Attribute; |
27 |
use Koha::Patron::Attributes; |
26 |
use Koha::Patron::Modifications; |
28 |
use Koha::Patron::Modifications; |
27 |
# TODO: Remove once Koha::Patron::Attribute(s) is implemented |
|
|
28 |
use C4::Members::Attributes qw( SetBorrowerAttributes ); |
29 |
|
29 |
|
30 |
use JSON; |
30 |
use JSON; |
|
|
31 |
use List::MoreUtils qw( uniq ); |
31 |
use Try::Tiny; |
32 |
use Try::Tiny; |
32 |
|
33 |
|
33 |
use base qw(Koha::Object); |
34 |
use base qw(Koha::Object); |
Lines 87-92
sub approve {
Link Here
|
87 |
my ($self) = @_; |
88 |
my ($self) = @_; |
88 |
|
89 |
|
89 |
my $data = $self->unblessed(); |
90 |
my $data = $self->unblessed(); |
|
|
91 |
my $extended_attributes; |
90 |
|
92 |
|
91 |
delete $data->{timestamp}; |
93 |
delete $data->{timestamp}; |
92 |
delete $data->{verification_token}; |
94 |
delete $data->{verification_token}; |
Lines 104-110
sub approve {
Link Here
|
104 |
|
106 |
|
105 |
# Take care of extended attributes |
107 |
# Take care of extended attributes |
106 |
if ( $self->extended_attributes ) { |
108 |
if ( $self->extended_attributes ) { |
107 |
our $extended_attributes |
109 |
$extended_attributes |
108 |
= try { decode_json( $self->extended_attributes ) } |
110 |
= try { decode_json( $self->extended_attributes ) } |
109 |
catch { |
111 |
catch { |
110 |
Koha::Exceptions::Patron::Modification::InvalidData->throw( |
112 |
Koha::Exceptions::Patron::Modification::InvalidData->throw( |
Lines 117-128
sub approve {
Link Here
|
117 |
try { |
119 |
try { |
118 |
$patron->store(); |
120 |
$patron->store(); |
119 |
|
121 |
|
120 |
# Take care of extended attributes |
122 |
# Deal with attributes |
121 |
if ( $self->extended_attributes ) { |
123 |
my @codes |
122 |
my $extended_attributes |
124 |
= uniq( map { $_->{code} } @{$extended_attributes} ); |
123 |
= decode_json( $self->extended_attributes ); |
125 |
foreach my $code (@codes) { |
124 |
SetBorrowerAttributes( $patron->borrowernumber, |
126 |
map { $_->delete } Koha::Patron::Attributes->search( |
125 |
$extended_attributes ); |
127 |
{ borrowernumber => $patron->borrowernumber, |
|
|
128 |
code => $code |
129 |
} |
130 |
); |
131 |
} |
132 |
foreach my $attr ( @{$extended_attributes} ) { |
133 |
Koha::Patron::Attribute->new( |
134 |
{ borrowernumber => $patron->borrowernumber, |
135 |
code => $attr->{code}, |
136 |
attribute => $attr->{value} |
137 |
} |
138 |
)->store; |
126 |
} |
139 |
} |
127 |
} |
140 |
} |
128 |
catch { |
141 |
catch { |
Lines 141-148
sub approve {
Link Here
|
141 |
} |
154 |
} |
142 |
|
155 |
|
143 |
|
156 |
|
144 |
|
|
|
145 |
|
146 |
=head3 type |
157 |
=head3 type |
147 |
|
158 |
|
148 |
=cut |
159 |
=cut |