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

(-)a/Koha/Patrons.pm (+30 lines)
Lines 207-212 sub anonymise_issue_history { Link Here
207
    return $nb_rows;
207
    return $nb_rows;
208
}
208
}
209
209
210
=head3 delete
211
212
    Koha::Patrons->search({ some filters here })->delete;
213
214
    Delete passed set of patron objects.
215
    Wrapper for Koha::Patron->delete. (We do not want to bypass Koha::Patron
216
    and let DBIx do the job without further housekeeping.)
217
    NOTE: By default includes a move to deletedborrowers.
218
219
    Return value (if relevant) is based on the individual return values.
220
221
=cut
222
223
sub delete {
224
    my ( $self ) = @_;
225
    my (@res, $rv);
226
    $rv = 1;
227
    while( my $patron = $self->next ) {
228
        $patron->move_to_deleted; # Needed here, since it is no default action..
229
        push @res, $patron->delete;
230
        $rv=-1 if $res[-1]==-1;
231
        $rv=0 if $rv==1 && $res[-1]==0;
232
    }
233
234
    # Return -1 if we encountered a single -1
235
    # Return 0 if we encountered a single 0 (but not a -1)
236
    # Return 1 if all individual deletes passed
237
    return $rv;
238
}
239
210
=head3 _type
240
=head3 _type
211
241
212
=cut
242
=cut
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +14 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 32;
22
use Test::More tests => 33;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
25
use Time::Fake;
25
use Time::Fake;
Lines 421-426 subtest "delete" => sub { Link Here
421
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
421
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
422
};
422
};
423
423
424
subtest 'Koha::Patrons->delete' => sub {
425
    plan tests => 3;
426
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
427
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
428
    my $id1 = $patron1->borrowernumber;
429
    my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }});
430
    is( $set->count, 2, 'Two patrons found as expected' );
431
    my $count1 = $schema->resultset('Deletedborrower')->count;
432
    is( $set->delete, 1, 'Two patrons deleted' );
433
    my $count2 = $schema->resultset('Deletedborrower')->count;
434
    is( $count2, $count1 + 2, 'Patrons moved to deletedborrowers' );
435
};
436
424
subtest 'add_enrolment_fee_if_needed' => sub {
437
subtest 'add_enrolment_fee_if_needed' => sub {
425
    plan tests => 4;
438
    plan tests => 4;
426
439
427
- 

Return to bug 21337