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

(-)a/C4/Members.pm (-108 lines)
Lines 72-78 BEGIN { Link Here
72
72
73
    #Modify data
73
    #Modify data
74
    push @EXPORT, qw(
74
    push @EXPORT, qw(
75
        &ModMember
76
        &changepassword
75
        &changepassword
77
    );
76
    );
78
77
Lines 261-373 sub patronflags { Link Here
261
    return ( \%flags );
260
    return ( \%flags );
262
}
261
}
263
262
264
265
=head2 ModMember
266
267
  my $success = ModMember(borrowernumber => $borrowernumber,
268
                                            [ field => value ]... );
269
270
Modify borrower's data.  All date fields should ALREADY be in ISO format.
271
272
return :
273
true on success, or false on failure
274
275
=cut
276
277
sub ModMember {
278
    my (%data) = @_;
279
280
    # trim whitespace from data which has some non-whitespace in it.
281
    foreach my $field_name (keys(%data)) {
282
        if ( defined $data{$field_name} && $data{$field_name} =~ /\S/ ) {
283
            $data{$field_name} =~ s/^\s*|\s*$//g;
284
        }
285
    }
286
287
    # test to know if you must update or not the borrower password
288
    if (exists $data{password}) {
289
        if ($data{password} eq '****' or $data{password} eq '') {
290
            delete $data{password};
291
        } else {
292
            if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
293
                # Update the hashed PIN in borrower_sync.hashed_pin, before Koha hashes it
294
                Koha::NorwegianPatronDB::NLUpdateHashedPIN( $data{'borrowernumber'}, $data{password} );
295
            }
296
            $data{password} = hash_password($data{password});
297
        }
298
    }
299
300
    my $old_categorycode = Koha::Patrons->find( $data{borrowernumber} )->categorycode;
301
302
    # get only the columns of a borrower
303
    my $schema = Koha::Database->new()->schema;
304
    my @columns = $schema->source('Borrower')->columns;
305
    my $new_borrower = { map { join(' ', @columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) };
306
307
    $new_borrower->{dateofbirth}     ||= undef if exists $new_borrower->{dateofbirth};
308
    $new_borrower->{dateenrolled}    ||= undef if exists $new_borrower->{dateenrolled};
309
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
310
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
311
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
312
    $new_borrower->{guarantorid}     ||= undef if exists $new_borrower->{guarantorid};
313
314
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
315
316
    my $borrowers_log = C4::Context->preference("BorrowersLog");
317
    if ( $borrowers_log && $patron->cardnumber ne $new_borrower->{cardnumber} )
318
    {
319
        logaction(
320
            "MEMBERS",
321
            "MODIFY",
322
            $data{'borrowernumber'},
323
            to_json(
324
                {
325
                    cardnumber_replaced => {
326
                        previous_cardnumber => $patron->cardnumber,
327
                        new_cardnumber      => $new_borrower->{cardnumber},
328
                    }
329
                },
330
                { utf8 => 1, pretty => 1 }
331
            )
332
        );
333
    }
334
335
    delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid};
336
337
    my $execute_success = $patron->store if $patron->set($new_borrower);
338
339
    if ($execute_success) { # only proceed if the update was a success
340
        # If the patron changes to a category with enrollment fee, we add a fee
341
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
342
            if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
343
                $patron->add_enrolment_fee_if_needed;
344
            }
345
        }
346
347
        # If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
348
        # cronjob will use for syncing with NL
349
        if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
350
            my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
351
                'synctype'       => 'norwegianpatrondb',
352
                'borrowernumber' => $data{'borrowernumber'}
353
            });
354
            # Do not set to "edited" if syncstatus is "new". We need to sync as new before
355
            # we can sync as changed. And the "new sync" will pick up all changes since
356
            # the patron was created anyway.
357
            if ( $borrowersync->syncstatus ne 'new' && $borrowersync->syncstatus ne 'delete' ) {
358
                $borrowersync->update( { 'syncstatus' => 'edited' } );
359
            }
360
            # Set the value of 'sync'
361
            $borrowersync->update( { 'sync' => $data{'sync'} } );
362
            # Try to do the live sync
363
            Koha::NorwegianPatronDB::NLSync({ 'borrowernumber' => $data{'borrowernumber'} });
364
        }
365
366
        logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if $borrowers_log;
367
    }
368
    return $execute_success;
369
}
370
371
=head2 GetAllIssues
263
=head2 GetAllIssues
372
264
373
  $issues = &GetAllIssues($borrowernumber, $sortkey, $limit);
265
  $issues = &GetAllIssues($borrowernumber, $sortkey, $limit);
(-)a/Koha/Patron.pm (-19 / +89 lines)
Lines 22-27 use Modern::Perl; Link Here
22
22
23
use Carp;
23
use Carp;
24
use List::MoreUtils qw( uniq );
24
use List::MoreUtils qw( uniq );
25
use JSON qw( to_json );
25
use Module::Load::Conditional qw( can_load );
26
use Module::Load::Conditional qw( can_load );
26
use Text::Unaccent qw( unac_string );
27
use Text::Unaccent qw( unac_string );
27
28
Lines 155-170 sub store { Link Here
155
                # We are in a transaction but the table is not locked
156
                # We are in a transaction but the table is not locked
156
                $self->fixup_cardnumber;
157
                $self->fixup_cardnumber;
157
            }
158
            }
158
            unless ( $self->in_storage ) {    #AddMember
159
159
160
                unless( $self->category->in_storage ) {
160
            unless( $self->category->in_storage ) {
161
                    Koha::Exceptions::Object::FKConstraint->throw(
161
                Koha::Exceptions::Object::FKConstraint->throw(
162
                        broken_fk => 'categorycode',
162
                    broken_fk => 'categorycode',
163
                        value     => $self->categorycode,
163
                    value     => $self->categorycode,
164
                    );
164
                );
165
                }
165
            }
166
167
            $self->trim_whitespaces;
166
168
167
                $self->trim_whitespaces;
169
            # We don't want invalid dates in the db (mysql has a bad habit of inserting 0000-00-00)
170
            $self->dateofbirth(undef) unless $self->dateofbirth;
171
            $self->debarred(undef)    unless $self->debarred;
172
173
            # Set default values if not set
174
            $self->sms_provider_id(undef) unless $self->sms_provider_id;
175
            $self->guarantorid(undef)     unless $self->guarantorid;
176
177
            unless ( $self->in_storage ) {    #AddMember
168
178
169
                # Generate a valid userid/login if needed
179
                # Generate a valid userid/login if needed
170
                $self->userid($self->generate_userid)
180
                $self->userid($self->generate_userid)
Lines 201-214 sub store { Link Here
201
                    ? Koha::AuthUtils::hash_password( $self->password )
211
                    ? Koha::AuthUtils::hash_password( $self->password )
202
                    : '!' );
212
                    : '!' );
203
213
204
                # We don't want invalid dates in the db (mysql has a bad habit of inserting 0000-00-00)
205
                $self->dateofbirth(undef) unless $self->dateofbirth;
206
                $self->debarred(undef)    unless $self->debarred;
207
208
                # Set default values if not set
209
                $self->sms_provider_id(undef) unless $self->sms_provider_id;
210
                $self->guarantorid(undef)     unless $self->guarantorid;
211
212
                $self->borrowernumber(undef);
214
                $self->borrowernumber(undef);
213
215
214
                $self = $self->SUPER::store;
216
                $self = $self->SUPER::store;
Lines 237-245 sub store { Link Here
237
                  if C4::Context->preference("BorrowersLog");
239
                  if C4::Context->preference("BorrowersLog");
238
            }
240
            }
239
            else {    #ModMember
241
            else {    #ModMember
242
                # test to know if you must update or not the borrower password
243
                if ( defined $self->password ) {
244
                    if ( $self->password eq '****' or $self->password eq '' ) {
245
                        $self->password(undef);
246
                    } else {
247
                        if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
248
                            # Update the hashed PIN in borrower_sync.hashed_pin, before Koha hashes it
249
                            Koha::NorwegianPatronDB::NLUpdateHashedPIN( $self->borrowernumber, $self->password );
250
                        }
251
                        $self->password(Koha::AuthUtils::hash_password($self->password));
252
                    }
253
                }
254
255
                 # Come from ModMember, but should not be possible (?)
256
                $self->dateenrolled(undef) unless $self->dateenrolled;
257
                $self->dateexpiry(undef)   unless $self->dateexpiry;
258
259
                if ( C4::Context->preference('FeeOnChangePatronCategory')
260
                    and $self->category->categorycode ne
261
                    $self->get_from_storage->category->categorycode )
262
                {
263
                    $self->add_enrolment_fee_if_needed;
264
                }
265
266
                # If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
267
                # cronjob will use for syncing with NL
268
                if (   C4::Context->preference('NorwegianPatronDBEnable')
269
                    && C4::Context->preference('NorwegianPatronDBEnable') == 1 )
270
                {
271
                    my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
272
                        'synctype'       => 'norwegianpatrondb',
273
                        'borrowernumber' => $self->borrowernumber,
274
                    });
275
                    # Do not set to "edited" if syncstatus is "new". We need to sync as new before
276
                    # we can sync as changed. And the "new sync" will pick up all changes since
277
                    # the patron was created anyway.
278
                    if ( $borrowersync->syncstatus ne 'new' && $borrowersync->syncstatus ne 'delete' ) {
279
                        $borrowersync->update( { 'syncstatus' => 'edited' } );
280
                    }
281
                    # Set the value of 'sync'
282
                    # FIXME THIS IS BROKEN # $borrowersync->update( { 'sync' => $data{'sync'} } );
283
284
                    # Try to do the live sync
285
                    Koha::NorwegianPatronDB::NLSync({ 'borrowernumber' => $self->borrowernumber });
286
                }
287
288
                my $borrowers_log = C4::Context->preference("BorrowersLog");
289
                my $previous_cardnumber = $self->get_from_storage->cardnumber;
290
                if ( $borrowers_log && $previous_cardnumber ne $self->cardnumber )
291
                {
292
                    logaction(
293
                        "MEMBERS",
294
                        "MODIFY",
295
                        $self->borrowernumber,
296
                        to_json(
297
                            {
298
                                cardnumber_replaced => {
299
                                    previous_cardnumber => $previous_cardnumber,
300
                                    new_cardnumber      => $self->cardnumber,
301
                                }
302
                            },
303
                            { utf8 => 1, pretty => 1 }
304
                        )
305
                    );
306
                }
307
308
                logaction( "MEMBERS", "MODIFY", $self->borrowernumber,
309
                    "UPDATE (executed w/ arg: " . $self->borrowernumber . ")" )
310
                  if $borrowers_log;
311
240
                $self = $self->SUPER::store;
312
                $self = $self->SUPER::store;
241
            }
313
            }
242
243
        }
314
        }
244
    );
315
    );
245
    return $self;
316
    return $self;
Lines 1162-1169 Generate a userid using the $surname and the $firstname (if there is a value in Link Here
1162
1233
1163
Return the generate userid ($firstname.$surname if there is a $firstname, or $surname if there is no value in $firstname) plus offset (0 if the $userid is unique, or a higher numeric value if not unique).
1234
Return the generate userid ($firstname.$surname if there is a $firstname, or $surname if there is no value in $firstname) plus offset (0 if the $userid is unique, or a higher numeric value if not unique).
1164
1235
1165
# Note: Should we set $self->userid with the generated value?
1236
# TODO: Set $self->userid with the generated value
1166
# Certainly yes, but we AddMember and ModMember will be rewritten
1167
1237
1168
=cut
1238
=cut
1169
1239
(-)a/members/memberentry.pl (-1 / +1 lines)
Lines 202-208 if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) Link Here
202
    }
202
    }
203
}
203
}
204
204
205
# remove keys from %newdata that ModMember() doesn't like
205
# remove keys from %newdata that is not part of patron's attributes
206
{
206
{
207
    my @keys_to_delete = (
207
    my @keys_to_delete = (
208
        qr/^BorrowerMandatoryField$/,
208
        qr/^BorrowerMandatoryField$/,
(-)a/members/members-update-do.pl (-5 / +4 lines)
Lines 22-28 use CGI qw ( -utf8 ); Link Here
22
use C4::Auth;
22
use C4::Auth;
23
use C4::Output;
23
use C4::Output;
24
use C4::Context;
24
use C4::Context;
25
use C4::Members;
25
use Koha::Patrons;
26
use Koha::Patron::Modifications;
26
use Koha::Patron::Modifications;
27
27
28
my $query = new CGI;
28
my $query = new CGI;
Lines 57-66 foreach my $param (@params) { Link Here
57
57
58
            if ($query->param("unset_gna_$borrowernumber")) {
58
            if ($query->param("unset_gna_$borrowernumber")) {
59
                # Unset gone no address
59
                # Unset gone no address
60
                ModMember(
60
                # FIXME Looks like this could go to $m->approve
61
                    borrowernumber => $borrowernumber,
61
                my $patron = Koha::Patrons->find( $borrowernumber );
62
                    gonenoaddress  => undef
62
                $patron->gonenoaddress(undef)->store;
63
                );
64
            }
63
            }
65
64
66
            $m->approve() if $m;
65
            $m->approve() if $m;
(-)a/members/update-child.pl (-10 / +4 lines)
Lines 22-28 Link Here
22
    script to update a child member to (usually) an adult member category
22
    script to update a child member to (usually) an adult member category
23
23
24
    - if called with op=multi, will return all available non child categories, for selection.
24
    - if called with op=multi, will return all available non child categories, for selection.
25
    - if called with op=update, script will update member record via  ModMember().
25
    - if called with op=update, script will update member record via Koha::Patron->store.
26
26
27
=cut
27
=cut
28
28
Lines 31-37 use CGI qw ( -utf8 ); Link Here
31
use C4::Context;
31
use C4::Context;
32
use C4::Auth;
32
use C4::Auth;
33
use C4::Output;
33
use C4::Output;
34
use C4::Members;
35
use Koha::Patrons;
34
use Koha::Patrons;
36
use Koha::Patron::Categories;
35
use Koha::Patron::Categories;
37
36
Lines 76-89 elsif ( $op eq 'update' ) { Link Here
76
    my $patron         = Koha::Patrons->find( $borrowernumber );
75
    my $patron         = Koha::Patrons->find( $borrowernumber );
77
    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
76
    output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
78
77
79
    my $member = $patron->unblessed;
78
    $patron->guarantorid(undef);
80
    $member->{'guarantorid'}  = 0;
79
    $patron->categorycode($catcode);
81
    $member->{'categorycode'} = $catcode;
80
    $patron->store;
82
    my $borcat = Koha::Patron::Categories->find($catcode);
83
    $member->{'category_type'} = $borcat->category_type;
84
    $member->{'description'}   = $borcat->description;
85
    delete $member->{password};
86
    ModMember(%$member);
87
81
88
    if (  $catcode_multi ) {
82
    if (  $catcode_multi ) {
89
        $template->param(
83
        $template->param(
(-)a/misc/cronjobs/nl-sync-to-koha.pl (-10 / +4 lines)
Lines 12-20 nl-sync-to-koha.pl - Sync patrons from the Norwegian national patron database (N Link Here
12
12
13
=cut
13
=cut
14
14
15
use C4::Members;
16
use C4::Members::Attributes qw( UpdateBorrowerAttribute );
15
use C4::Members::Attributes qw( UpdateBorrowerAttribute );
17
use Koha::NorwegianPatronDB qw( NLCheckSysprefs NLGetChanged );
16
use Koha::NorwegianPatronDB qw( NLCheckSysprefs NLGetChanged );
17
use Koha::Patrons;
18
use Koha::Database;
18
use Koha::Database;
19
use Getopt::Long;
19
use Getopt::Long;
20
use Pod::Usage;
20
use Pod::Usage;
Lines 70-86 foreach my $patron ( @{ $result->{'kohapatrons'} } ) { Link Here
70
        # Delete the extra data from the copy of the hashref
70
        # Delete the extra data from the copy of the hashref
71
        delete $clean_patron{'_extra'};
71
        delete $clean_patron{'_extra'};
72
        # Find the borrowernumber based on cardnumber
72
        # Find the borrowernumber based on cardnumber
73
        my $stored_patron = Koha::Database->new->schema->resultset('Borrower')->find({
73
        my $stored_patron = Koha::Patrons->find({ cardnumber => $patron->{cardnumber} });
74
            'cardnumber' => $patron->{'cardnumber'}
75
        });
76
        my $borrowernumber = $stored_patron->borrowernumber;
74
        my $borrowernumber = $stored_patron->borrowernumber;
77
        if ( $run ) {
75
        if ( $run ) {
78
            # Call ModMember
76
            # FIXME Exceptions must be caught here
79
            my $success = ModMember(
77
            if ( $stored_patron->set(\%clean_patron)->store ) {
80
                'borrowernumber' => $borrowernumber,
81
                %clean_patron,
82
            );
83
            if ( $success ) {
84
                # Get the sync object
78
                # Get the sync object
85
                my $sync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
79
                my $sync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
86
                    'synctype'       => 'norwegianpatrondb',
80
                    'synctype'       => 'norwegianpatrondb',
(-)a/opac/opac-messaging.pl (-13 / +12 lines)
Lines 30-35 use C4::Output; Link Here
30
use C4::Members;
30
use C4::Members;
31
use C4::Members::Messaging;
31
use C4::Members::Messaging;
32
use C4::Form::MessagingPreferences;
32
use C4::Form::MessagingPreferences;
33
use Koha::Patrons;
33
use Koha::SMS::Providers;
34
use Koha::SMS::Providers;
34
35
35
my $query = CGI->new();
36
my $query = CGI->new();
Lines 50-86 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
50
    }
51
    }
51
);
52
);
52
53
53
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
54
my $patron = Koha::Patrons->find( $borrowernumber ); # FIXME and if borrowernumber is invalid?
55
54
my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
56
my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
55
57
56
if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
58
if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
57
    my $sms = $query->param('SMSnumber');
59
    my $sms = $query->param('SMSnumber');
58
    my $sms_provider_id = $query->param('sms_provider_id');
60
    my $sms_provider_id = $query->param('sms_provider_id');
59
    if ( defined $sms && ( $borrower->{'smsalertnumber'} // '' ) ne $sms
61
    if ( defined $sms && ( $patron->smsalertnumber // '' ) ne $sms
60
            or ( $borrower->{sms_provider_id} // '' ) ne $sms_provider_id ) {
62
            or ( $patron->sms_provider_id // '' ) ne $sms_provider_id ) {
61
        ModMember(
63
        $patron->set({
62
            borrowernumber  => $borrowernumber,
63
            smsalertnumber  => $sms,
64
            smsalertnumber  => $sms,
64
            sms_provider_id => $sms_provider_id,
65
            sms_provider_id => $sms_provider_id,
65
        );
66
        })->store;
66
        # FIXME will not be needed when ModMember will be replaced
67
        $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
68
    }
67
    }
69
68
70
    C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $borrowernumber }, $template);
69
    C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $patron->borrowernumber }, $template);
71
}
70
}
72
71
73
C4::Form::MessagingPreferences::set_form_values({ borrowernumber     => $borrower->{'borrowernumber'} }, $template);
72
C4::Form::MessagingPreferences::set_form_values({ borrowernumber     => $patron->borrowernumber }, $template);
74
73
75
$template->param( BORROWER_INFO         => $borrower,
74
$template->param( BORROWER_INFO         => $patron->unblessed,
76
                  messagingview         => 1,
75
                  messagingview         => 1,
77
                  SMSnumber => $borrower->{'smsalertnumber'},
76
                  SMSnumber             => $patron->smsalertnumber, # FIXME This is already sent 2 lines above
78
                  SMSSendDriver                =>  C4::Context->preference("SMSSendDriver"),
77
                  SMSSendDriver                =>  C4::Context->preference("SMSSendDriver"),
79
                  TalkingTechItivaPhone        =>  C4::Context->preference("TalkingTechItivaPhoneNotification") );
78
                  TalkingTechItivaPhone        =>  C4::Context->preference("TalkingTechItivaPhoneNotification") );
80
79
81
if ( C4::Context->preference("SMSSendDriver") eq 'Email' ) {
80
if ( C4::Context->preference("SMSSendDriver") eq 'Email' ) {
82
    my @providers = Koha::SMS::Providers->search();
81
    my @providers = Koha::SMS::Providers->search();
83
    $template->param( sms_providers => \@providers, sms_provider_id => $borrower->{'sms_provider_id'} );
82
    $template->param( sms_providers => \@providers, sms_provider_id => $patron->sms_provider_id );
84
}
83
}
85
84
86
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
85
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
(-)a/opac/opac-privacy.pl (-7 / +8 lines)
Lines 21-27 use CGI qw ( -utf8 ); Link Here
21
21
22
use C4::Auth;    # checkauth, getborrowernumber.
22
use C4::Auth;    # checkauth, getborrowernumber.
23
use C4::Context;
23
use C4::Context;
24
use C4::Members;
25
use C4::Output;
24
use C4::Output;
26
use Koha::Patrons;
25
use Koha::Patrons;
27
26
Lines 50-61 my $privacy = $query->param("privacy"); Link Here
50
my $privacy_guarantor_checkouts = $query->param("privacy_guarantor_checkouts");
49
my $privacy_guarantor_checkouts = $query->param("privacy_guarantor_checkouts");
51
50
52
if ( $op eq "update_privacy" ) {
51
if ( $op eq "update_privacy" ) {
53
    ModMember(
52
    my $patron = Koha::Patrons->find( $borrowernumber );
54
        borrowernumber             => $borrowernumber,
53
    if ( $patron ) {
55
        privacy                    => $privacy,
54
        $patron->set({
56
        privacy_guarantor_checkouts => $privacy_guarantor_checkouts,
55
            privacy                    => $privacy,
57
    );
56
            privacy_guarantor_checkouts => $privacy_guarantor_checkouts,
58
    $template->param( 'privacy_updated' => 1 );
57
        })->store;
58
        $template->param( 'privacy_updated' => 1 );
59
    }
59
}
60
}
60
elsif ( $op eq "delete_record" ) {
61
elsif ( $op eq "delete_record" ) {
61
62
(-)a/t/db_dependent/Koha/Patrons.t (-8 / +8 lines)
Lines 402-417 subtest 'add_enrolment_fee_if_needed' => sub { Link Here
402
402
403
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
403
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
404
    $borrower_data{categorycode} = 'J';
404
    $borrower_data{categorycode} = 'J';
405
    C4::Members::ModMember(%borrower_data);
405
    $patron->set(\%borrower_data)->store;
406
    $total = $patron->account->balance;
406
    $total = $patron->account->balance;
407
    is( int($total), int($enrolmentfee_K), "Kid growing and become a juvenile, but shouldn't pay for the upgrade " );
407
    is( int($total), int($enrolmentfee_K), "Kid growing and become a juvenile, but shouldn't pay for the upgrade " );
408
408
409
    $borrower_data{categorycode} = 'K';
409
    $borrower_data{categorycode} = 'K';
410
    C4::Members::ModMember(%borrower_data);
410
    $patron->set(\%borrower_data)->store;
411
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 );
411
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 );
412
412
413
    $borrower_data{categorycode} = 'J';
413
    $borrower_data{categorycode} = 'J';
414
    C4::Members::ModMember(%borrower_data);
414
    $patron->set(\%borrower_data)->store;
415
    $total = $patron->account->balance;
415
    $total = $patron->account->balance;
416
    is( int($total), int($enrolmentfee_K + $enrolmentfee_J), "Kid growing and become a juvenile, they should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
416
    is( int($total), int($enrolmentfee_K + $enrolmentfee_J), "Kid growing and become a juvenile, they should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
417
417
Lines 1362-1374 subtest 'Log cardnumber change' => sub { Link Here
1362
    plan tests => 3;
1362
    plan tests => 3;
1363
1363
1364
    t::lib::Mocks::mock_preference( 'BorrowersLog', 1 );
1364
    t::lib::Mocks::mock_preference( 'BorrowersLog', 1 );
1365
    my $patron = $builder->build( { source => 'Borrower' } );
1365
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
1366
1366
1367
    my $cardnumber = $patron->{cardnumber};
1367
    my $cardnumber = $patron->cardnumber;
1368
    $patron->{cardnumber} = 'TESTCARDNUMBER';
1368
    $patron->set( { cardnumber => 'TESTCARDNUMBER' });
1369
    ModMember(%$patron);
1369
    $patron->store;
1370
1370
1371
    my @logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->{borrowernumber} } );
1371
    my @logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } );
1372
    my $log_info = from_json( $logs[0]->info );
1372
    my $log_info = from_json( $logs[0]->info );
1373
    is( $log_info->{cardnumber_replaced}->{new_cardnumber}, 'TESTCARDNUMBER', 'Got correct new cardnumber' );
1373
    is( $log_info->{cardnumber_replaced}->{new_cardnumber}, 'TESTCARDNUMBER', 'Got correct new cardnumber' );
1374
    is( $log_info->{cardnumber_replaced}->{previous_cardnumber}, $cardnumber, 'Got correct old cardnumber' );
1374
    is( $log_info->{cardnumber_replaced}->{previous_cardnumber}, $cardnumber, 'Got correct old cardnumber' );
(-)a/t/db_dependent/Letters.t (-1 / +1 lines)
Lines 610-616 subtest 'SendQueuedMessages' => sub { Link Here
610
    is( $@, '', 'SendQueuedMessages should not explode if the patron does not have a sms provider set' );
610
    is( $@, '', 'SendQueuedMessages should not explode if the patron does not have a sms provider set' );
611
611
612
    my $sms_pro = $builder->build_object({ class => 'Koha::SMS::Providers', value => { domain => 'kidclamp.rocks' } });
612
    my $sms_pro = $builder->build_object({ class => 'Koha::SMS::Providers', value => { domain => 'kidclamp.rocks' } });
613
    ModMember( borrowernumber => $borrowernumber, smsalertnumber => '5555555555', sms_provider_id => $sms_pro->id() );
613
    $patron->set( { smsalertnumber => '5555555555', sms_provider_id => $sms_pro->id() } )->store;
614
    $message_id = C4::Letters::EnqueueLetter($my_message); #using datas set around line 95 and forward
614
    $message_id = C4::Letters::EnqueueLetter($my_message); #using datas set around line 95 and forward
615
    C4::Letters::SendQueuedMessages();
615
    C4::Letters::SendQueuedMessages();
616
    my $sms_message_address = $schema->resultset('MessageQueue')->search({
616
    my $sms_message_address = $schema->resultset('MessageQueue')->search({
(-)a/t/db_dependent/Members.t (-26 / +28 lines)
Lines 97-105 my %data = ( Link Here
97
my $addmem=Koha::Patron->new(\%data)->store->borrowernumber;
97
my $addmem=Koha::Patron->new(\%data)->store->borrowernumber;
98
ok($addmem, "Koha::Patron->store()");
98
ok($addmem, "Koha::Patron->store()");
99
99
100
my $member = Koha::Patrons->find( { cardnumber => $CARDNUMBER } )
100
my $patron = Koha::Patrons->find( { cardnumber => $CARDNUMBER } )
101
  or BAIL_OUT("Cannot read member with card $CARDNUMBER");
101
  or BAIL_OUT("Cannot read member with card $CARDNUMBER");
102
$member = $member->unblessed;
102
my $member = $patron->unblessed;
103
103
104
ok ( $member->{firstname}    eq $FIRSTNAME    &&
104
ok ( $member->{firstname}    eq $FIRSTNAME    &&
105
     $member->{surname}      eq $SURNAME      &&
105
     $member->{surname}      eq $SURNAME      &&
Lines 114-120 $member->{firstname} = $CHANGED_FIRSTNAME . q{ }; Link Here
114
$member->{email}     = $EMAIL;
114
$member->{email}     = $EMAIL;
115
$member->{phone}     = $PHONE;
115
$member->{phone}     = $PHONE;
116
$member->{emailpro}  = $EMAILPRO;
116
$member->{emailpro}  = $EMAILPRO;
117
ModMember(%$member);
117
$patron->set($member)->store;
118
my $changedmember = Koha::Patrons->find( { cardnumber => $CARDNUMBER } )->unblessed;
118
my $changedmember = Koha::Patrons->find( { cardnumber => $CARDNUMBER } )->unblessed;
119
ok ( $changedmember->{firstname} eq $CHANGED_FIRSTNAME &&
119
ok ( $changedmember->{firstname} eq $CHANGED_FIRSTNAME &&
120
     $changedmember->{email}     eq $EMAIL             &&
120
     $changedmember->{email}     eq $EMAIL             &&
Lines 152-194 is ($checkcardnum, "2", "Card number is too long"); Link Here
152
    dateenrolled => '',
152
    dateenrolled => '',
153
);
153
);
154
my $borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber;
154
my $borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber;
155
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
155
$patron = Koha::Patrons->find( $borrowernumber );
156
my $borrower = $patron->unblessed;
156
is( $borrower->{dateofbirth}, undef, 'Koha::Patron->store should undef dateofbirth if empty string is given');
157
is( $borrower->{dateofbirth}, undef, 'Koha::Patron->store should undef dateofbirth if empty string is given');
157
is( $borrower->{debarred}, undef, 'Koha::Patron->store should undef debarred if empty string is given');
158
is( $borrower->{debarred}, undef, 'Koha::Patron->store should undef debarred if empty string is given');
158
isnt( $borrower->{dateexpiry}, '0000-00-00', 'Koha::Patron->store should not set dateexpiry to 0000-00-00 if empty string is given');
159
isnt( $borrower->{dateexpiry}, '0000-00-00', 'Koha::Patron->store should not set dateexpiry to 0000-00-00 if empty string is given');
159
isnt( $borrower->{dateenrolled}, '0000-00-00', 'Koha::Patron->store should not set dateenrolled to 0000-00-00 if empty string is given');
160
isnt( $borrower->{dateenrolled}, '0000-00-00', 'Koha::Patron->store should not set dateenrolled to 0000-00-00 if empty string is given');
160
161
161
ModMember( borrowernumber => $borrowernumber, dateofbirth => '', debarred => '', dateexpiry => '', dateenrolled => '' );
162
$patron->set({ dateofbirth => '', debarred => '', dateexpiry => '', dateenrolled => '' })->store;
162
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
163
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
163
is( $borrower->{dateofbirth}, undef, 'ModMember should undef dateofbirth if empty string is given');
164
is( $borrower->{dateofbirth}, undef, 'Koha::Patron->store should undef dateofbirth if empty string is given');
164
is( $borrower->{debarred}, undef, 'ModMember should undef debarred if empty string is given');
165
is( $borrower->{debarred}, undef, 'Koha::Patron->store should undef debarred if empty string is given');
165
isnt( $borrower->{dateexpiry}, '0000-00-00', 'ModMember should not set dateexpiry to 0000-00-00 if empty string is given');
166
isnt( $borrower->{dateexpiry}, '0000-00-00', 'Koha::Patron->store should not set dateexpiry to 0000-00-00 if empty string is given');
166
isnt( $borrower->{dateenrolled}, '0000-00-00', 'ModMember should not set dateenrolled to 0000-00-00 if empty string is given');
167
isnt( $borrower->{dateenrolled}, '0000-00-00', 'Koha::Patron->store should not set dateenrolled to 0000-00-00 if empty string is given');
167
168
168
ModMember( borrowernumber => $borrowernumber, dateofbirth => '1970-01-01', debarred => '2042-01-01', dateexpiry => '9999-12-31', dateenrolled => '2015-09-06' );
169
$patron->set({ dateofbirth => '1970-01-01', debarred => '2042-01-01', dateexpiry => '9999-12-31', dateenrolled => '2015-09-06' })->store;
169
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
170
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
170
is( $borrower->{dateofbirth}, '1970-01-01', 'ModMember should correctly set dateofbirth if a valid date is given');
171
is( $borrower->{dateofbirth}, '1970-01-01', 'Koha::Patron->store should correctly set dateofbirth if a valid date is given');
171
is( $borrower->{debarred}, '2042-01-01', 'ModMember should correctly set debarred if a valid date is given');
172
is( $borrower->{debarred}, '2042-01-01', 'Koha::Patron->store should correctly set debarred if a valid date is given');
172
is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given');
173
is( $borrower->{dateexpiry}, '9999-12-31', 'Koha::Patron->store should correctly set dateexpiry if a valid date is given');
173
is( $borrower->{dateenrolled}, '2015-09-06', 'ModMember should correctly set dateenrolled if a valid date is given');
174
is( $borrower->{dateenrolled}, '2015-09-06', 'Koha::Patron->store should correctly set dateenrolled if a valid date is given');
174
175
175
subtest 'ModMember should not update userid if not true' => sub {
176
subtest 'Koha::Patron->store should not update userid if not true' => sub {
176
    plan tests => 3;
177
    plan tests => 3;
177
178
178
    $data{ cardnumber } = "234567890";
179
    $data{ cardnumber } = "234567890";
179
    $data{userid} = 'a_user_id';
180
    $data{userid} = 'a_user_id';
180
    $borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber;
181
    $borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber;
181
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
182
    my $patron = Koha::Patrons->find( $borrowernumber );
183
    my $borrower = $patron->unblessed;
182
184
183
    ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' );
185
    $patron->set( { firstname => 'Tomas', userid => '' } )->store;
184
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
186
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
185
    is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an empty string' );
187
    is ( $borrower->{userid}, $data{userid}, 'Koha::Patron->store should not update the userid with an empty string' );
186
    ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => 0 );
188
    $patron->set( { firstname => 'Tomas', userid => 0 } )->store;
187
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
189
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
188
    is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an 0');
190
    is ( $borrower->{userid}, $data{userid}, 'Koha::Patron->store should not update the userid with an 0');
189
    ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => undef );
191
    $patron->set( { firstname => 'Tomas', userid => undef } )->store;
190
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
192
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
191
    is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an undefined value');
193
    is ( $borrower->{userid}, $data{userid}, 'Koha::Patron->store should not update the userid with an undefined value');
192
};
194
};
193
195
194
#Regression tests for bug 10612
196
#Regression tests for bug 10612
Lines 272-278 my @listpatrons = ($bor1inlist, $bor2inlist); Link Here
272
AddPatronsToList(  { list => $list1, borrowernumbers => \@listpatrons });
274
AddPatronsToList(  { list => $list1, borrowernumbers => \@listpatrons });
273
my $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } );
275
my $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } );
274
is( scalar(@$patstodel),0,'No staff deleted from list of all staff');
276
is( scalar(@$patstodel),0,'No staff deleted from list of all staff');
275
ModMember( borrowernumber => $bor2inlist, categorycode => 'CIVILIAN' );
277
Koha::Patrons->find($bor2inlist)->set({ categorycode => 'CIVILIAN' })->store;
276
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
278
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
277
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted from list');
279
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted from list');
278
$patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patron_list_id => $list1->patron_list_id() } );
280
$patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patron_list_id => $list1->patron_list_id() } );
Lines 282-289 ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inli Link Here
282
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
284
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
283
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by last issue date');
285
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by last issue date');
284
286
285
ModMember( borrowernumber => $bor1inlist, categorycode => 'CIVILIAN' );
287
Koha::Patrons->find($bor1inlist)->set({ categorycode => 'CIVILIAN' })->store;
286
ModMember( borrowernumber => $guarantee->{borrowernumber} ,guarantorid=>$bor1inlist );
288
Koha::Patrons->find($guarantee->{borrowernumber})->set({ guarantorid => $bor1inlist })->store;
287
289
288
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
290
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
289
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted from list');
291
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted from list');
Lines 293-299 $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02', patron_list Link Here
293
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by expirationdate and list');
295
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by expirationdate and list');
294
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
296
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
295
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by last issue date');
297
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by last issue date');
296
ModMember( borrowernumber => $guarantee->{borrowernumber}, guarantorid=>'' );
298
Koha::Patrons->find($guarantee->{borrowernumber})->set({ guarantorid => '' })->store;
297
299
298
$builder->build({
300
$builder->build({
299
        source => 'Issue',
301
        source => 'Issue',
(-)a/t/db_dependent/Reserves.t (-2 / +2 lines)
Lines 526-538 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Res Link Here
526
526
527
#Set the dateofbirth for the Borrower making them "too young".
527
#Set the dateofbirth for the Borrower making them "too young".
528
$borrower->{dateofbirth} = DateTime->now->add( years => -15 );
528
$borrower->{dateofbirth} = DateTime->now->add( years => -15 );
529
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
529
Koha::Patrons->find( $borrowernumber )->set({ dateofbirth => $borrower->{dateofbirth} })->store;
530
530
531
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'ageRestricted', "Reserving a 'PEGI 16' Biblio by a 15 year old borrower fails");
531
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'ageRestricted', "Reserving a 'PEGI 16' Biblio by a 15 year old borrower fails");
532
532
533
#Set the dateofbirth for the Borrower making them "too old".
533
#Set the dateofbirth for the Borrower making them "too old".
534
$borrower->{dateofbirth} = DateTime->now->add( years => -30 );
534
$borrower->{dateofbirth} = DateTime->now->add( years => -30 );
535
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
535
Koha::Patrons->find( $borrowernumber )->set({ dateofbirth => $borrower->{dateofbirth} })->store;
536
536
537
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
537
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
538
       ####
538
       ####
(-)a/tools/modborrowers.pl (-3 / +2 lines)
Lines 295-302 if ( $op eq 'do' ) { Link Here
295
        # If at least one field are filled, we want to modify the borrower
295
        # If at least one field are filled, we want to modify the borrower
296
        if ( defined $infos ) {
296
        if ( defined $infos ) {
297
            $infos->{borrowernumber} = $borrowernumber;
297
            $infos->{borrowernumber} = $borrowernumber;
298
            my $success = ModMember(%$infos);
298
            eval { Koha::Patrons->find( $borrowernumber )->set($infos)->store; };
299
            if (!$success) {
299
            if ( $@ ) { # FIXME We could provide better error handling here
300
                my $patron = Koha::Patrons->find( $borrowernumber );
300
                my $patron = Koha::Patrons->find( $borrowernumber );
301
                $infos->{cardnumber} = $patron ? $patron->cardnumber || '' : '';
301
                $infos->{cardnumber} = $patron ? $patron->cardnumber || '' : '';
302
                push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber}, cardnumber => $infos->{cardnumber} };
302
                push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber}, cardnumber => $infos->{cardnumber} };
303
- 

Return to bug 20287