From 036584acf6d70af40741f0477ad28f9f641ee5ec Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 18 Aug 2021 17:58:38 +0200 Subject: [PATCH] Bug 28717: Fix additional content logs The logging for additional contents added by bug 26205 has been broken by but 22544. This patch is a revisited version as bug 24387 has been pushed. It does not log MODIFY if no modification has been made on a template (useful when only 1 version/lang of a content has been modified) Test plan: Turn on NewsLog Add/modify and delete additional contents/News and confirm that modification are logged. --- .../prog/en/modules/tools/viewlog.tt | 2 +- tools/additional-contents.pl | 32 +++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt index 3b0886d3690..6ea33bed706 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -362,7 +362,7 @@ [% IF ( loopro.module == 'CIRCULATION' ) %] Item [% loopro.barcode | html %] [% ELSE %] - [% IF loopro.module == "SYSTEMPREFERENCE" || loopro.module == "REPORTS" || loopro.module == "OPACNEWS" %] + [% IF loopro.module == "SYSTEMPREFERENCE" || loopro.module == "REPORTS" || loopro.module == "NEWS" %]
[% loopro.info | trim | html %]
diff --git a/tools/additional-contents.pl b/tools/additional-contents.pl index e4a409cb688..7a10bebf137 100755 --- a/tools/additional-contents.pl +++ b/tools/additional-contents.pl @@ -27,6 +27,7 @@ use CGI qw ( -utf8 ); use C4::Auth qw(get_template_and_user); use C4::Koha; use C4::Context; +use C4::Log qw( logaction ); use C4::Output qw(output_html_with_http_headers); use C4::Languages qw(getTranslatedLanguages); use Koha::DateUtils; @@ -119,10 +120,12 @@ elsif ( $op eq 'add_validate' ) { # Delete if title or content is empty unless ( $title and $content ) { $additional_content->delete if $additional_content; + logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $additional_content->code, $additional_content->title, $additional_content->lang, $additional_content->content)); next; } elsif ( $additional_content ) { + my $updated; eval { - $additional_content->update( + $additional_content->set( { category => $category, code => $code, @@ -137,12 +140,17 @@ elsif ( $op eq 'add_validate' ) { borrowernumber => $borrowernumber, } ); + $updated = $additional_content->_result->get_dirty_columns; + $additional_content->store; }; if ($@) { $success = 0; push @messages, { type => 'error', code => 'error_on_update' }; last; } + + logaction('NEWS', 'MODIFY' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content)) + if C4::Context->preference("NewsLog") && $updated; } else { my $additional_content = Koha::AdditionalContent->new( @@ -166,6 +174,9 @@ elsif ( $op eq 'add_validate' ) { push @messages, { type => 'error', code => 'error_on_insert' }; last; } + + logaction('NEWS', 'ADD' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content)) + if C4::Context->preference("NewsLog"); } } @@ -173,8 +184,23 @@ elsif ( $op eq 'add_validate' ) { } elsif ( $op eq 'delete_confirmed' ) { my @ids = $cgi->multi_param('ids'); - my $deleted = - eval { Koha::AdditionalContents->search( { idnew => @ids } )->delete; }; + my $deleted = eval { + + my $schema = Koha::Database->new->schema; + $schema->txn_do( + sub { + my $contents = + Koha::AdditionalContents->search( { idnew => @ids } ); + + if ( C4::Context->preference("NewsLog") ) { + while ( my $c = $contents->next ) { + logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $c->code, $c->title, $c->lang, $c->content)); + } + } + $contents->delete; + } + ); + }; if ( $@ or not $deleted ) { push @messages, { type => 'error', code => 'error_on_delete' }; -- 2.25.1