From fbd6c336ecb82f7a2e1aa2e8953276213085e1e6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 10 Feb 2021 12:09:19 +0000 Subject: [PATCH] Bug 14233: Add logging to notice create/update/delete This patch adds the call to logaction to record when a notice is added or changed. Test plan 1/ Add a new notice and check a corresponding line appears in the action_logs table. 2/ Update a notice and check that a corresponding line appears in the action_logs table. 3/ Signoff Signed-off-by: Kelly McElligott Signed-off-by: David Nind --- tools/letter.pl | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/tools/letter.pl b/tools/letter.pl index 20eb74771b..d651ca77c4 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,9 @@ sub add_validate { next; } elsif ( $letter and $letter->{message_transport_type} eq $mtt and $letter->{lang} eq $lang ) { + logaction( 'NOTICES', 'MODIFY', $letter->{id}, $letter->{content}, + 'Intranet' ) + unless ( $content eq $letter->{content} ); $dbh->do( q{ UPDATE letter @@ -326,11 +330,20 @@ 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'); } } # set up default display @@ -351,15 +364,19 @@ sub delete_confirm { sub delete_confirmed { my ($branchcode, $module, $code, $mtt, $lang) = @_; - C4::Letters::DelLetter( + my $letter = Koha::Notice::Templates->find( { - branchcode => $branchcode || '', - module => $module, - code => $code, - mtt => $mtt, - lang => $lang, + branchcode => $branchcode || '', + module => $module, + code => $code, + message_transport_type => $mtt, + lang => $lang, } ); + if ( $letter ) { + logaction('NOTICES', 'DELETE', $letter->id, $letter->content, 'Intranet'); + $letter->delete; + } # setup default display for screen default_display($branchcode); return; -- 2.20.1