Bug 21337: Add Koha::Patrons->delete (trivial wrapper)
Adds Koha::Patrons->delete as wrapper around Koha::Patron->delete. We do not want to bypass Koha::Patron and let DBIx do the job without further housekeeping. A call to move_to_deleted is included now, but could be made optional with a parameter if needed. Test plan: Run t/db_dependent/Koha/Patrons.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Michal Denar <black23@gmail.com> Signed-off-by: Michal Denar <black23@gmail.com> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
parent
cea8a72708
commit
e652f47ced
|
|
@ -207,6 +207,36 @@ sub anonymise_issue_history {
|
|||
return $nb_rows;
|
||||
}
|
||||
|
||||
=head3 delete
|
||||
|
||||
Koha::Patrons->search({ some filters here })->delete;
|
||||
|
||||
Delete passed set of patron objects.
|
||||
Wrapper for Koha::Patron->delete. (We do not want to bypass Koha::Patron
|
||||
and let DBIx do the job without further housekeeping.)
|
||||
NOTE: By default includes a move to deletedborrowers.
|
||||
|
||||
Return value (if relevant) is based on the individual return values.
|
||||
|
||||
=cut
|
||||
|
||||
sub delete {
|
||||
my ( $self ) = @_;
|
||||
my (@res, $rv);
|
||||
$rv = 1;
|
||||
while( my $patron = $self->next ) {
|
||||
$patron->move_to_deleted; # Needed here, since it is no default action..
|
||||
push @res, $patron->delete;
|
||||
$rv=-1 if $res[-1]==-1;
|
||||
$rv=0 if $rv==1 && $res[-1]==0;
|
||||
}
|
||||
|
||||
# Return -1 if we encountered a single -1
|
||||
# Return 0 if we encountered a single 0 (but not a -1)
|
||||
# Return 1 if all individual deletes passed
|
||||
return $rv;
|
||||
}
|
||||
|
||||
=head3 _type
|
||||
|
||||
=cut
|
||||
|
|
|
|||
|
|
@ -422,6 +422,19 @@ subtest "delete" => sub {
|
|||
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
|
||||
};
|
||||
|
||||
subtest 'Koha::Patrons->delete' => sub {
|
||||
plan tests => 3;
|
||||
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
|
||||
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
|
||||
my $id1 = $patron1->borrowernumber;
|
||||
my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }});
|
||||
is( $set->count, 2, 'Two patrons found as expected' );
|
||||
my $count1 = $schema->resultset('Deletedborrower')->count;
|
||||
is( $set->delete, 1, 'Two patrons deleted' );
|
||||
my $count2 = $schema->resultset('Deletedborrower')->count;
|
||||
is( $count2, $count1 + 2, 'Patrons moved to deletedborrowers' );
|
||||
};
|
||||
|
||||
subtest 'add_enrolment_fee_if_needed' => sub {
|
||||
plan tests => 4;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue