Skip to content

Commit

Permalink
Merge branch 'add-welcome-option' into 22.11-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaudGLT committed Oct 3, 2023
2 parents 76b95f5 + 61612d2 commit adbfaab
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
12 changes: 9 additions & 3 deletions Koha/Plugin/Com/Biblibre/PatronImport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use Mojo::JSON qw(decode_json);;
use base qw(Koha::Plugins::Base);


our $VERSION = '2.0';
our $VERSION = '2.1';

our $metadata = {
name => 'Patron import',
author => 'Alex Arnaud <alex.arnaud@biblibre.com>',
description => 'A tool for importing patrons into Koha',
date_authored => '2019-07-02',
date_updated => '2019-07-02',
minimum_version => '20.11',
date_updated => '2023-07-27',
minimum_version => '22.11',
maximum_version => '',
version => $VERSION,
};
Expand Down Expand Up @@ -242,6 +242,7 @@ sub install {
type varchar(255) COLLATE utf8_unicode_ci NOT NULL,
createonly tinyint COLLATE utf8_unicode_ci NULL,
autocardnumber varchar(20) COLLATE utf8_unicode_ci NULL,
welcome_message tinyint COLLATE utf8_unicode_ci NULL,
clear_logs INT(5) COLLATE utf8_unicode_ci NULL,
flow_settings text COLLATE utf8_unicode_ci NULL,
plugins_enabled text COLLATE utf8_unicode_ci NULL,
Expand Down Expand Up @@ -605,6 +606,11 @@ sub upgrade {
");
}

if ($DBversion < '2.1') {
my $import_table = $self->get_qualified_table_name('import');
$dbh->do("ALTER TABLE $import_table ADD COLUMN welcome_message tinyint COLLATE utf8_unicode_ci NULL;");
}

$self->store_data({'__INSTALLED_VERSION__' => $VERSION});

return 1;
Expand Down
3 changes: 3 additions & 0 deletions Koha/Plugin/Com/Biblibre/PatronImport/Controller/Import.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sub edit {
my $type = $cgi->param('type');
my $createonly = $cgi->param('createonly') ? 1 : 0;
my $autocardnumber = $cgi->param('autocardnumber');
my $welcome_message = $cgi->param('welcome_message') ? 1 : 0;
my $clear_logs = $cgi->param('clear_log_older_than');
my $flow_settings = _handle_flow_settings($cgi);

Expand All @@ -54,6 +55,7 @@ sub edit {
type => $type,
createonly => $createonly,
autocardnumber => $autocardnumber,
welcome_message => $welcome_message,
clear_logs => $clear_logs,
flow_settings => $flow_settings,
plugins_enabled => join(',', @plugins_enabled)
Expand Down Expand Up @@ -90,6 +92,7 @@ sub edit {
type => $import->{type},
createonly => $import->{createonly},
autocardnumber => $import->{autocardnumber},
welcome_message => $import->{welcome_message},
clear_logs => $import->{clear_logs},
%{ $flow_settings }
);
Expand Down
11 changes: 6 additions & 5 deletions Koha/Plugin/Com/Biblibre/PatronImport/Helper/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ sub _load_db_conf {
$tables->{extended_attributes_table} = $plugin->{extended_attributes_table};

my $conf;
my ( $setup, $import_settings ) = _load_setup($import_id);
$conf->{setup} = $setup;
$conf->{createonly} = $import_settings->{createonly} || 0;
$conf->{autocardnumber} = $import_settings->{autocardnumber} || 'no';
$conf->{clear_logs} = $import_settings->{clear_logs} || 5;
my ( $setup, $import_settings) = _load_setup($import_id);
$conf->{setup} = $setup;
$conf->{createonly} = $import_settings->{createonly} || 0;
$conf->{autocardnumber} = $import_settings->{autocardnumber} || 'no';
$conf->{welcome_message} = $import_settings->{welcome_message} || 0;
$conf->{clear_logs} = $import_settings->{clear_logs} || 5;
$conf->{plugins_enabled} = $import_settings->{plugins_enabled};

$conf->{map} = _load_field_mappings($import_id);
Expand Down
29 changes: 29 additions & 0 deletions Koha/Plugin/Com/Biblibre/PatronImport/KohaPatron.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use Modern::Perl;

use C4::Context;
use C4::Members;
use C4::Letters qw( GetPreparedLetter EnqueueLetter );
use Koha::Patron;
use Koha::Patrons;
use Koha::Patron::Attribute::Types;
Expand Down Expand Up @@ -440,6 +441,34 @@ sub to_koha {
$this->{'borrowernumber'} = $borrowernumber;
my $patron_orm = Koha::Patrons->find($borrowernumber);

if ($conf->{welcome_message}) {
my $emailaddr = $patron_orm->email;
if ($emailaddr) {
eval {
my $letter = GetPreparedLetter(
module => 'members',
letter_code => 'WELCOME',
branchcode => $patron_orm->branchcode,
lang => $patron_orm->lang || 'default',
tables => {
'branches' => $patron_orm->branchcode,
'borrowers' => $patron_orm->borrowernumber,
},
want_librarian => 1,
) or return;

my $message_id = EnqueueLetter(
{
letter => $letter,
borrowernumber => $patron_orm->id,
to_address => $emailaddr,
message_transport_type => 'email'
}
);
};
}
}

if ( $exists == 0 or $protect_message_preferences == 0 ) {
Koha::Plugin::Com::Biblibre::PatronImport::Helper::MessagePreferences::set($borrowernumber, \%patron);
}
Expand Down
12 changes: 12 additions & 0 deletions Koha/Plugin/Com/Biblibre/PatronImport/templates/import/edit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
</div>
</li>

<li>
<label for="welcome_message">Send email to new patrons :</label>
[% IF welcome_message %]
<input name="welcome_message" type="checkbox" checked="checked"/>
[% ELSE %]
<input name="welcome_message" type="checkbox"/>
[% END %]
<div class="hint">
"WELCOME" notice is used.
</div>
</li>

<li>
<label for="clear_log_older_than">Clear reports and logs older than:</label>
[% IF clear_logs %]
Expand Down

0 comments on commit adbfaab

Please sign in to comment.