function drush_domain_delete in Domain Access 8
Same name and namespace in other branches
- 7.3 domain.drush.inc \drush_domain_delete()
Deletes a domain record.
Parameters
string $argument: The domain_id to delete. Pass 'all' to delete all records.
File
- domain/
domain.drush.inc, line 433 - 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.'));
}
if ($argument == 'all') {
$domains = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple(NULL, TRUE);
if (empty($domains)) {
drush_print(dt('There are no domains to delete.'));
return;
}
$content = drush_choice([
1 => dt('Delete all domains'),
], dt('This action may not be undone. Continue?'), '!value');
if (empty($content)) {
return;
}
}
elseif ($domain = drush_domain_get_from_argument($argument)) {
if ($domain
->isDefault()) {
return drush_set_error('domain', dt('The primary domain may not be deleted. Use drush domain-default to set a new default domain.'));
}
$domains = [
$domain,
];
}
else {
return;
}
foreach ($domains as $domain) {
$domain
->delete();
drush_print(dt('Domain record @domain deleted.', [
'@domain' => $domain
->getHostname(),
]));
}
return;
// TODO: Set options for re-assigning content.
$list = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple(NULL, TRUE);
$options = [
'0' => dt('Do not reassign'),
];
foreach ($list as $data) {
if ($data
->id() != $domain
->id()) {
$options[$data
->getDomainId()] = $data
->getHostname();
}
}
$content = drush_choice($options, dt('Reassign content to:'), '!value');
if (empty($content)) {
return;
}
$users = drush_choice($options, dt('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.'));
}