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 <oleonard@myacpl.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Lucas Gass 2021-05-12 18:20:16 +00:00 committed by Kyle M Hall
parent 7fef05b641
commit 305df49ecf
5 changed files with 39 additions and 3 deletions

View file

@ -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 {

View file

@ -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");
}

View file

@ -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'),

View file

@ -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

View file

@ -95,6 +95,7 @@
[% CASE 'SEARCHENGINE' %]Search engine
[% CASE 'NOTICES' %]Notices[% UNLESS Koha.Preference('NoticesLog') %] <i class="fa fa-warning" title="Log not enabled"></i>[% END %]
[% CASE 'OPACNEWS' %]OPAC News[% UNLESS Koha.Preference('NewsLog') %] <i class="fa fa-warning" title="Log not enabled"></i>[% END %]
[% CASE %][% module | html %]
[% END %]
[% END %]
@ -200,7 +201,7 @@
[% ELSE %]
<label for="moduleALL" class="viewlog"><input type="checkbox" id="moduleALL" name="modules" value=""> All</label>
[% 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 %]
<label for="module[% modx | html %]" class="viewlog"><input type="checkbox" id="module[% modx | html %]" name="modules" value="[% modx | html %]" checked="checked"> [% PROCESS translate_log_module module=modx %]</label>
[% ELSE %]
@ -361,7 +362,7 @@
[% IF ( loopro.module == 'CIRCULATION' ) %]
<a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% loopro.info | uri %]&amp;biblionumber=[% loopro.biblionumber | uri %]&amp;bi=[% loopro.biblioitemnumber | uri %]#item[% loopro.info | uri %]" title="Display detail for this item">Item [% loopro.barcode | html %]</a>
[% ELSE %]
[% IF loopro.module == "SYSTEMPREFERENCE" || loopro.module == "REPORTS" %]
[% IF loopro.module == "SYSTEMPREFERENCE" || loopro.module == "REPORTS" || loopro.module == "OPACNEWS" %]
<div class="loginfo" id="loginfo[% loopro.action_id | html %]">[% loopro.info | trim | html %]</div>
<div class="compare_info" id="compare_info[% loopro.action_id | html %]">
<label><input type="checkbox" name="diff" id="action_id[% loopro.action_id | html %]" data-actionid="[% loopro.action_id | html %]" data-filter="[% FOREACH info IN loopro.info.split(' \| ') %][% IF loop.first %][% info | html %][% END %][% END %]" class="compare" /> Compare</label>