You are here

function drush_domain_delete in Domain Access 7.3

Same name and namespace in other branches
  1. 8 domain/domain.drush.inc \drush_domain_delete()

Delete a domain record.

File

./domain.drush.inc, line 325
Drush commands for Domain Access.

Code

function drush_domain_delete($argument = NULL) {
  if (is_null($argument)) {
    drush_set_error('domain', dt('You must specify a domain to delete.'));
  }

  // Resolve the domain.
  if ($domain = drush_domain_get_from_argument($argument)) {
    $domains = array(
      $domain,
    );
  }
  else {
    return;
  }
  if (!empty($domain['is_default'])) {
    return drush_set_error('domain', dt('The primary domain may not be deleted.'));
  }

  // Set options for re-assigning content.
  $list = domain_domains();
  $options = array(
    '0' => t('Do not reassign'),
  );
  foreach ($list as $data) {
    if ($data['domain_id'] != $domain['domain_id']) {
      $options[$data['domain_id']] = $data['subdomain'];
    }
  }
  $content = drush_choice($options, t('Reassign content to:'), '!value');
  if (empty($content)) {
    return;
  }
  $users = drush_choice($options, t('Reassign users to:'), '!value');
  if (empty($users)) {
    return;
  }
  $values['domain_access'] = !empty($content) ? $content : 'none';
  $values['domain_editor'] = !empty($content) ? $users : 'none';
  domain_delete($domain, $values);
  drush_print(dt('Domain record deleted.'));
}