From 058884ed4f41e97d7bf0957156cf2a0b99bb33bf Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 7 Apr 2021 15:02:17 +0200 Subject: [PATCH] Bug 14233: Add logging support to notices and slips management This enhancements adds support for logging changes to notices and slips. Features include: - a system preference (NoticesLog) which allows you to enable logging changes for notices and slips - logging new notices, changes to notices, and deletion of notices - filtering in the log viewer so you can show all changes for a specific notice - a comparison feature, so you can see what changes were made to a notice. Test plan: 1/ Add some 'Notice' action logs by adding a new notice or updateing an existing notice 2/ Go to the 'Log viewer' under 'Tools' 3/ Note you can filter by 'Notices' 4/ Confirm the changes you made appear in the logs and that the 'Object' field links back to the updated notice ready for editing. 1/ Make some changes to at least two different notices to trigger logs 2/ Go to the 'Log viewer' from 'Tools' and filter on 'Notices' 3/ Note, you can now see the 'Compare' checkbox option for these logs 4/ Select the checkbox on one of the notices and note that the results are now filtered by that specific notice. 5/ Select a second checkbox to expose the option to 'View comparison' 6/ Click 'View comparison' to see the 'Diff view' of the two notices. Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- .../prog/en/modules/tools/viewlog.tt | 48 +++++++++++-------- tools/letter.pl | 41 ++++++++++++---- tools/viewlog.pl | 10 ++++ 3 files changed, 69 insertions(+), 30 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 97862f674b..a535488d26 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -96,6 +96,7 @@ [% CASE 'SEARCHENGINE' %]Search engine +[% CASE 'NOTICES' %]Notices[% UNLESS Koha.Preference('NoticesLog') %] [% END %] [% CASE %][% module | html %] [% END %] [% END %] @@ -190,7 +191,7 @@ [% ELSE %] [% END %] - [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'LETTER' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE' ] %] + [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'LETTER' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE', 'NOTICES' ] %] [% IF modules.grep(modx).size %] [% ELSE %] @@ -324,27 +325,27 @@ [% ELSE %] [% loopro.object | html %] [% END %] + [% ELSIF ( loopro.module == 'CATALOGUING' ) %] + [% IF ( loopro.info.substr(0, 4) == 'item' ) %] + Item [% loopro.object | html %] from + Biblio [% loopro.biblionumber | html %] + [% ELSIF ( loopro.info.substr(0, 6) == 'biblio' ) %] + Biblio [% loopro.object | html %] + [% ELSE %] + [% loopro.object | html %] + [% END %] + [% ELSIF ( loopro.module == 'SERIAL' ) %] + Subscription [% loopro.object | html %] + [% ELSIF ( loopro.module == 'AUTHORITIES' ) %] + Authority [% loopro.object | html %] + [% ELSIF ( loopro.module == 'NOTICES' ) %] + [% IF ( loopro.notice ) %] + Notice [% loopro.notice.title | html %] ([% loopro.notice.code | html %]) + [% ELSE %] + [% loopro.object | html %] + [% END %] [% ELSE %] - [% IF ( loopro.module == 'CATALOGUING' ) %] - [% IF ( loopro.info.substr(0, 4) == 'item' ) %] - Item [% loopro.object | html %] from - Biblio [% loopro.biblionumber | html %] - [% ELSIF ( loopro.info.substr(0, 6) == 'biblio' ) %] - Biblio [% loopro.object | html %] - [% ELSE %] - [% loopro.object | html %] - [% END %] - [% ELSE %] - [% IF ( loopro.module == 'SERIAL' ) %] - Subscription [% loopro.object | html %] - [% ELSE %] - [% IF ( loopro.module == 'AUTHORITIES' ) %] - Authority [% loopro.object | html %] - [% ELSE %] - [% loopro.object | html %] - [% END %] - [% END %] - [% END %] + [% loopro.object | html %] [% END %] @@ -356,6 +357,11 @@
+ [% ELSIF loopro.module == "NOTICES" %] +
[% loopro.info | trim | html %]
+
+ +
[% ELSE %]
[% loopro.info | html %] diff --git a/tools/letter.pl b/tools/letter.pl index 20eb74771b..faf80e7d39 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -46,6 +46,7 @@ use C4::Auth; use C4::Context; use C4::Output; use C4::Letters; +use C4::Log; use Koha::Patron::Attribute::Types; @@ -315,6 +316,10 @@ sub add_validate { next; } elsif ( $letter and $letter->{message_transport_type} eq $mtt and $letter->{lang} eq $lang ) { + logaction( 'NOTICES', 'MODIFY', $letter->{id}, $content, + 'Intranet' ) + if ( C4::Context->preference("NoticesLog") + && $content ne $letter->{content} ); $dbh->do( q{ UPDATE letter @@ -326,11 +331,22 @@ sub add_validate { $branchcode, $oldmodule, $code, $mtt, $lang ); } else { - $dbh->do( - q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type, lang) VALUES (?,?,?,?,?,?,?,?,?)}, - undef, - $branchcode || '', $module, $code, $name, $is_html || 0, $title, $content, $mtt, $lang - ); + my $letter = Koha::Notice::Template->new( + { + branchcode => $branchcode, + module => $module, + code => $code, + name => $name, + is_html => $is_html, + title => $title, + content => $content, + message_transport_type => $mtt, + lang => $lang + } + )->store; + logaction( 'NOTICES', 'CREATE', $letter->id, $letter->content, + 'Intranet' ) + if C4::Context->preference("NoticesLog"); } } # set up default display @@ -350,16 +366,23 @@ sub delete_confirm { } sub delete_confirmed { - my ($branchcode, $module, $code, $mtt, $lang) = @_; - C4::Letters::DelLetter( + my ( $branchcode, $module, $code, $mtt, $lang ) = @_; + my $letters = Koha::Notice::Templates->search( { branchcode => $branchcode || '', module => $module, code => $code, - mtt => $mtt, - lang => $lang, + ( $mtt ? ( message_transport_type => $mtt ) : () ), + ( $lang ? ( lang => $lang ) : () ), } ); + while ( my $letter = $letters->next ) { + logaction( 'NOTICES', 'DELETE', $letter->id, $letter->content, + 'Intranet' ) + if C4::Context->preference("NoticesLog"); + $letter->delete; + } + # setup default display for screen default_display($branchcode); return; diff --git a/tools/viewlog.pl b/tools/viewlog.pl index b58dcbacac..e67e911c40 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -186,6 +186,16 @@ if ($do_it) { } } } + + if ( $log->module eq 'NOTICES' ) { + if ( $log->object ) { + my $notice = Koha::Notice::Templates->find( { id => $log->object } ); + if ($notice && $output eq 'screen') { + $result->{notice} = $notice->unblessed; + } + } + } + push @data, $result; } if ( $output eq "screen" ) { -- 2.39.5