Bug 19936: Replace Generate_Userid - Update the occurrences
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 8 Jan 2018 21:44:25 +0000 (18:44 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 12 Apr 2018 12:36:41 +0000 (09:36 -0300)
Test plan:
Same test plan as previous patch:
add/update/import patrons and watch the userid

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Members.pm
members/memberentry.pl

index 137b8e0..ade8b11 100644 (file)
@@ -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
index 2d002c3..a1703d0 100755 (executable)
@@ -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'};