From 56e393b57091b3bbf8cfc5271e028d753f4b2c2d Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 15 Dec 2022 16:10:55 +0100 Subject: [PATCH] Bug 32426: [DO NOT PUSH] Introduce example plugin RM: Do not push this patch! A very simple plugin; it just returns the borrowers.email field, assuming that you made this field mandatory. It should check uniqueness, provide an alternative; for simplicity that is not included here. Test plan: NOTE: Some unit tests may fail when applying this patch/installing this plugin. That's no problem; this example plugin just serves as POC. Install the plugin. You could just run: * perl -MKoha::Plugin::Example::Userid_email -e"Koha::Plugin::Example::Userid_email->new->install" Run t/db_dependent/Koha/Patron_generate_userid.t. This should pass. Enter a new patron via OPAC self registration; try existing and new email address. Toggle PatronSelfRegistrationVerifyByEmail. Try again (existing, new). Go to staff memberentry page. Add new patron with new email address. (Leave userid empty.) Verify the newly generated userid after saving. Try to add another patron with the same email. You should see an alert. Edit an existing patron. Try new and existing email address. When editing, clear userid and save. Check result. Uninstall the plugin. * perl -MKoha::Plugin::Example::Userid_email -e"Koha::Plugin::Example::Userid_email->new->uninstall" Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- Koha/Plugin/Example/Userid_email.pm | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Koha/Plugin/Example/Userid_email.pm diff --git a/Koha/Plugin/Example/Userid_email.pm b/Koha/Plugin/Example/Userid_email.pm new file mode 100644 index 0000000000..62d683adeb --- /dev/null +++ b/Koha/Plugin/Example/Userid_email.pm @@ -0,0 +1,55 @@ +package Koha::Plugin::Example::Userid_email; + +# Limited test implementation of patron_generate_userid, returning borrowers.email. + +use Modern::Perl; +use parent qw/Koha::Plugins::Base/; +use C4::Context; + +our $VERSION = 1.00; +our $metadata = { version => $VERSION }; + +=pod + +=head1 METHODS + +=head2 new + +=cut + +sub new { + my ( $class, $args ) = @_; + $args //= {}; + return $class->SUPER::new({ %$args, metadata => $metadata }); +} + +=head2 install + +=cut + +sub install { + my ( $self ) = shift; + C4::Context->dbh->do( "INSERT IGNORE INTO plugin_methods (plugin_class, plugin_method) VALUES (?,?)", undef, __PACKAGE__, 'patron_generate_userid' ); +} + +=head2 uninstall + +=cut + +sub uninstall { + my ( $self ) = shift; + C4::Context->dbh->do( "DELETE FROM plugin_data WHERE plugin_class=?", undef, __PACKAGE__ ); + C4::Context->dbh->do( "DELETE FROM plugin_methods WHERE plugin_class=?", undef, __PACKAGE__ ); +} + +=head2 patron_generate_userid + +=cut + +sub patron_generate_userid { +#TODO This c/should be extended with verification (uniqueness), etc. + my ($self, $params) = @_; + return $params->{patron}->email; +} + +1; -- 2.39.2