View | Details | Raw Unified | Return to bug 29005
Collapse All | Expand All

(-)a/Koha/Patrons/Import.pm (-2 / +48 lines)
Lines 24-29 use Encode qw( decode_utf8 ); Link Here
24
use Try::Tiny qw( catch try );
24
use Try::Tiny qw( catch try );
25
25
26
use C4::Members qw( checkcardnumber );
26
use C4::Members qw( checkcardnumber );
27
use C4::Letters qw( GetPreparedLetter EnqueueLetter );
27
28
28
use Koha::Libraries;
29
use Koha::Libraries;
29
use Koha::Patrons;
30
use Koha::Patrons;
Lines 74-79 sub import_patrons { Link Here
74
    my $overwrite_cardnumber = $params->{overwrite_cardnumber};
75
    my $overwrite_cardnumber = $params->{overwrite_cardnumber};
75
    my $overwrite_passwords  = $params->{overwrite_passwords};
76
    my $overwrite_passwords  = $params->{overwrite_passwords};
76
    my $dry_run              = $params->{dry_run};
77
    my $dry_run              = $params->{dry_run};
78
    my $send_welcome         = $params->{send_welcome};
77
    my $extended             = C4::Context->preference('ExtendedPatronAttributes');
79
    my $extended             = C4::Context->preference('ExtendedPatronAttributes');
78
    my $set_messaging_prefs  = C4::Context->preference('EnhancedMessagingPreferences');
80
    my $set_messaging_prefs  = C4::Context->preference('EnhancedMessagingPreferences');
79
81
Lines 196-206 sub import_patrons { Link Here
196
            }
198
            }
197
        }
199
        }
198
200
201
        my $is_new = 0;
199
        if ($patron) {
202
        if ($patron) {
200
            $member = $patron->unblessed;
203
            $member = $patron->unblessed;
201
            $borrowernumber = $member->{'borrowernumber'};
204
            $borrowernumber = $member->{'borrowernumber'};
202
        } else {
205
        } else {
203
            $member = {};
206
            $member = {};
207
            $is_new = 1;
204
        }
208
        }
205
209
206
        if ( C4::Members::checkcardnumber( $borrower{cardnumber}, $borrowernumber ) ) {
210
        if ( C4::Members::checkcardnumber( $borrower{cardnumber}, $borrowernumber ) ) {
Lines 277-283 sub import_patrons { Link Here
277
                }
281
                }
278
            }
282
            }
279
283
280
            my $patron = Koha::Patrons->find( $borrowernumber );
281
            try {
284
            try {
282
                $schema->storage->txn_do(sub {
285
                $schema->storage->txn_do(sub {
283
                    $patron->set(\%borrower)->store;
286
                    $patron->set(\%borrower)->store;
Lines 373-379 sub import_patrons { Link Here
373
        else {
376
        else {
374
            try {
377
            try {
375
                $schema->storage->txn_do(sub {
378
                $schema->storage->txn_do(sub {
376
                    my $patron = Koha::Patron->new(\%borrower)->store;
379
                    $patron = Koha::Patron->new(\%borrower)->store;
377
                    $borrowernumber = $patron->id;
380
                    $borrowernumber = $patron->id;
378
381
379
                    if ( $patron->is_debarred ) {
382
                    if ( $patron->is_debarred ) {
Lines 439-444 sub import_patrons { Link Here
439
442
440
        next LINE unless $success;
443
        next LINE unless $success;
441
444
445
        # Send ACCTDETAILS welcome email is the user is new and we're set to send mail
446
        if ($send_welcome && $is_new) {
447
            my $emailaddr = $patron->notice_email_address;
448
449
            # if we manage to find a valid email address, send notice 
450
            if ($emailaddr) {
451
                eval {
452
                    my $letter = GetPreparedLetter(
453
                        module      => 'members',
454
                        letter_code => 'ACCTDETAILS',
455
                        branchcode  => $patron->branchcode,,
456
                        lang        => $patron->lang || 'default',
457
                        tables      => {
458
                            'branches'  => $patron->branchcode,
459
                            'borrowers' => $patron->borrowernumber,
460
                        },
461
                        want_librarian => 1,
462
                    ) or return;
463
464
                    my $message_id = EnqueueLetter(
465
                        {
466
                            letter                 => $letter,
467
                            borrowernumber         => $patron->id,
468
                            to_address             => $emailaddr,
469
                            message_transport_type => 'email'
470
                        }
471
                    );
472
                };
473
                if ($@) {
474
                    push @errors, { welcome_email_err => 1, borrowernumber => $borrowernumber };
475
                } else {
476
                    push(
477
                        @feedback,
478
                        {
479
                            feedback     => 1,
480
                            name         => 'welcome_sent',
481
                            value        => $borrower{'surname'} . ' / ' . $borrowernumber . ' / ' . $emailaddr
482
                        }
483
                    );
484
                }
485
            }
486
        }
487
442
        # Add a guarantor if we are given a relationship
488
        # Add a guarantor if we are given a relationship
443
        if ( $guarantor_id ) {
489
        if ( $guarantor_id ) {
444
            my $relationship = Koha::Patron::Relationships->find(
490
            my $relationship = Koha::Patron::Relationships->find(
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt (+11 lines)
Lines 344-349 Link Here
344
            </fieldset>
344
            </fieldset>
345
        [% END %]
345
        [% END %]
346
346
347
        <fieldset class="rows">
348
            <legend>Welcome email</legend>
349
            <ul>
350
                <li>
351
                    <input class="welcome_new" type="checkbox" id="welcome_new" name="welcome_new"/>
352
                    <label class="welcome_new" for="welcome_new">Send email to new patrons</label>
353
                    <span class="hint"> ACCTDETAILS notice is used</span>
354
                </li>
355
            </ul>
356
        </fieldset>
357
347
        <fieldset class="action">
358
        <fieldset class="action">
348
            <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
359
            <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
349
            <input type="submit" value="Import" />
360
            <input type="submit" value="Import" />
(-)a/tools/import_borrowers.pl (-1 / +2 lines)
Lines 97-102 my @preserve_fields = $input->param('preserve_existing'); Link Here
97
97
98
my $uploadborrowers = $input->param('uploadborrowers');
98
my $uploadborrowers = $input->param('uploadborrowers');
99
my $matchpoint      = $input->param('matchpoint');
99
my $matchpoint      = $input->param('matchpoint');
100
my $welcome_new     = $input->param('welcome_new');
100
if ($matchpoint) {
101
if ($matchpoint) {
101
    $matchpoint =~ s/^patron_attribute_//;
102
    $matchpoint =~ s/^patron_attribute_//;
102
}
103
}
Lines 128-133 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
128
            overwrite_passwords          => $overwrite_passwords,
129
            overwrite_passwords          => $overwrite_passwords,
129
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
130
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
130
            preserve_fields              => \@preserve_fields,
131
            preserve_fields              => \@preserve_fields,
132
            send_welcome                 => $welcome_new,
131
        }
133
        }
132
    );
134
    );
133
135
134
- 

Return to bug 29005