You are here

function hosting_client_update in Hostmaster (Aegir) 6

Implementation of hook_update().

As an existing node is being updated in the database, we need to do our own database updates.

File

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

Code

function hosting_client_update($node) {

  // if this is a new node or we're adding a new revision,
  if ($node->revision) {
    hosting_client_insert($node);
  }
  else {
    if ($node->uname) {
      $node->uname = hosting_client_sanitize($node->uname);
    }
    else {
      $node->uname = hosting_client_sanitize($node->title);
    }
    db_query("UPDATE {hosting_client} SET nid=%d, uname='%s' WHERE vid=%d", $node->nid, $node->uname, $node->vid);
  }
  if ($node->users) {
    foreach ($node->users as $user) {
      db_query('DELETE FROM {hosting_client_user} WHERE user = %d AND client = %d', $user, $node->nid);
    }
  }
  if ($node->new_user) {
    $user = user_load(array(
      'name' => $node->new_user,
    ));
    db_query('INSERT INTO {hosting_client_user} (client, user, contact_type) VALUES (%d, %d, "%s")', $node->nid, $user->uid, '');
  }
}