Skip to content

Commit

Permalink
CS-5913: Trim and remove duplicate spaces from author names
Browse files Browse the repository at this point in the history
Updates Author names in database by trimming spaces and removing
duplicate spaces by one.
Adds functionality to ReadName method, this is used to look up
Author Names, but the output also is used to create new Authors
when they don't exist.
  • Loading branch information
m038 committed Sep 15, 2015
1 parent a4674a0 commit ecf2190
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions newscoop/admin-files/users/authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
}
}

$first_name =Input::Get('first_name');
$last_name = Input::Get('last_name');
// Important! Trim spaces and replace multiple ones by space
$first_name = preg_replace('/\s+/', ' ', trim(Input::Get('first_name')));
$last_name = preg_replace('/\s+/', ' ', trim(Input::Get('last_name')));
$can_save = false;
if ($id > -1 && strlen($first_name) > 0 && strlen($last_name) > 0) {
$can_save = true;
Expand Down
6 changes: 5 additions & 1 deletion newscoop/classes/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ public static function ReadName($p_name)
}
}

return array('first_name' => $firstName, 'last_name' => $lastName);
// Important! Trim spaces and replace multiple ones by space
return array(
'first_name' => preg_replace('/\s+/', ' ', trim($firstName)),
'last_name' => preg_replace('/\s+/', ' ', trim($lastName))
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE Authors SET first_name=TRIM(first_name), last_name=TRIM(last_name);
UPDATE Authors SET first_name=replace(replace(replace(first_name,' ',' __|__'),'__|__ ',''),'__|__','') WHERE 0 < LOCATE(' ', first_name);
UPDATE Authors SET last_name=replace(replace(replace(last_name,' ',' __|__'),'__|__ ',''),'__|__','') WHERE 0 < LOCATE(' ', last_name);

0 comments on commit ecf2190

Please sign in to comment.