@@ -, +, @@ patron --- Koha/Patron.pm | 5 +++++ t/db_dependent/Koha/Patrons.t | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -42,6 +42,7 @@ use Koha::Patron::Categories; use Koha::Patron::HouseboundProfile; use Koha::Patron::HouseboundRole; use Koha::Patron::Images; +use Koha::Patron::Modifications; use Koha::Patron::Relationships; use Koha::Patrons; use Koha::Plugins; @@ -383,6 +384,10 @@ sub delete { # FIXME Could be $patron->get_lists $_->delete for Koha::Virtualshelves->search( { owner => $self->borrowernumber } ); + # We cannot have a FK on borrower_modifications.borrowernumber, the table is also used + # for patron selfreg + $_->delete for Koha::Patron::Modifications->search( { borrowernumber => $self->borrowernumber } ); + $self->SUPER::delete; logaction( "MEMBERS", "DELETE", $self->borrowernumber, "" ) if C4::Context->preference("BorrowersLog"); --- a/t/db_dependent/Koha/Patrons.t +++ a/t/db_dependent/Koha/Patrons.t @@ -466,7 +466,7 @@ subtest "move_to_deleted" => sub { }; subtest "delete" => sub { - plan tests => 6; + plan tests => 7; t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); my $patron = $builder->build( { source => 'Borrower' } ); my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); @@ -480,6 +480,7 @@ subtest "delete" => sub { value => { owner => $patron->{borrowernumber} } } ); + my $modification = $builder->build_object({ class => 'Koha::Patron::Modifications', value => { borrowernumber => $patron->{borrowernumber} } }); my $deleted = $retrieved_patron->delete; is( ref($deleted), 'Koha::Patron', 'Koha::Patron->delete should return the deleted patron object if the patron has been correctly deleted' ); @@ -492,6 +493,8 @@ subtest "delete" => sub { is( Koha::Virtualshelves->search( { owner => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's lists| ); + is( Koha::Patron::Modifications->search( { borrowernumber => $patron->{borrowernumber} } )->count, 0, q|Koha::Patron->delete should have deleted patron's modifications| ); + my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'DELETE', object => $retrieved_patron->borrowernumber } )->count; is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); }; --