You are here

function hosting_client_update in Hosting 7.4

Same name and namespace in other branches
  1. 5 client/hosting_client.module \hosting_client_update()
  2. 6.2 client/hosting_client.module \hosting_client_update()
  3. 7.3 client/hosting_client.module \hosting_client_update()

Implements hook_update().

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

File

client/hosting_client.module, line 537

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_update('hosting_client')
      ->fields(array(
      'uname' => $node->uname,
    ))
      ->condition('nid', $node->nid)
      ->execute();
  }
  if ($node->users) {
    foreach ($node->users as $user) {
      db_delete('hosting_client_user')
        ->condition('user', $user)
        ->condition('client', $node->nid)
        ->execute();
    }
  }
  if ($node->new_user) {
    $user = user_load_multiple(array(), array(
      'name' => $node->new_user,
    ));
    $user = array_shift($user);
    $id = db_insert('hosting_client_user')
      ->fields(array(
      'client' => $node->nid,
      'user' => $user->uid,
      'contact_type' => '',
    ))
      ->execute();
  }
}