From 7e658ecbc07dfc7835158a2e079bf2bf4b46a530 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 21 Dec 2023 23:05:19 +0000 Subject: [PATCH] Bug 35597: logaction when modifying or deleteing suggestions To test: 1. Apply patch, restart services, updatedatabase 2. Search for the system preference 'SuggestionsLog', it should be off. Turn it on. 3. Create a purhase suggestion 4. Go to Tools > Log viewer. In modules check 'Suggestions' 5. You should see your newly created suggestion. 6. Modify the suggestion and check the logs again, the modification should be logged. 7. Delete the suggestion, the deletion should be logged. 8. Do a purchase suggestion via the OPAC. 9. Check the logs to see the newly created suggestion, the interface should be OPAC. 10. Turn of SuggestionsLog 11. No changes of any kind should be logged. Signed-off-by: Owen Leonard Signed-off-by: Ray Delahunty Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- C4/Suggestions.pm | 7 +++++++ Koha/Suggestion.pm | 5 ++++- .../data/mysql/atomicupdate/bug_35597.pl | 19 +++++++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/logs.pref | 6 ++++++ .../prog/en/modules/tools/viewlog.tt | 5 ++++- 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_35597.pl diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index 14c6b203c1..fae1c650a3 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -27,6 +27,7 @@ use C4::Letters; use C4::Biblio qw( GetMarcFromKohaField ); use Koha::DateUtils qw( dt_from_string ); use Koha::Suggestions; +use C4::Log qw(logaction); use base qw(Exporter); @@ -290,6 +291,9 @@ sub ModSuggestion { ) or warn "can't enqueue letter $letter"; } } + if (C4::Context->preference("SuggestionsLog")) { + logaction('SUGGESTION', 'MODIFY', $suggestion->{suggestionid}, $suggestion_object ); + } return 1; # No useful if the exception is raised earlier } @@ -343,6 +347,9 @@ sub DelSuggestion { }; $sth = $dbh->prepare($queryDelete); my $suggestiondeleted = $sth->execute($suggestionid); + if (C4::Context->preference("SuggestionsLog")) { + logaction('SUGGESTION', 'DELETE', $suggestionid, '' ); + } return $suggestiondeleted; } } diff --git a/Koha/Suggestion.pm b/Koha/Suggestion.pm index b14c1123ca..a6dd307671 100644 --- a/Koha/Suggestion.pm +++ b/Koha/Suggestion.pm @@ -28,6 +28,7 @@ use Koha::DateUtils qw( dt_from_string ); use Koha::Patrons; use Koha::AuthorisedValues; use Koha::Exceptions::Suggestion; +use C4::Log qw(logaction); use base qw(Koha::Object); @@ -111,7 +112,9 @@ sub store { ) or warn "can't enqueue letter $letter"; } } - + if (C4::Context->preference("NewsLog")) { + logaction('SUGGESTION', 'CREATE', $result->suggestionid, '' ); + } return $result; } diff --git a/installer/data/mysql/atomicupdate/bug_35597.pl b/installer/data/mysql/atomicupdate/bug_35597.pl new file mode 100755 index 0000000000..3101b2fcc8 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_35597.pl @@ -0,0 +1,19 @@ +use Modern::Perl; + +return { + bug_number => "35597", + description => "Add SuggestionsLog system preference ", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + # sysprefs + $dbh->do( + q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) + VALUES ('SuggestionsLog', '0', 'If enabled, log purchase suggestion changes', '' , 'YesNo') + } + ); + say $out "Added new system preference 'SuggestionsLog'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index d6a450e514..df70c69def 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -755,6 +755,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('SubscriptionLog','1',NULL,'If ON, enables subscriptions log','YesNo'), ('suggestion','1','','If ON, enables patron suggestions feature in OPAC','YesNo'), ('suggestionPatronCategoryExceptions', '', '', 'List the patron categories not affected by suggestion system preference if on', 'Free'), +('SuggestionsLog','0',NULL,'If ON, log pirchase suggestion changes','YesNo'), ('SuspendHoldsIntranet','1','Allow holds to be suspended from the intranet.',NULL,'YesNo'), ('SuspendHoldsOpac','1','Allow holds to be suspended from the OPAC.',NULL,'YesNo'), ('SuspensionsCalendar','noSuspensionsWhenClosed','ignoreCalendar|noSuspensionsWhenClosed','Specify whether to use the Calendar in calculating suspension expiration','Choice'), 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 f947270dde..985089a9ac 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 @@ -114,6 +114,12 @@ Logging: 1: Log 0: "Don't log" - any actions on recalls (create, cancel, expire, fulfill). + - + - pref: SuggestionsLog + choices: + 1: Log + 0: "Don't log" + - any changes to purchase suggestions (create, modify, delete ). Debugging: - 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 7c10c55b65..10b65cfdb3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -101,6 +101,7 @@ [% CASE 'NOTICES' %]Notices[% UNLESS Koha.Preference('NoticesLog') %] [% END %] [% CASE 'NEWS' %]News[% UNLESS Koha.Preference('NewsLog') %] [% END %] [% CASE 'RECALLS' %]Recalls[% UNLESS Koha.Preference('RecallsLog') %] [% END %] +[% CASE 'SUGGESTION' %]Suggestions[% UNLESS Koha.Preference('SuggestionsLog') %] [% END %] [% CASE %][% module | html %] [% END %] @@ -221,7 +222,7 @@ [% ELSE %] [% END %] - [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'CLAIMS' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE', 'NOTICES', 'NEWS', 'RECALLS' ] %] + [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'CLAIMS' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE', 'NOTICES', 'NEWS', 'RECALLS', 'SUGGESTION' ] %] [% IF modules.grep(modx).size %] [% ELSE %] @@ -387,6 +388,8 @@ [% ELSE %] Basket [% loopro.object | html %] [% END %] + [% ELSIF ( loopro.module == "SUGGESTION" ) %] + [% loopro.object | html %] [% ELSE %] [% loopro.object | html %] [% END %] -- 2.39.5