Using an existing client name during anonymous checkout still allows the site to be ordered, but assigns it to the existing client (and associated user). It also throws the following errors:

Client name already in use.
user warning: Duplicate entry 'ergonlogicenterp' for key 'uname_unq' query: INSERT INTO hosting_client (vid, nid, uname) VALUES (142, 120, 'ergonlogicenterp' ) in /var/aegir/hostmaster-6.x-1.2/profiles/hostmaster/modules/hosting/client/hosting_client.module on line 306.

Validating the "company" field (or client name, or whatever) should avoid this.

Comments

ergonlogic’s picture

My patch in #1237178: hosting_client_validate_suggest() appears broken mostly fixes this. However, hosting_client_validate_suggest() will only work for the first 10 duplicates. Admittedly, that is an edge case.

But the code below (lines 252-5 from _uc_hosting_add_client in uc_hosting.module) doesn't actually do what it says:

  // Make sure the client title is unique
  if ($suggestion = hosting_client_validate_suggest($client)) {
    $client->title = $suggestion;
  }

Since we aren't validating a form at this point, we can't use hosting_client_validate()... So maybe we need to suggest/write a new Aegir function: hosting_client_is_unique() or something.

ergonlogic’s picture

Aha! just found:


/**
 * Validate that Mr. shopper is not duplicating a client
 */
function uc_hosting_form_uc_cart_checkout_form_alter (&$form, $form_state) {
  // TODO Set a validation function
  // $form[#validate][] = 'uc_hosting_checkout_validation';
}

/**
 *
 */
function uc_hosting_checkout_validation ($form, $form_state) {
  // TODO The submitted billing info will be used to modify clients
  // We need to make sure that data is not going to duplicate
  // an existing client first.
}

So, maybe break out the client construction code from _uc_hosting_add_client, and check that a form submission would result in a unique client?

jayelless’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB

I experienced this problem, and was investigating this issue, along with the fact that the created hosting client node titles were generated with an unnecessary zero tacked onto the end (even when they were unique and there was no name collision).

Additionally, when a long client name was entered (or company name when that was used), then the resulting client name and client title were rejected.

I had the following errors:

Client name already in use, try Thirtythree Double-Tri00.
user warning: Duplicate entry 'thirtythreedoubl' for key 2 query: INSERT INTO hosting_client (vid, nid, uname) VALUES (710, 639, 'thirtythreedoubl' ) in /var/aegir/hostmaster-6.x-1.6/profiles/hostmaster/modules/hosting/client/hosting_client.module on line 323.

The code in comment #1 above does not provide for uniqueness in the first 16 characters ("MAX_GROUP_LENGTH"), which is required for uname.

I believe the solution is to recode the section that forces a unique client username and title as follows:

  // Make sure the client username and title are unique
  $client->uname = hosting_client_sanitize($client->title);
  $nid = db_result(db_query("SELECT nid FROM {hosting_client} WHERE uname LIKE '%s'", $client->uname));
  if ($nid) {
    for($i = 0; $nid; $i++) {
      $xname = substr($client->uname, 0, MAX_GROUP_LENGTH - strlen($i)) . $i;
      $nid = db_result(db_query("SELECT nid FROM {hosting_client} WHERE uname LIKE '%s'", $xname));
    }
    $client->uname = $xname;
    $client->title .= " " . --$i;
  }

This code will cycle though as many iterations as are required to find a unique "uname" within the MAX_GROUP_LENGTH string length, and will also add the numeric suffix to the title that would otherwise be generated (it does not have the same length restriction).

This change appears to work correctly for anonymous users as well as logged in users.

Patch attached

gboudrias’s picture

Status: Needs review » Fixed

After testing and validating with ergonlogic, I pushed jlscott's patch to the 6.x-1.x branch.

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.