Skip to content

Commit

Permalink
Bug 20287: Move trim values to a method
Browse files Browse the repository at this point in the history
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
  • Loading branch information
joubu authored and kidclamp committed Jul 18, 2018
1 parent 1b13c45 commit a6059c4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion C4/Auth_with_ldap.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions C4/Members.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions Koha/Patron.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) = @_;

Expand Down

0 comments on commit a6059c4

Please sign in to comment.