You are here

function domain_user_domainupdate in Domain Access 6.2

Same name and namespace in other branches
  1. 5 domain_user/domain_user.module \domain_user_domainupdate()

Implement hook_domainupdate()

File

domain_user/domain_user.module, line 301
Creates unique subdomains for registered users.

Code

function domain_user_domainupdate($op, $domain, $form_state = array()) {
  $root = variable_get('domain_user_root', variable_get('domain_root', ''));
  switch ($op) {
    case 'update':

      // If these are different, then we must delete a row from {access}.
      if (isset($form_state['values']['subdomain']) && $domain['subdomain'] != $form_state['values']['subdomain']) {
        $mask = str_replace('.' . $root, '', $domain['subdomain']);
        db_query("DELETE FROM {access} WHERE mask = '%s'", $mask);
      }
      domain_user_rules();
      break;
    case 'delete':

      // Delete from {domain_user}
      db_query("DELETE FROM {domain_user} WHERE domain_id = %d", $domain['domain_id']);

      // Move from user domain to default domain for {domain_editor}
      $check = db_result(db_query("SELECT 1 FROM {domain_editor} WHERE uid = %d AND domain_id = 0", $domain['uid']));
      if (empty($check)) {
        db_query("INSERT INTO {domain_editor} (domain_id, uid) VALUES (0, %d)", $domain['uid'], $domain['domain_id']);
      }
      else {
        db_query("DELETE FROM {domain_editor} WHERE uid = %d AND domain_id = %d", $domain['uid'], $domain['domain_id']);
      }

      // Delete from the access rules.
      $user_root = variable_get('domain_user_root', variable_get('domain_root', ''));
      $mask = str_replace('.' . $user_root, '', $domain['subdomain']);
      db_query("DELETE FROM {access} WHERE mask = '%s'", $mask);
      break;
  }
}