View | Details | Raw Unified | Return to bug 21337
Collapse All | Expand All

(-)a/Koha/Patrons.pm (-4 / +4 lines)
Lines 209-231 sub anonymise_issue_history { Link Here
209
209
210
=head3 delete
210
=head3 delete
211
211
212
    Koha::Patrons->search({ some filters here })->delete;
212
    Koha::Patrons->search({ some filters here })->delete({ move => 1 });
213
213
214
    Delete passed set of patron objects.
214
    Delete passed set of patron objects.
215
    Wrapper for Koha::Patron->delete. (We do not want to bypass Koha::Patron
215
    Wrapper for Koha::Patron->delete. (We do not want to bypass Koha::Patron
216
    and let DBIx do the job without further housekeeping.)
216
    and let DBIx do the job without further housekeeping.)
217
    NOTE: By default includes a move to deletedborrowers.
217
    Includes a move to deletedborrowers if move flag set.
218
218
219
    Return value (if relevant) is based on the individual return values.
219
    Return value (if relevant) is based on the individual return values.
220
220
221
=cut
221
=cut
222
222
223
sub delete {
223
sub delete {
224
    my ( $self ) = @_;
224
    my ( $self, $params ) = @_;
225
    my (@res, $rv);
225
    my (@res, $rv);
226
    $rv = 1;
226
    $rv = 1;
227
    while( my $patron = $self->next ) {
227
    while( my $patron = $self->next ) {
228
        $patron->move_to_deleted; # Needed here, since it is no default action..
228
        $patron->move_to_deleted if $params->{move};
229
        push @res, $patron->delete;
229
        push @res, $patron->delete;
230
        $rv=-1 if $res[-1]==-1;
230
        $rv=-1 if $res[-1]==-1;
231
        $rv=0 if $rv==1 && $res[-1]==0;
231
        $rv=0 if $rv==1 && $res[-1]==0;
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +1 lines)
Lines 429-435 subtest 'Koha::Patrons->delete' => sub { Link Here
429
    my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }});
429
    my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }});
430
    is( $set->count, 2, 'Two patrons found as expected' );
430
    is( $set->count, 2, 'Two patrons found as expected' );
431
    my $count1 = $schema->resultset('Deletedborrower')->count;
431
    my $count1 = $schema->resultset('Deletedborrower')->count;
432
    is( $set->delete, 1, 'Two patrons deleted' );
432
    is( $set->delete({ move => 1 }), 1, 'Two patrons deleted' );
433
    my $count2 = $schema->resultset('Deletedborrower')->count;
433
    my $count2 = $schema->resultset('Deletedborrower')->count;
434
    is( $count2, $count1 + 2, 'Patrons moved to deletedborrowers' );
434
    is( $count2, $count1 + 2, 'Patrons moved to deletedborrowers' );
435
};
435
};
436
- 

Return to bug 21337