From 79702a55f0d0a02295790b79da1597eb5ec43a9f Mon Sep 17 00:00:00 2001
From: Sofian Benaissa <sfyn@host216.office.koumbit.net>
Date: Fri, 25 Mar 2011 12:29:40 -0400
Subject: [PATCH] Move the node suggestion from hosting_client_validate into its own function

---
 modules/hosting/client/hosting_client.module |   28 ++++++++++++++++++-------
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/modules/hosting/client/hosting_client.module b/modules/hosting/client/hosting_client.module
index 48046e2..7a65c20 100644
--- a/modules/hosting/client/hosting_client.module
+++ b/modules/hosting/client/hosting_client.module
@@ -228,14 +228,7 @@ function hosting_client_validate(&$node) {
 
   $nid = db_result(db_query("SELECT nid FROM {hosting_client} WHERE LOWER(uname) LIKE LOWER('%s')", hosting_client_sanitize($node->title)));
   if ($nid && $node->nid != $nid) {
-    $suggestion = FALSE;
-    for ($i = 0; $i < 10; $i++) {
-      $nid = db_result(db_query("SELECT nid FROM {hosting_client} WHERE LOWER(uname) LIKE LOWER('%s')", hosting_client_sanitize($node->title) . $i));
-      if ($nid && $node->nid != $nid) {
-        $suggestion = $node->title . $i;
-        break;
-      }
-    }
+    $suggestion = hosting_client_validate_suggest($node); 
     if ($suggestion) {
       form_set_error('title', t("Client name already in use, try @suggestion.", $suggestion));
     } else {
@@ -257,6 +250,25 @@ function hosting_client_validate(&$node) {
 }
 
 /**
+ * Helper for hosting_client_validate to suggest a new client title
+ *
+ * @see hosting_client_validate()
+ * @param $node
+ *   The node being validated
+ */
+function hosting_client_validate_suggest($node) {
+  $suggestion = FALSE;
+  for ($i = 0; $i < 10; $i++) {
+    $nid = db_result(db_query("SELECT nid FROM {hosting_client} WHERE LOWER(uname) LIKE LOWER('%s')", hosting_client_sanitize($node->title) . $i));
+    if ($nid && $node->nid != $nid) {
+      $suggestion = $node->title . $i;
+      break;
+    }
+  }
+  return $suggestion;
+}
+
+/**
  * Implementation of hook_insert().
  */
 function hosting_client_insert($node) {
-- 
1.5.6.5
