You are here

protected function DomainCommands::deleteDomain in Domain Access 8

Deletes a domain record.

Parameters

\Drupal\domain\DomainInterface[] $domains: The domains to delete.

Throws

\Drupal\domain\Commands\DomainCommandException

\UnexpectedValueException

1 call to DomainCommands::deleteDomain()
DomainCommands::delete in domain/src/Commands/DomainCommands.php
Delete a domain from the site.

File

domain/src/Commands/DomainCommands.php, line 1152

Class

DomainCommands
Drush commands for the domain module.

Namespace

Drupal\domain\Commands

Code

protected function deleteDomain(array $domains) {
  foreach ($domains as $domain) {
    if (!$domain instanceof DomainInterface) {
      throw new StorageException('deleting domains: value is not a domain');
    }
    $hostname = $domain
      ->getHostname();
    if ($this->isDryRun) {
      $this
        ->logger()
        ->info(dt('DRYRUN: Domain record @domain deleted.', [
        '@domain' => $hostname,
      ]));
      continue;
    }
    try {
      $domain
        ->delete();
    } catch (EntityStorageException $e) {
      throw new DomainCommandException(dt('Unable to delete domain: @domain', [
        '@domain' => $hostname,
      ]), $e);
    }
    $this
      ->logger()
      ->info(dt('Domain record @domain deleted.', [
      '@domain' => $hostname,
    ]));
  }
}