You are here

function drush_domain_test in Domain Access 8

Same name and namespace in other branches
  1. 7.3 domain.drush.inc \drush_domain_test()

Tests a domain record for the proper HTTP response.

Parameters

string $argument: The domain_id to test. Passing no value tests all records.

File

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

Code

function drush_domain_test($argument = NULL) {

  // TODO: This won't work in a subdirectory without a parameter.
  if ($base_path = drush_get_option('base_path')) {
    $GLOBALS['base_path'] = '/' . $base_path . '/';
  }
  if (is_null($argument)) {
    $domains = \Drupal::entityTypeManager()
      ->getStorage('domain')
      ->loadMultiple(NULL, TRUE);
  }
  else {
    if ($domain = drush_domain_get_from_argument($argument)) {
      $domains = [
        $domain,
      ];
    }
    else {
      return;
    }
  }
  foreach ($domains as $domain) {
    if ($domain
      ->getResponse() != 200) {
      drush_print(dt('Fail: !error. Please pass a --uri parameter or a --base_path to retest.', [
        '!error' => $domain
          ->getResponse(),
      ]));
    }
    else {
      drush_print(dt('Success: !url tested successfully.', [
        '!url' => $domain
          ->getPath(),
      ]));
    }
  }
}