Lines 20-25
Link Here
|
20 |
|
20 |
|
21 |
# pragma |
21 |
# pragma |
22 |
use Modern::Perl; |
22 |
use Modern::Perl; |
|
|
23 |
use Try::Tiny; |
23 |
|
24 |
|
24 |
# external modules |
25 |
# external modules |
25 |
use CGI qw ( -utf8 ); |
26 |
use CGI qw ( -utf8 ); |
Lines 273-303
$newdata{'country'} = $input->param('country') if defined($input->param('country
Link Here
|
273 |
|
274 |
|
274 |
$newdata{'lang'} = $input->param('lang') if defined($input->param('lang')); |
275 |
$newdata{'lang'} = $input->param('lang') if defined($input->param('lang')); |
275 |
|
276 |
|
276 |
# builds default userid |
277 |
# Bug 32426 removed the fake_patron code here that filled $newdata{userid}. We should leave it now to patron->store. |
277 |
# userid input text may be empty or missing because of syspref BorrowerUnwantedField |
|
|
278 |
if ( ( defined $newdata{'userid'} && $newdata{'userid'} eq '' ) || $check_BorrowerUnwantedField =~ /userid/ && !defined $data{'userid'} ) { |
279 |
my $fake_patron = Koha::Patron->new; |
280 |
$fake_patron->userid($patron->userid) if $patron; # editing |
281 |
if ( ( defined $newdata{'firstname'} || $category->category_type eq 'I' ) && ( defined $newdata{'surname'} ) ) { |
282 |
# Full page edit, firstname and surname input zones are present |
283 |
$fake_patron->firstname($newdata{firstname}); |
284 |
$fake_patron->surname($newdata{surname}); |
285 |
$fake_patron->generate_userid; |
286 |
$newdata{'userid'} = $fake_patron->userid; |
287 |
} |
288 |
elsif ( ( defined $data{'firstname'} || $category->category_type eq 'I' ) && ( defined $data{'surname'} ) ) { |
289 |
# Partial page edit (access through "Details"/"Library details" tab), firstname and surname input zones are not used |
290 |
# Still, if the userid field is erased, we can create a new userid with available firstname and surname |
291 |
# FIXME clean thiscode newdata vs data is very confusing |
292 |
$fake_patron->firstname($data{firstname}); |
293 |
$fake_patron->surname($data{surname}); |
294 |
$fake_patron->generate_userid; |
295 |
$newdata{'userid'} = $fake_patron->userid; |
296 |
} |
297 |
else { |
298 |
$newdata{'userid'} = $data{'userid'}; |
299 |
} |
300 |
} |
301 |
|
278 |
|
302 |
my $extended_patron_attributes; |
279 |
my $extended_patron_attributes; |
303 |
if ($op eq 'save' || $op eq 'insert'){ |
280 |
if ($op eq 'save' || $op eq 'insert'){ |
Lines 350-364
if ($op eq 'save' || $op eq 'insert'){
Link Here
|
350 |
} |
327 |
} |
351 |
} |
328 |
} |
352 |
} |
329 |
} |
353 |
# Check if the 'userid' is unique. 'userid' might not always be present in |
330 |
|
354 |
# the edited values list when editing certain sub-forms. Get it straight |
331 |
# Bug 32426 removed the userid unique-check here. Postpone it to patron->store. |
355 |
# from the DB if absent. |
|
|
356 |
my $userid = $newdata{ userid } // $borrower_data->{ userid }; |
357 |
my $p = $borrowernumber ? Koha::Patrons->find( $borrowernumber ) : Koha::Patron->new(); |
358 |
$p->userid( $userid ); |
359 |
unless ( $p->has_valid_userid ) { |
360 |
push @errors, "ERROR_login_exist"; |
361 |
} |
362 |
|
332 |
|
363 |
my $password = $input->param('password'); |
333 |
my $password = $input->param('password'); |
364 |
my $password2 = $input->param('password2'); |
334 |
my $password2 = $input->param('password2'); |
Lines 428-442
if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
Link Here
|
428 |
if ($op eq 'insert'){ |
398 |
if ($op eq 'insert'){ |
429 |
# we know it's not a duplicate borrowernumber or there would already be an error |
399 |
# we know it's not a duplicate borrowernumber or there would already be an error |
430 |
delete $newdata{password2}; |
400 |
delete $newdata{password2}; |
431 |
$patron = eval { Koha::Patron->new(\%newdata)->store }; |
401 |
$success = 1; |
432 |
if ( $@ ) { |
402 |
$patron = try { |
433 |
# FIXME Urgent error handling here, we cannot fail without relevant feedback |
403 |
Koha::Patron->new(\%newdata)->store; |
434 |
# Lot of code will need to be removed from this script to handle exceptions raised by Koha::Patron->store |
404 |
} catch { |
435 |
warn "Patron creation failed! - $@"; # Maybe we must die instead of just warn |
405 |
$success = 0; |
436 |
push @messages, {error => 'error_on_insert_patron'}; |
406 |
$nok = 1; |
|
|
407 |
if( ref($_) eq 'Koha::Exceptions::Patron::InvalidUserid' ) { |
408 |
push @errors, "ERROR_login_exist"; |
409 |
} else { |
410 |
# FIXME Urgent error handling here, we cannot fail without relevant feedback |
411 |
# Lot of code will need to be removed from this script to handle exceptions raised by Koha::Patron->store |
412 |
warn "Patron creation failed! - $@"; # Maybe we must die instead of just warn |
413 |
push @messages, {error => 'error_on_insert_patron'}; |
414 |
} |
437 |
$op = "add"; |
415 |
$op = "add"; |
438 |
} else { |
416 |
return; |
439 |
$success = 1; |
417 |
}; |
|
|
418 |
|
419 |
if ( $success ) { |
440 |
add_guarantors( $patron, $input ); |
420 |
add_guarantors( $patron, $input ); |
441 |
$borrowernumber = $patron->borrowernumber; |
421 |
$borrowernumber = $patron->borrowernumber; |
442 |
$newdata{'borrowernumber'} = $borrowernumber; |
422 |
$newdata{'borrowernumber'} = $borrowernumber; |
Lines 444-450
if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
Link Here
|
444 |
} |
424 |
} |
445 |
|
425 |
|
446 |
# If 'AutoEmailNewUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode. |
426 |
# If 'AutoEmailNewUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode. |
447 |
if ( C4::Context->preference("AutoEmailNewUser") ) { |
427 |
if ( $patron && C4::Context->preference("AutoEmailNewUser") ) { |
448 |
#look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead |
428 |
#look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead |
449 |
my $emailaddr = $patron->notice_email_address; |
429 |
my $emailaddr = $patron->notice_email_address; |
450 |
# if we manage to find a valid email address, send notice |
430 |
# if we manage to find a valid email address, send notice |
Lines 513-531
if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
Link Here
|
513 |
|
493 |
|
514 |
delete $newdata{password2}; |
494 |
delete $newdata{password2}; |
515 |
|
495 |
|
516 |
eval { |
496 |
try { |
517 |
$patron->set(\%newdata)->store if scalar(keys %newdata) > 1; # bug 4508 - avoid crash if we're not |
497 |
$patron->set(\%newdata)->store if scalar(keys %newdata) > 1; |
518 |
# updating any columns in the borrowers table, |
498 |
# bug 4508 - avoid crash if we're not updating any columns in the borrowers table (editing patron attrs or msg prefs) |
519 |
# which can happen if we're only editing the |
499 |
$success = 1; |
520 |
# patron attributes or messaging preferences sections |
500 |
} catch { |
521 |
}; |
501 |
$success = 0; |
522 |
if ( $@ ) { |
502 |
$nok = 1; |
523 |
warn "Patron modification failed! - $@"; # Maybe we must die instead of just warn |
503 |
if( ref($_) eq 'Koha::Exceptions::Patron::InvalidUserid' ) { |
524 |
push @messages, {error => 'error_on_update_patron'}; |
504 |
push @errors, "ERROR_login_exist"; |
|
|
505 |
} else { |
506 |
warn "Patron modification failed! - $@"; # Maybe we must die instead of just warn |
507 |
push @messages, {error => 'error_on_update_patron'}; |
508 |
} |
525 |
$op = "modify"; |
509 |
$op = "modify"; |
526 |
} else { |
510 |
}; |
|
|
511 |
|
512 |
if ( $success ) { |
527 |
|
513 |
|
528 |
$success = 1; |
|
|
529 |
# Update or create our HouseboundRole if necessary. |
514 |
# Update or create our HouseboundRole if necessary. |
530 |
my $housebound_role = Koha::Patron::HouseboundRoles->find($borrowernumber); |
515 |
my $housebound_role = Koha::Patron::HouseboundRoles->find($borrowernumber); |
531 |
my ( $hsbnd_chooser, $hsbnd_deliverer ) = ( 0, 0 ); |
516 |
my ( $hsbnd_chooser, $hsbnd_deliverer ) = ( 0, 0 ); |
532 |
- |
|
|