You are here

function hosting_client_insert in Hostmaster (Aegir) 6

Implementation of hook_insert().

1 call to hosting_client_insert()
hosting_client_update in modules/hosting/client/hosting_client.module
Implementation of hook_update().

File

modules/hosting/client/hosting_client.module, line 302

Code

function hosting_client_insert($node) {
  if ($node->uname) {
    $node->uname = hosting_client_sanitize($node->uname);
  }
  else {
    $node->uname = hosting_client_sanitize($node->title);
  }
  db_query("INSERT INTO {hosting_client} (vid, nid, uname) VALUES (%d, %d, '%s' )", $node->vid, $node->nid, $node->uname);
  if (variable_get('hosting_client_register_user', FALSE) && !user_load(array(
    'mail' => $node->email,
  ))) {
    $user = hosting_client_register_user($node);
    $node->uid = $user->uid;
    db_query("UPDATE {node} SET uid = %d WHERE nid = %d", $user->uid, $node->nid);
    db_query("UPDATE {node_revisions} SET uid = %d WHERE vid = %d", $user->uid, $node->vid);
  }
  if (isset($node->new_user)) {
    $user = user_load(array(
      'name' => $node->new_user,
    ));
    if ($user) {
      db_query("INSERT INTO {hosting_client_user} (client, user, contact_type) VALUES (%d, %d, '%s')", $node->nid, $user->uid, '');
    }
  }
}