You are here

function acquia_spi_requirements in Acquia Connector 7.3

Same name and namespace in other branches
  1. 6.2 acquia_spi/acquia_spi.install \acquia_spi_requirements()
  2. 7.2 acquia_spi/acquia_spi.install \acquia_spi_requirements()

Implements hook_requirements().

File

acquia_spi/acquia_spi.install, line 44
Installer file for Acquia SPI module.

Code

function acquia_spi_requirements($phase) {
  $requirements = array();
  $last_sent = variable_get('acquia_spi_cron_last', 0);
  $use_cron = variable_get('acquia_spi_use_cron', 1);
  switch ($phase) {
    case 'runtime':
      $has_credentials = acquia_agent_has_credentials();
      if ($has_credentials) {
        $config_url = '';
        $description = '';
        $interval = '';
        $key = sha1(drupal_get_private_key());
        $blocked = variable_get('acquia_spi_blocked', FALSE);
        $environment_change_detected = acquia_spi_environment_change_detected();
        $environment_changes = variable_get('acquia_spi_environment_changes');
        $off_acquia_hosting = $environment_change_detected ? array_key_exists('acquia_hosted', $environment_changes) && !acquia_spi_check_acquia_hosted() : FALSE;
        $ago = REQUEST_TIME - $last_sent;
        $name_required = is_null(variable_get('acquia_spi_site_name')) && is_null(variable_get('acquia_spi_site_machine_name')) && !acquia_spi_check_acquia_hosted();
        if ($blocked) {
          $severity = REQUIREMENT_WARNING;
          $config_url = url('admin/config/system/acquia-agent/environment-change');
          $description = t('This site has been disabled from sending profile data to Acquia Cloud. <a href="!config-page">Enable this site</a>.', array(
            '!config-page' => $config_url,
          ));
        }
        elseif ($off_acquia_hosting) {
          $severity = REQUIREMENT_ERROR;
          $config_url = url('admin/config/system/acquia-agent/environment-change');
          $description = t('This site is not hosted on Acquia Cloud and is not connected to Acquia Insight. You might see this message if you have created a new Drupal site using a database dump from a site that is hosted on Acquia Cloud. You can <a href="!config-page">connect this site to Acquia Insight</a>.', array(
            '!config-page' => $config_url,
          ));
        }
        elseif ($environment_change_detected) {
          $severity = REQUIREMENT_ERROR;
          $config_url = url('admin/config/system/acquia-agent/environment-change');
          $description = t('A change in your site\'s environment has been detected. SPI data cannot be submitted until this is resolved. Please <a href="!config-page">confirm the action you wish to take</a>.', array(
            '!config-page' => $config_url,
          ));
        }
        elseif ($name_required) {
          $severity = REQUIREMENT_ERROR;
          $config_url = url('admin/config/system/acquia-agent');
          $description = t('You are not currently sending site profile data to Acquia Insight. You can <a href="!config-page">connect this site to Acquia Insight</a>.', array(
            '!config-page' => $config_url,
          ));
        }
        elseif ($ago >= 60 * 60 * 36) {
          $severity = REQUIREMENT_WARNING;
          $description = t('SPI data has not been reported to the Acquia Subscription for more than a day.<br/>');
        }
        else {
          $severity = REQUIREMENT_OK;
        }
        if (!$environment_change_detected && !$blocked && !$name_required) {
          if (!$use_cron) {
            $config_url = url('admin/config/system/acquia-agent');
            $description .= t('You are not sending site profile data to Acquia Cloud via Drupal\'s cron system. <a href="!config-page">View Acquia Subscription configuration</a> for details.<br/>', array(
              '!config-page' => $config_url,
            ));
          }
          else {
            $interval = variable_get('acquia_spi_cron_interval', 30);
            if (variable_get('acquia_spi_cron_interval_override', FALSE)) {
              $interval = variable_get('acquia_spi_cron_interval_override', 30);
            }
            $description .= t('SPI data will be sent once every !interval minutes once cron is called.', array(
              '!interval' => $interval,
            )) . ' ';
          }
          $description .= t('You can <a href="!spi-send">manually send SPI data</a>.', array(
            '!spi-send' => url('system/acquia-spi-send', array(
              'query' => array(
                'destination' => 'admin/reports/status',
                'key' => $key,
              ),
            )),
          ));
        }
        if ($last_sent == 0) {
          $value = t('SPI data has not been sent');
        }
        else {
          $value = t('Last sent !time ago', array(
            '!time' => format_interval($ago),
          ));
        }
        $requirements['acquia_spi'] = array(
          'title' => t('Acquia Insight'),
          'severity' => $severity,
          'value' => $value,
          'description' => $description,
        );
      }

      // Acquia SPI custom tests status.
      $variables = array(
        '@help' => url('admin/help/acquia_agent'),
        '@validate' => url('system/acquia-spi-custom-test-validate'),
      );
      $modules = module_implements('acquia_spi_test');
      if (empty($modules)) {
        $description = 'No custom tests were detected in any module.<br/>';
        $value = 'Not implemented (<a href="@help">more information</a>)';
        $severity = REQUIREMENT_OK;
      }
      else {
        $result = acquia_spi_test_status();
        if (!empty($result)) {
          $modules = implode(', ', array_keys($result));
          $description = 'Custom tests within the following module(s) have failed validation and will not be sent: %modules. <br/>Please check the error logs for more information regarding how to pass validation or <a href="@validate">perform another validation check</a>. (A validation check can also be performed via the Drush command, "spi-test-validate.")';
          $value = 'Failed (<a href="@help">more information</a>)';
          $severity = REQUIREMENT_ERROR;
        }
        else {
          $modules = implode(', ', $modules);
          $description = 'Custom test data is structured properly and is sending from: %modules';
          $value = 'Passed';
          $severity = REQUIREMENT_OK;
        }
        $variables['%modules'] = $modules;
      }
      $requirements['acquia_spi_test'] = array(
        'title' => t('Acquia Insight Custom Tests'),
        // phpcs:ignore
        'description' => t($description, $variables),
        // phpcs:ignore
        'value' => t($value, $variables),
        'severity' => $severity,
      );
      break;
  }
  return $requirements;
}