From 7b1d08df0f4f69c52826c80a13158245287f4c00 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Jan 2018 18:44:25 -0300 Subject: [PATCH] Bug 19936: Replace Generate_Userid - Update the occurrences Test plan: Same test plan as previous patch: add/update/import patrons and watch the userid Signed-off-by: Josef Moravec Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- C4/Members.pm | 4 ++-- members/memberentry.pl | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 137b8e028d..ade8b11710 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -414,9 +414,9 @@ sub AddMember { } } - my $p = Koha::Patron->new( { userid => $data{userid} } ); + my $p = Koha::Patron->new( { userid => $data{userid}, firstname => $data{firstname}, surname => $data{surname} } ); # generate a proper login if none provided - $data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} ) + $data{'userid'} = $p->generate_userid if ( $data{'userid'} eq '' || ! $p->has_valid_userid ); # add expiration date if it isn't already there diff --git a/members/memberentry.pl b/members/memberentry.pl index 2d002c3b7e..a1703d0f40 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -158,6 +158,8 @@ if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' ) { $borrower_data = $patron->unblessed; $borrower_data->{category_type} = $patron->category->category_type; +} else { + $patron = Koha::Patron->new; } my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'}; my $category_type = $input->param('category_type') || ''; @@ -279,12 +281,17 @@ $newdata{'lang'} = $input->param('lang') if defined($input->param('lang')) if ( ( defined $newdata{'userid'} && $newdata{'userid'} eq '' ) || $check_BorrowerUnwantedField =~ /userid/ && !defined $data{'userid'} ) { if ( ( defined $newdata{'firstname'} ) && ( defined $newdata{'surname'} ) ) { # Full page edit, firstname and surname input zones are present - $newdata{'userid'} = Generate_Userid( $borrowernumber, $newdata{'firstname'}, $newdata{'surname'} ); + $patron->firstname($newdata{firstname}); + $patron->surname($newdata{surname}); + $newdata{'userid'} = $patron->generate_userid; } elsif ( ( defined $data{'firstname'} ) && ( defined $data{'surname'} ) ) { # Partial page edit (access through "Details"/"Library details" tab), firstname and surname input zones are not used # Still, if the userid field is erased, we can create a new userid with available firstname and surname - $newdata{'userid'} = Generate_Userid( $borrowernumber, $data{'firstname'}, $data{'surname'} ); + # FIXME clean thiscode newdata vs data is very confusing + $patron->firstname($data{firstname}); + $patron->surname($data{surname}); + $newdata{'userid'} = $patron->generate_userid; } else { $newdata{'userid'} = $data{'userid'}; -- 2.39.5