You are here

public function EndpointAccessibilityRequirement::verify in Acquia Content Hub 8

Verify the accessibility of the content hub endpoints.

Overrides ContentHubRequirementBase::verify

File

acquia_contenthub_diagnostic/src/Plugin/ContentHubRequirement/EndpointAccessibilityRequirement.php, line 53

Class

EndpointAccessibilityRequirement
Defines an endpoint accessibility requirement.

Namespace

Drupal\acquia_contenthub_diagnostic\Plugin\ContentHubRequirement

Code

public function verify() {

  // If Content Hub is not installed there is no reason to run this test.
  if (!$this->moduleHandler
    ->moduleExists('acquia_contenthub')) {
    return REQUIREMENT_OK;
  }
  $this->clientManager = \Drupal::service('acquia_contenthub.client_manager');
  if (!$this->clientManager
    ->isConnected()) {
    $this
      ->setValue($this
      ->t('Endpoint validation failed'));
    $this
      ->setDescription($this
      ->t('Client Manager not connected. Configure Content Hub and try again.'));
    return REQUIREMENT_ERROR;
  }
  $this->domain = $this
    ->getDomain();
  try {
    $this
      ->testWebhookEndpoint();
    $this
      ->testContentViewEndpoint();
    if ($this->description) {
      $this
        ->setValue($this
        ->t('Endpoint validation failed'));
      $this
        ->setDescription($this->description);
      return REQUIREMENT_ERROR;
    }
  } catch (\Exception $e) {
    $this
      ->setValue($this
      ->t('Cannot validate endpoints'));
    $this
      ->setDescription($this
      ->t('Verify your server and site configuration and try again. Error: @error', [
      '@error' => $e
        ->getMessage(),
    ]));
    return REQUIREMENT_ERROR;
  }
  return REQUIREMENT_OK;
}