From 305df49ecf494ac7dcbfcb927b5283440d0de5d9 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Wed, 12 May 2021 18:20:16 +0000 Subject: [PATCH] Bug 26205: Add logging of news items To test: 1. Apply patch, updatedatabase, restart_all 2. Make sure the system pref 'NewsLog' is turned on. 3. Go to the Koha News tool and create a new news item. 4. View the logs and display only the OPAC News module 5. You should see your new news, it will include the lang ( OPACheader_en ) and the content of the news item. 6. Filter the logs so the only action is 'Add', your new news item should appear 7. Modify some news items 8. They should appear in the logs now as modification. 9. Make sure you can filter the action to 'Modify' and can confirm it works 10. Delete some news items 11. They should appear in the logs now as deletinon 12. Make sure you can filter the action to 'Delete' and can confirm it works Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- C4/NewsChannels.pm | 22 +++++++++++++++++++ .../bug_26205_add_newslog_system_pref.perl | 7 ++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/logs.pref | 7 +++++- .../prog/en/modules/tools/viewlog.tt | 5 +++-- 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_26205_add_newslog_system_pref.perl diff --git a/C4/NewsChannels.pm b/C4/NewsChannels.pm index 7c9df5b2e5..28a2d6074d 100644 --- a/C4/NewsChannels.pm +++ b/C4/NewsChannels.pm @@ -21,6 +21,8 @@ package C4::NewsChannels; use Modern::Perl; use C4::Context; use Koha::DateUtils; +use C4::Log qw(logaction); +use Koha::News; use vars qw(@ISA @EXPORT); @@ -68,6 +70,11 @@ sub add_opac_new { my $sth = $dbh->prepare("INSERT INTO opac_news ( $field_string ) VALUES ( $values_string )"); $sth->execute(@values); $retval = 1; + + #log the NEW OPAC news entry + if (C4::Context->preference("NewsLog")) { + logaction('OPACNEWS', 'ADD' , undef, $href_entry->{lang} . ' | ' . $href_entry->{content}); + } } return $retval; } @@ -108,12 +115,26 @@ sub upd_opac_new { $sth->execute(@values); $retval = 1; } + + #log new OPAC news modification + if (C4::Context->preference("NewsLog")) { + logaction('OPACNEWS', 'MODIFY' , undef, $href_entry->{lang} . ' | ' . $href_entry->{content}); + } return $retval; } sub del_opac_new { my ($ids) = @_; if ($ids) { + + #log new OPAC news deletion + if (C4::Context->preference("NewsLog")) { + foreach my $newsid ( split(/,/, $ids )) { + my $n = Koha::News->find( $newsid ); + logaction('OPACNEWS', 'DELETE', undef, $n->unblessed->{lang} . ' | ' . $n->unblessed->{content} ); + } + } + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("DELETE FROM opac_news WHERE idnew IN ($ids)"); $sth->execute(); @@ -121,6 +142,7 @@ sub del_opac_new { } else { return 0; } + } sub get_opac_new { diff --git a/installer/data/mysql/atomicupdate/bug_26205_add_newslog_system_pref.perl b/installer/data/mysql/atomicupdate/bug_26205_add_newslog_system_pref.perl new file mode 100644 index 0000000000..2ffbb93231 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_26205_add_newslog_system_pref.perl @@ -0,0 +1,7 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('NewsLog', '0', 'If enabled, log OPAC News changes', '', 'YesNo'); | ); + + # Always end with this (adjust the bug info) + NewVersion( $DBversion, 26205, "Log OPAC News changes"); +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 0a86168ee0..3430bc26e7 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -348,6 +348,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('minPasswordLength','8',NULL,'Specify the minimum length of a patron/staff password','free'), ('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''), ('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'), +('NewsLog','0',NULL,'If ON, log OPAC news changes','YesNo'), ('NewsToolEditor','tinymce','tinymce|codemirror','Choose tool for editing News.', 'Choice'), ('noissuescharge','5','','Define maximum amount withstanding before checkouts are blocked','Integer'), ('NoIssuesChargeGuarantees','','','Define maximum amount withstanding before checkouts are blocked','Integer'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref index dd062935f4..5f04124ec8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref @@ -102,7 +102,12 @@ Logging: on: Log off: "Don't log" - " changes to notice templates." - + - + - pref: NewsLog + choices: + on: Log + off: "Don't log" + - " changes to OPAC news" Debugging: - - pref: DumpTemplateVarsIntranet 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 9760ba6c40..444991761d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -95,6 +95,7 @@ [% CASE 'SEARCHENGINE' %]Search engine [% CASE 'NOTICES' %]Notices[% UNLESS Koha.Preference('NoticesLog') %] [% END %] +[% CASE 'OPACNEWS' %]OPAC News[% UNLESS Koha.Preference('NewsLog') %] [% END %] [% CASE %][% module | html %] [% END %] [% END %] @@ -200,7 +201,7 @@ [% ELSE %] [% END %] - [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'CLAIMS' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE', 'NOTICES' ] %] + [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'CLAIMS' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE', 'NOTICES', 'OPACNEWS' ] %] [% IF modules.grep(modx).size %] [% ELSE %] @@ -361,7 +362,7 @@ [% IF ( loopro.module == 'CIRCULATION' ) %] Item [% loopro.barcode | html %] [% ELSE %] - [% IF loopro.module == "SYSTEMPREFERENCE" || loopro.module == "REPORTS" %] + [% IF loopro.module == "SYSTEMPREFERENCE" || loopro.module == "REPORTS" || loopro.module == "OPACNEWS" %]
[% loopro.info | trim | html %]
-- 2.39.5