You are here

acquia_spi.install in Acquia Connector 6.2

Installer file for Acquia SPI module.

File

acquia_spi/acquia_spi.install
View source
<?php

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

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

/**
 * Implementation of 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');
}

/**
 * Implementation of 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) {
        $key = sha1(drupal_get_private_key());
        $config_url = $description = $interval = '';
        $ago = time() - $last_sent;
        if ($ago >= 60 * 60 * 36) {

          // 1.5 days ago.
          $severity = REQUIREMENT_WARNING;
          $description = 'SPI data has not been reported to Acquia Insight for more than a day.<br/>';
        }
        else {
          $severity = REQUIREMENT_OK;
        }
        if (!$use_cron) {
          $config_url = url('admin/settings/acquia-agent');
          $description .= 'You are not sending SPI data via Drupal\'s cron system. <a href="!config-page">View Acquia subscription configuration</a> for details.<br/>';
        }
        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 .= 'SPI data will be sent once every !interval minutes once cron is called. ';
        }
        $description .= 'You can <a href="!spi-send">manually send SPI data</a>.';
        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 SPI'),
          'severity' => $severity,
          'value' => $value,
          'description' => t($description, array(
            '!interval' => $interval,
            '!config-page' => $config_url,
            '!spi-send' => url('system/acquia-spi-send', array(
              'query' => array(
                'destination' => 'admin/reports/status',
                'key' => $key,
              ),
            )),
          )),
        );
      }

      // 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 SPI Custom Tests'),
        'description' => t($description, $variables),
        'value' => t($value, $variables),
        'severity' => $severity,
      );
      break;
  }
  return $requirements;
}

Functions

Namesort descending Description
acquia_spi_requirements Implementation of hook_requirements().
acquia_spi_uninstall Implementation of hook_uninstall().