From 5bc75d3ffff6216e3575c4d17b4a967662012971 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Fri, 16 Jul 2021 16:00:44 +0000 Subject: [PATCH] Bug 28717: Add logging logic to koha-news.pl To test: 1. have some news items 2. make sure NewsLog is turned on 3. Add, modify, and delete some news 4. Check the action logs, nothing is logged 5. Apply patch 6. do step 3 again 7. now changes should be logged 8. make sure you try deleting multiple news items at once and confirm that all deletions are logged --- .../prog/en/modules/tools/viewlog.tt | 2 +- tools/koha-news.pl | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 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 3b0886d369..6ea33bed70 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/koha-news.pl b/tools/koha-news.pl index fa8db8913f..c46c0b0581 100755 --- a/tools/koha-news.pl +++ b/tools/koha-news.pl @@ -32,6 +32,7 @@ use C4::Languages qw(getTranslatedLanguages); use Date::Calc qw/Date_to_Days Today/; use Koha::DateUtils; use Koha::News; +use C4::Log qw(logaction); my $cgi = CGI->new; @@ -117,6 +118,10 @@ elsif ( $op eq 'add' ) { branchcode => $branchcode, borrowernumber => $borrowernumber, })->store; + #log news addition + if (C4::Context->preference("NewsLog")) { + logaction('NEWS', 'ADD' , undef, $lang . ' | ' . $content); + } print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl"); } else { @@ -136,11 +141,22 @@ elsif ( $op eq 'edit' ) { branchcode => $branchcode, })->store; } + #log news modification + if (C4::Context->preference("NewsLog")) { + logaction('NEWS', 'MODIFY' , undef, $lang . ' | ' . $content); + } print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl"); } elsif ( $op eq 'del' ) { my @ids = $cgi->multi_param('ids'); - Koha::News->search({ idnew => \@ids })->delete; + #log news deletion then delete it + if (C4::Context->preference("NewsLog")) { + foreach my $newsid ( @ids ) { + my $n = Koha::News->find( $newsid ); + logaction('NEWS', 'DELETE', undef, $n->lang . ' | ' . $n->content ); + } + } + Koha::News->search({ idnew => @ids })->delete; print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl"); } -- 2.20.1