You are here

function domain_update_7303 in Domain Access 7.3

Remove the zero record from the database.

File

./domain.install, line 244
Install file.

Code

function domain_update_7303(&$sandbox) {

  // We grab the default domain, remove it from the database, and
  // then re-save it into the table, using the new value as the default domain.
  $default = db_query("SELECT * FROM {domain} WHERE domain_id = 0")
    ->fetchAssoc();
  if (empty($default)) {
    return t('Domain Access did not find an existing domain 0. No updates required.');
  }

  // We have to do a delete and re-insert here to properly increment the id.
  // Since the module might be disabled, we can't use drupal_write_record();
  db_delete('domain')
    ->condition('domain_id', 0)
    ->execute();
  db_insert('domain')
    ->fields(array(
    'subdomain' => $default['subdomain'],
    'sitename' => $default['sitename'],
    'scheme' => $default['scheme'],
    'valid' => $default['valid'],
    'weight' => $default['weight'],
    'is_default' => $default['is_default'],
  ))
    ->execute();

  // Update tables that use a domain_id and we control directly.
  $default_id = db_query("SELECT domain_id FROM {domain} WHERE is_default = 1")
    ->fetchField();
  db_update('domain_editor')
    ->fields(array(
    'domain_id' => $default_id,
  ))
    ->condition('domain_id', 0)
    ->execute();
  db_update('domain_access')
    ->fields(array(
    'gid' => $default_id,
  ))
    ->condition('gid', 0)
    ->condition('realm', 'domain_id')
    ->execute();
  db_update('node_access')
    ->fields(array(
    'gid' => $default_id,
  ))
    ->condition('gid', 0)
    ->condition('realm', 'domain_id')
    ->execute();

  // Remove the old variables.
  variable_del('domain_root');
  variable_del('domain_sitename');
  variable_del('domain_scheme');

  // Update message.
  return t('Domain Access updated domain 0 successfully');
}