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