From 70a56449bf34058aa06677ae5dd8718f3ac09be9 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 17 Nov 2021 10:27:38 +0000 Subject: [PATCH] Bug 29495: Add code level constraint replacement This patch adds a check in Koha::Checkouts::ReturnClaim::store to replace the database level foreign key check. Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Tomas Cohen Arazi Signed-off-by: Fridolin Somers --- Koha/Checkouts/ReturnClaim.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Koha/Checkouts/ReturnClaim.pm b/Koha/Checkouts/ReturnClaim.pm index 3488e51626..b8569beea5 100644 --- a/Koha/Checkouts/ReturnClaim.pm +++ b/Koha/Checkouts/ReturnClaim.pm @@ -53,6 +53,16 @@ sub store { Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy->throw(); } + unless ( !$self->issue_id + || Koha::Checkouts->find( $self->issue_id ) + || Koha::Old::Checkouts->find( $self->issue_id ) ) + { + Koha::Exceptions::Object::FKConstraint->throw( + error => 'Broken FK constraint', + broken_fk => 'issue_id' + ); + } + return $self->SUPER::store; } -- 2.39.5