From 25293ce9c84bfcd4d735fd6e3fad51c19acaab70 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 17 Nov 2021 10:27:38 +0000 Subject: [PATCH] [21.05.x] 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 --- 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.35.1