From 75c5c6a3d305532441a283b30f7a6dfa68274b3a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 23 Oct 2024 12:04:02 +0200 Subject: [PATCH] Bug 38136: Return '404 Not Found' when trying to delete a non-existent translation --- svc/localization | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/svc/localization b/svc/localization index 15e78030b06..825e9d51870 100755 --- a/svc/localization +++ b/svc/localization @@ -3,10 +3,12 @@ use Modern::Perl; use Encode qw( encode ); use Try::Tiny; +use JSON qw( to_json ); use C4::Service; use Koha::Caches; use Koha::Database; +use C4::Output qw( output_with_http_headers ); our ( $query, $response ) = C4::Service->init( parameters => 'manage_itemtypes' ); @@ -84,6 +86,13 @@ sub delete_translation { my $row = $schema->resultset($source)->find($object_id); if ($row && $row->can('localizations')) { my $localization = $row->localizations->find($localization_id); + + unless ( $localization ) { + my $json = to_json ( { errors => 'Not found' } ); + output_with_http_headers $query, undef, $json, 'js', '404 Not Found'; + exit; + } + if ($localization) { $localization->delete(); Koha::Caches->get_instance('localization')->clear_from_cache("$source:" . $localization->lang); -- 2.34.1