You are here

acquia_spi.install in Acquia Connector 7.3

Installer file for Acquia SPI module.

File

acquia_spi/acquia_spi.install
View source
<?php

/**
 * @file
 * Installer file for Acquia SPI module.
 */

// -- Core hooks ---------------------------------------------------------------

/**
 * Implements hook_uninstall().
 */
function acquia_spi_uninstall() {
  variable_del('acquia_spi_cron_last');
  variable_del('acquia_spi_cron_interval');
  variable_del('acquia_spi_cron_interval_override');
  variable_del('acquia_spi_use_cron');
  variable_del('acquia_welcome');
  variable_del('acquia_spi_boot_last');
  variable_del('acquia_spi_module_diff_data');
  variable_del('acquia_spi_admin_priv');
  variable_del('acquia_spi_send_node_user');
  variable_del('acquia_spi_send_watchdog');
  variable_del('acquia_spi_server');
  variable_del('acquia_spi_ssl_override');
  variable_del('acquia_spi_module_rebuild');
  variable_del('acquia_spi_set_variables_automatic');
  variable_del('acquia_spi_ignored_set_variables');
  variable_del('acquia_spi_saved_variables');
  variable_del('acquia_spi_set_variables_override');
  variable_del('acquia_spi_blocked');
  variable_del('acquia_spi_environment_changed_action');
  variable_del('acquia_spi_environment_changes');
  variable_del('acquia_spi_site_environment');
  variable_del('acquia_spi_env_detection_enabled');
  variable_del('acquia_spi_site_machine_name');
  variable_del('acquia_spi_site_name');
  variable_del('acquia_spi_site_uuid');
}

/**
 * Implements hook_requirements().
 */
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;
}

/**
 * Make sure new form is added to the menu.
 */
function acquia_spi_update_7001() {
  menu_rebuild();
}

/**
 * Delete the multisite related settings as it is not currently supported.
 */
function acquia_spi_update_7002() {
  variable_del('acquia_spi_is_multisite');
  variable_del('acquia_spi_multisite_identifier');
  variable_del('acquia_spi_machine_multisite_identifier');
}

/**
 * Delete the module diff data variable.
 */
function acquia_spi_update_7003() {
  variable_del('acquia_spi_module_diff_data');
}

Functions

Namesort descending Description
acquia_spi_requirements Implements hook_requirements().
acquia_spi_uninstall Implements hook_uninstall().
acquia_spi_update_7001 Make sure new form is added to the menu.
acquia_spi_update_7002 Delete the multisite related settings as it is not currently supported.
acquia_spi_update_7003 Delete the module diff data variable.