From 3757953b5b14fb20a61724d1eb01abdbd540d446 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: Andrew Fuerste-Henry (cherry picked from commit f0fac71bbd8f073a5836f88402d20aa67175195b) Signed-off-by: Victor Grousset/tuxayo --- Koha/Checkouts/ReturnClaim.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Koha/Checkouts/ReturnClaim.pm b/Koha/Checkouts/ReturnClaim.pm index 624c725949..78341e629a 100644 --- a/Koha/Checkouts/ReturnClaim.pm +++ b/Koha/Checkouts/ReturnClaim.pm @@ -52,6 +52,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