You are here

public function SpiController::get in Acquia Connector 3.x

Same name and namespace in other branches
  1. 8.2 src/Controller/SpiController.php \Drupal\acquia_connector\Controller\SpiController::get()
  2. 8 src/Controller/SpiController.php \Drupal\acquia_connector\Controller\SpiController::get()

Gather site profile information about this site.

Parameters

string $method: Optional identifier for the method initiating request. Values could be 'cron' or 'menu callback' or 'drush'.

Return value

array An associative array keyed by types of information.

1 call to SpiController::get()
SpiController::sendFullSpi in src/Controller/SpiController.php
Gather full SPI data and send to Acquia.

File

src/Controller/SpiController.php, line 84

Class

SpiController
SPI Controller class.

Namespace

Drupal\acquia_connector\Controller

Code

public function get($method = '') {
  $config = $this->configFactory
    ->getEditable('acquia_connector.settings');

  // Get the Drupal version.
  $drupal_version = $this
    ->getVersionInfo();
  $stored = $this
    ->dataStoreGet([
    'platform',
  ]);
  if (!empty($stored['platform'])) {
    $platform = $stored['platform'];
  }
  else {
    $platform = $this
      ->getPlatform();
  }
  $acquia_hosted = $this
    ->checkAcquiaHosted();
  $environment = $this
    ->config('acquia_connector.settings')
    ->get('spi.site_environment');
  $env_detection_enabled = $this
    ->config('acquia_connector.settings')
    ->get('spi.env_detection_enabled');
  if ($acquia_hosted) {
    if ($environment != $_SERVER['AH_SITE_ENVIRONMENT']) {
      $config
        ->set('spi.site_environment', $_SERVER['AH_SITE_ENVIRONMENT']);
      $environment = $_SERVER['AH_SITE_ENVIRONMENT'];
      if ($env_detection_enabled) {
        $this
          ->state()
          ->set('spi.site_machine_name', $this
          ->getAcquiaHostedMachineName());
      }
    }
  }
  else {
    if ($environment) {
      $config
        ->set('spi.site_environment', NULL);
    }
    $environment = NULL;
  }
  if ($env_detection_enabled === NULL) {
    $config
      ->set('spi.env_detection_enabled', TRUE);
  }
  $config
    ->save();
  $spi = [
    // Used in HMAC validation.
    'rpc_version' => ACQUIA_CONNECTOR_ACQUIA_SPI_DATA_VERSION,
    // Used in Fix it now feature.
    'spi_data_version' => ACQUIA_CONNECTOR_ACQUIA_SPI_DATA_VERSION,
    'site_key' => sha1(\Drupal::service('private_key')
      ->get()),
    'site_uuid' => $this
      ->config('acquia_connector.settings')
      ->get('spi.site_uuid'),
    'env_changed_action' => $this
      ->config('acquia_connector.settings')
      ->get('spi.environment_changed_action'),
    'acquia_hosted' => $acquia_hosted,
    'name' => $this
      ->state()
      ->get('spi.site_name'),
    'machine_name' => $this
      ->state()
      ->get('spi.site_machine_name'),
    'environment' => $environment,
    'modules' => $this
      ->getModules(),
    'platform' => $platform,
    'quantum' => $this
      ->getQuantum(),
    'system_status' => $this
      ->getSystemStatus(),
    'failed_logins' => $this
      ->config('acquia_connector.settings')
      ->get('spi.send_watchdog') ? $this
      ->getFailedLogins() : [],
    '404s' => $this
      ->config('acquia_connector.settings')
      ->get('spi.send_watchdog') ? $this
      ->get404s() : [],
    'watchdog_size' => $this
      ->getWatchdogSize(),
    'watchdog_data' => $this
      ->config('acquia_connector.settings')
      ->get('spi.send_watchdog') ? $this
      ->getWatchdogData() : [],
    'last_nodes' => $this
      ->config('acquia_connector.settings')
      ->get('spi.send_node_user') ? $this
      ->getLastNodes() : [],
    'last_users' => $this
      ->config('acquia_connector.settings')
      ->get('spi.send_node_user') ? $this
      ->getLastUsers() : [],
    'extra_files' => $this
      ->checkFilesPresent(),
    'ssl_login' => $this
      ->checkLogin(),
    'distribution' => isset($drupal_version['distribution']) ? $drupal_version['distribution'] : '',
    'base_version' => $drupal_version['base_version'],
    'build_data' => $drupal_version,
    'roles' => Json::encode(user_roles()),
    'uid_0_present' => $this
      ->getUidZeroIsPresent(),
  ];
  $scheme = parse_url($this
    ->config('acquia_connector.settings')
    ->get('spi.server'), PHP_URL_SCHEME);
  $via_ssl = in_array('ssl', stream_get_transports(), TRUE) && $scheme == 'https' ? TRUE : FALSE;
  if ($this
    ->config('acquia_connector.settings')
    ->get('spi.ssl_override')) {
    $via_ssl = TRUE;
  }
  $additional_data = [];
  $security_review = new SecurityReviewController();
  $security_review_results = $security_review
    ->runSecurityReview();

  // It's worth sending along node access control information even if there
  // are no modules implementing it - some alerts are simpler if we know we
  // don't have to worry about node access.
  // Check for node grants modules.
  $additional_data['node_grants_modules'] = $this
    ->moduleHandler()
    ->getImplementations('node_grants');

  // Check for node access modules.
  $additional_data['node_access_modules'] = $this
    ->moduleHandler()
    ->getImplementations('node_access');
  if (!empty($security_review_results)) {
    $additional_data['security_review'] = $security_review_results['security_review'];
  }

  // Collect all user-contributed custom tests that pass validation.
  $custom_tests_results = $this
    ->testCollect();
  if (!empty($custom_tests_results)) {
    $additional_data['custom_tests'] = $custom_tests_results;
  }
  $spi_data = $this
    ->moduleHandler()
    ->invokeAll('acquia_connector_spi_get');
  if (!empty($spi_data)) {
    foreach ($spi_data as $name => $data) {
      if (is_string($name) && is_array($data)) {
        $additional_data[$name] = $data;
      }
    }
  }
  include_once "core/includes/update.inc";
  $additional_data['pending_updates'] = (bool) update_get_update_list();
  if (!empty($additional_data)) {

    // JSON encode this additional data.
    $spi['additional_data'] = json_encode($additional_data);
  }
  if (!empty($method)) {
    $spi['send_method'] = $method;
  }
  if (!$via_ssl) {
    return $spi;
  }
  else {
    $variablesController = new VariablesController();

    // Values returned only over SSL.
    $spi_ssl = [
      'system_vars' => $variablesController
        ->getVariablesData(),
      'settings_ra' => $this
        ->getSettingsPermissions(),
      'admin_count' => $this
        ->config('acquia_connector.settings')
        ->get('spi.admin_priv') ? $this
        ->getAdminCount() : '',
      'admin_name' => $this
        ->config('acquia_connector.settings')
        ->get('spi.admin_priv') ? $this
        ->getSuperName() : '',
    ];
    return array_merge($spi, $spi_ssl);
  }
}