Lines 41-46
use Koha::Account;
Link Here
|
41 |
|
41 |
|
42 |
use base qw(Koha::Object); |
42 |
use base qw(Koha::Object); |
43 |
|
43 |
|
|
|
44 |
our $RESULTSET_PATRON_ID_MAPPING = { |
45 |
Accountline => 'borrowernumber', |
46 |
ArticleRequest => 'borrowernumber', |
47 |
BorrowerAttribute => 'borrowernumber', |
48 |
BorrowerDebarment => 'borrowernumber', |
49 |
BorrowerFile => 'borrowernumber', |
50 |
BorrowerModification => 'borrowernumber', |
51 |
ClubEnrollment => 'borrowernumber', |
52 |
Issue => 'borrowernumber', |
53 |
ItemsLastBorrower => 'borrowernumber', |
54 |
Linktracker => 'borrowernumber', |
55 |
Message => 'borrowernumber', |
56 |
MessageQueue => 'borrowernumber', |
57 |
OldIssue => 'borrowernumber', |
58 |
OldReserve => 'borrowernumber', |
59 |
Rating => 'borrowernumber', |
60 |
Reserve => 'borrowernumber', |
61 |
Review => 'borrowernumber', |
62 |
Statistic => 'borrowernumber', |
63 |
SearchHistory => 'userid', |
64 |
Suggestion => 'suggestedby', |
65 |
TagAll => 'borrowernumber', |
66 |
Virtualshelfcontent => 'borrowernumber', |
67 |
Virtualshelfshare => 'borrowernumber', |
68 |
Virtualshelve => 'owner', |
69 |
}; |
70 |
|
44 |
=head1 NAME |
71 |
=head1 NAME |
45 |
|
72 |
|
46 |
Koha::Patron - Koha Patron Object class |
73 |
Koha::Patron - Koha Patron Object class |
Lines 200-205
sub siblings {
Link Here
|
200 |
); |
227 |
); |
201 |
} |
228 |
} |
202 |
|
229 |
|
|
|
230 |
=head3 merge_with |
231 |
|
232 |
my $patron = Koha::Patrons->find($id); |
233 |
$patron->merge_with( \@patron_ids ); |
234 |
|
235 |
This subroutine merges a list of patrons into the patron record. This is accomplished by finding |
236 |
all related patron ids for the patrons to be merged in other tables and changing the ids to be that |
237 |
of the keeper patron. |
238 |
|
239 |
=cut |
240 |
|
241 |
sub merge_with { |
242 |
my ( $self, $patron_ids ) = @_; |
243 |
|
244 |
my @patron_ids = @{ $patron_ids }; |
245 |
|
246 |
# Ensure the keeper isn't in the list of patrons to merge |
247 |
@patron_ids = grep { $_ ne $self->id } @patron_ids; |
248 |
|
249 |
my $schema = Koha::Database->new()->schema(); |
250 |
|
251 |
my $results; |
252 |
|
253 |
$self->_result->result_source->schema->txn_do( sub { |
254 |
foreach my $patron_id (@patron_ids) { |
255 |
my $patron = Koha::Patrons->find( $patron_id ); |
256 |
|
257 |
next unless $patron; |
258 |
|
259 |
# Unbless for safety, the patron will end up being deleted |
260 |
$results->{merged}->{$patron_id}->{patron} = $patron->unblessed; |
261 |
|
262 |
while (my ($r, $field) = each(%$RESULTSET_PATRON_ID_MAPPING)) { |
263 |
my $rs = $schema->resultset($r)->search({ $field => $patron_id }); |
264 |
$results->{merged}->{ $patron_id }->{updated}->{$r} = $rs->count(); |
265 |
$rs->update({ $field => $self->id }); |
266 |
} |
267 |
|
268 |
$patron->move_to_deleted(); |
269 |
$patron->delete(); |
270 |
} |
271 |
}); |
272 |
|
273 |
return $results; |
274 |
} |
275 |
|
276 |
|
277 |
|
203 |
=head3 wants_check_for_previous_checkout |
278 |
=head3 wants_check_for_previous_checkout |
204 |
|
279 |
|
205 |
$wants_check = $patron->wants_check_for_previous_checkout; |
280 |
$wants_check = $patron->wants_check_for_previous_checkout; |