You are here

function drush_domain_add in Domain Access 7.3

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

Add a new domain.

Parameters

$subdomain: The domain name to register.

$sitename: The sitename to use for this domain.

Return value

The domain created or an error message.

File

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

Code

function drush_domain_add($subdomain, $sitename) {
  $start_weight = (int) db_query("SELECT weight FROM {domain} ORDER BY weight DESC")
    ->fetchField();
  $record = array(
    'subdomain' => strtolower($subdomain),
    'sitename' => $sitename,
    'valid' => !drush_get_option('invalid') ? 1 : 0,
    'scheme' => !drush_get_option('https') ? 'http' : 'https',
    'weight' => ($weight = drush_get_option('weight')) ? $weight : $start_weight + 1,
    'is_default' => ($is_default = drush_get_option('is_default')) ? $is_default : 0,
  );
  if (!empty($record['is_default'])) {
    $error = domain_check_response($record, TRUE);
    if ($error) {
      return drush_set_error('domain', $error);
    }
  }
  $domain = domain_save($record, $record);
  if (isset($domain['domain_id'])) {
    drush_print(dt('Created @domain for @sitename.', array(
      '@domain' => $domain['subdomain'],
      '@sitename' => $domain['sitename'],
    )));
  }
  else {
    drush_print(dt('The request could not be completed.'));
  }
}