From a6059c4d2d43e43aa021069ce97d6424a76c4f41 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 21 Feb 2018 17:32:00 -0300 Subject: [PATCH] Bug 20287: Move trim values to a method Signed-off-by: Josef Moravec Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- C4/Auth_with_ldap.pm | 2 +- C4/Members.pm | 7 ------- Koha/Patron.pm | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index bbb1094229..03fab46da8 100644 --- a/C4/Auth_with_ldap.pm +++ b/C4/Auth_with_ldap.pm @@ -223,7 +223,7 @@ sub checkpw_ldap { return(1, $cardnumber, $local_userid); } } elsif ($config{replicate}) { # A2, C2 - $borrowernumber = C4::Members::AddMember(%borrower) or die "AddMember failed"; + Koha::Patron->new( \%borrower )->store; C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $borrowernumber, categorycode => $borrower{'categorycode'} } ); } else { return 0; # B2, D2 diff --git a/C4/Members.pm b/C4/Members.pm index bd339d5dbb..18f8f67b87 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -405,13 +405,6 @@ sub AddMember { ); } - # trim whitespace from data which has some non-whitespace in it. - foreach my $field_name (keys(%data)) { - if ( defined $data{$field_name} && $data{$field_name} =~ /\S/ ) { - $data{$field_name} =~ s/^\s*|\s*$//g; - } - } - my $p = Koha::Patron->new( { userid => $data{userid}, firstname => $data{firstname}, surname => $data{surname} } ); # generate a proper login if none provided $data{'userid'} = $p->generate_userid diff --git a/Koha/Patron.pm b/Koha/Patron.pm index f8efe5b15a..6396b50f27 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -104,6 +104,24 @@ sub fixup_cardnumber { $self->cardnumber($max+1); } +# trim whitespace from data which has some non-whitespace in it. +# Could be moved to Koha::Object if need to be reused +sub trim_whitespaces { + my( $self ) = @_; + + my $schema = Koha::Database->new->schema; + my @columns = $schema->source('Borrowers')->columns; + + for my $column( @columns ) { + my $value = $self->$column; + if ( defined $value ) { + $value =~ s/^\s*|\s*$//g; + $self->$column($value); + } + } + return $self; +} + sub store { my( $self ) = @_; -- 2.39.5