From c71d696a5e55646837291e46ec0821537250da07 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 30 Aug 2023 16:49:58 +0200 Subject: [PATCH] Bug 31503: DO NOT PUSH - Add example plugin Test plan: Run perl -MKoha::Plugin::Test_Newsletter -e"Koha::Plugin::Test_Newsletter->new->install" Enable OPACCustomConsentTypes. Test consenting and refusing consent on OPAC account page. Run perl -MKoha::Plugin::Test_Newsletter -e"Koha::Plugin::Test_Newsletter->new->uninstall" Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- Koha/Plugin/Test_Newsletter.pm | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Koha/Plugin/Test_Newsletter.pm diff --git a/Koha/Plugin/Test_Newsletter.pm b/Koha/Plugin/Test_Newsletter.pm new file mode 100644 index 00000000000..5030660e14b --- /dev/null +++ b/Koha/Plugin/Test_Newsletter.pm @@ -0,0 +1,55 @@ +package Koha::Plugin::Test_Newsletter; + +#Implements patron_consent_type plugin. + +use Modern::Perl; +use C4::Context; + +use parent qw/Koha::Plugins::Base/; + +use constant CONSENT_TYPE => 'NEWSLETTER'; + +our $VERSION = 1.00; +our $metadata = { version => $VERSION }; + +my $consent_info = { + title => { + 'en' => q|Newsletter|, + }, + description => { + 'en' => + q|We would be happy to regularly send you a newsletter by email about our library services and activities.|, + }, +}; + +sub new { + my ( $class, $params ) = @_; + $params->{metadata} = $metadata; + $params->{metadata}->{name} = $class; + return $class->SUPER::new($params); +} + +sub install { + my ($self) = shift; + C4::Context->dbh->do( + "INSERT IGNORE INTO plugin_methods (plugin_class, plugin_method) VALUES (?,?)", + undef, + ref $self, + 'patron_consent_type' + ); + return 1; +} + +sub uninstall { + my ($self) = @_; + C4::Context->dbh->do( "DELETE FROM plugin_data WHERE plugin_class LIKE ?", undef, ref $self ); + C4::Context->dbh->do( "DELETE FROM plugin_methods WHERE plugin_class LIKE ?", undef, ref $self ); + return 1; +} + +sub patron_consent_type { + my ($self) = @_; + return [ CONSENT_TYPE, $consent_info ]; +} + +1; -- 2.41.0