From d5fdd1217c74757d6b3d374912b158912b0810d9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 8 Jun 2022 11:56:30 +0200 Subject: [PATCH] Bug 30904: (bug 24387 follow-up) Fix library modification of additional contents Modifying an existing element of additional content (News) by changing the library causes a duplication of the entry on the Additional contents (News) list. A subsequent attempt of deleting one of the entries results in deleting both of them. This is due to the fact that after the unwanted duplication all the entries share the same additional_contents.code. Test plan ========= 1. Create a piece of news under Tools > News. 2. After having saved it make a modification by changing the library. It should result in two rows in the table. 3. Delete one of the lines with Delete button. Both lines will disappear. 4. Apply the patch. 5. Repeat the steps 1 and 2. Only the one (the modified) entry should be present in the table. Signed-off-by: Lucas Gass Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- .../prog/en/modules/tools/additional-contents.tt | 1 + tools/additional-contents.pl | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt index 5b1ea8a746..05f315b81e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt @@ -183,6 +183,7 @@ +
  1. diff --git a/tools/additional-contents.pl b/tools/additional-contents.pl index cead55e9a1..c179cac7ef 100755 --- a/tools/additional-contents.pl +++ b/tools/additional-contents.pl @@ -82,6 +82,7 @@ elsif ( $op eq 'add_validate' ) { my $location = $cgi->param('location'); my $code = $cgi->param('code'); my $branchcode = $cgi->param('branchcode') || undef; + my $idnew = $cgi->param('idnew'); my @lang = $cgi->multi_param('lang'); @@ -92,6 +93,8 @@ elsif ( $op eq 'add_validate' ) { my $published_on = dt_from_string( scalar $cgi->param('published_on') ); my $number = $cgi->param('number'); + my $original_default = $idnew ? Koha::AdditionalContents->find($idnew) : undef; + my $success = 1; for my $lang ( sort {$a ne 'default'} @lang ) { # Process 'default' first my $title = $cgi->param( 'title_' . $lang ); @@ -100,7 +103,7 @@ elsif ( $op eq 'add_validate' ) { { category => $category, code => $code, - branchcode => $branchcode, + branchcode => $original_default ? $original_default->branchcode : $branchcode, lang => $lang, } ); -- 2.39.5