From 1d47227b9b199a05f079d925de8398b252bb8548 Mon Sep 17 00:00:00 2001 From: Tristan Olive Date: Mon, 19 Oct 2015 14:34:20 -0400 Subject: [PATCH] Drupal: Limit username length on import The Drupal users table definition limits username to 60 characters; on import, limit this to 56 chars, leaving room for a duplicate "tally" at the end of the string (should it be necessary) (DBOINC-145) --- .../modules/boincuser/includes/boincuser.helpers.inc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.helpers.inc b/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.helpers.inc index 2fffee3f29..6b486489be 100644 --- a/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.helpers.inc +++ b/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.helpers.inc @@ -197,8 +197,15 @@ function find_unique_name($requested_name) { } $same_name_tally = 1; $cleaned_name = preg_replace('/[^a-zA-Z0-9_ \.-]/s', '_', $requested_name); + $name_length = strlen($cleaned_name); + if ($name_length > 56) { + // Name is limited to 60 characters, but we want to leave space to add a + // tally if needed (for users with duplicate names); Limit to 56 chars and + // replace the middle of the string with "..." if too long + $cleaned_name = substr_replace($cleaned_name, '...', 28, ($name_length-56)+3); + } $unique_name = $cleaned_name; - while (db_result(db_query("SELECT uid FROM users WHERE name = '{$unique_name}' LIMIT 1"))) { + while (db_result(db_query("SELECT uid FROM {users} WHERE name = '{$unique_name}' LIMIT 1"))) { $same_name_tally++; $unique_name = "{$cleaned_name}_{$same_name_tally}"; }