From 235e73e908a602b58565ce6fa37368b9336e5275 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 3 Jan 2022 11:31:54 +0100 Subject: [PATCH] Bug 29778: Prevent orphan additional contents When deleting a content, only the main one (lang="default") is removed, which leads to orphan contents in the DB that are still displayed on the UI. Test plan: 0. Don't apply this patch 1. Create some contents, translate them in different languages 2. Delete some of them => Note that they are still displayed on the UI and that the entries with lang!="default" are still in the DB 3. Apply this patch 4. Repeat 1 5. Run updatedatabase 6. Delete from of the contents => Note that the orphan entries created before you applied the patch have been removed and that the "delete" behaviour is now working correnctly. Signed-off-by: Lucas Gass Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall --- installer/data/mysql/atomicupdate/bug_29778.pl | 18 ++++++++++++++++++ tools/additional-contents.pl | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_29778.pl diff --git a/installer/data/mysql/atomicupdate/bug_29778.pl b/installer/data/mysql/atomicupdate/bug_29778.pl new file mode 100755 index 0000000000..c8f25e7c90 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_29778.pl @@ -0,0 +1,18 @@ +use Modern::Perl; + +return { + bug_number => "29778", + description => "Delete orphan additional contents", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + $dbh->do(q{ + DELETE FROM additional_contents + WHERE code NOT IN ( + SELECT code + FROM additional_contents + WHERE lang = "default" + ); + }); + }, +} diff --git a/tools/additional-contents.pl b/tools/additional-contents.pl index e63a44a809..d5d02f00c9 100755 --- a/tools/additional-contents.pl +++ b/tools/additional-contents.pl @@ -204,12 +204,12 @@ elsif ( $op eq 'delete_confirmed' ) { my $contents = Koha::AdditionalContents->search( { idnew => \@ids } ); - if ( C4::Context->preference("NewsLog") ) { - while ( my $c = $contents->next ) { + while ( my $c = $contents->next ) { + Koha::AdditionalContents->search( { code => $c->code } )->delete; + if ( C4::Context->preference("NewsLog") ) { logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $c->code, $c->title, $c->lang, $c->content)); } } - $contents->delete; } ); }; -- 2.39.5