You are here

acquia_agent.install in Acquia Connector 7.2

Install, update and uninstall functions for the acquia_agent module.

File

acquia_agent/acquia_agent.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the acquia_agent module.
 *
 */

/**
 * The minimum PHP memory recommended to install Acquia Drupal.
 */
define('ACQUIA_DRUPAL_MINIMUM_PHP_MEMORY', '32M');

// When update.php is being run, alter the list of updates according to
// Acquia's preferences.
if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update' && isset($_POST['start'])) {
  acquia_agent_alter_module_updates($_POST['start']);
}

/**
 * Implementation of hook_uninstall().
 */
function acquia_agent_uninstall() {
  variable_del('acquia_identifier');
  variable_del('acquia_key');
  variable_del('acquia_network_address');
  variable_del('acquia_subscription_data');
  variable_del('acquia_subscription_name');
  variable_del('acquia_agent_cloud_migration');
  variable_del('acquia_agent_debug');
  variable_del('acquia_agent_verify_peer');
  variable_del('acquia_dynamic_banner');
  variable_del('acquia_migrate_files');
  variable_del('acquia_banner_service');
  variable_del('acquia_agent_hide_signup_messages');
}

/**
 * Implementation of hook_disable().
 */
function acquia_agent_disable() {
  $mlid = db_query("SELECT mlid FROM {menu_links} WHERE link_title = 'acquia_subscription_status' AND menu_name = 'admin_menu'")
    ->fetchField();
  if ($mlid) {
    menu_link_delete($mlid);
  }
}

/**
 * Alter a list of module updates so that Acquia's updates run first.
 */
function acquia_agent_alter_module_updates(&$updates) {
  uksort($updates, '_acquia_agent_alter_module_updates_cmp');
}

/**
 * Comparison function for sorting module updates.
 */
function _acquia_agent_alter_module_updates_cmp($a, $b) {

  // Preserve the Drupal core behavior where system.module's updates run
  // first.
  if ($a == 'system' || $b == 'system') {
    return $a == 'system' ? -1 : 1;
  }
  elseif ($a == 'acquia_agent' || $b == 'acquia_agent') {
    return $a == 'acquia_agent' ? -1 : 1;
  }

  // Otherwise we don't care what order the updates run in.
  return 0;
}

/**
 * Implementation of hook_requirements()
 */
function acquia_agent_requirements($phase) {
  include_once 'acquia_agent.module';
  acquia_agent_load_versions();
  $requirements = array();
  $has_credentials = acquia_agent_has_credentials();
  $is_active = acquia_agent_subscription_is_active();
  $memory_limit = ini_get('memory_limit');
  switch ($phase) {
    case 'runtime':

      // Inform users on subscription status. Either we know they are active,
      // or we know they have credentials but not active (not set up yet) or
      // we have credentials but an inactive subscription (either bad
      // credentials or expired subscription).
      if ($is_active) {
        $requirements['acquia_subscription_status'] = array(
          'title' => t('Acquia subscription status'),
          'severity' => REQUIREMENT_OK,
          'value' => t('Active'),
          'description' => t('You can <a href="@refresh-status">manually refresh the subscription status</a>.', array(
            '@refresh-status' => url('admin/config/system/acquia-agent/refresh-status', array(
              'query' => drupal_get_destination(),
            )),
          )),
        );
      }
      elseif (!$has_credentials) {
        $requirements['acquia_subscription_status'] = array(
          'title' => t('Acquia subscription status'),
          'severity' => REQUIREMENT_WARNING,
          'value' => t('Unknown'),
          'description' => t('You did not complete your Acquia subscription signup. You can provide the subscription identifier and the subscription key at the <a href="@settings">Acquia settings</a> page or try to <a href="@refresh-status">manually refresh the subscription status</a>.', array(
            '@settings' => url('admin/config/system/acquia-agent'),
            '@refresh-status' => url('admin/config/system/acquia-agent/refresh-status', array(
              'query' => drupal_get_destination(),
            )),
          )),
        );
      }
      else {
        $subscription = variable_get('acquia_subscription_data', array(
          'active' => FALSE,
        ));
        $href = isset($subscription['href']) ? $subscription['href'] . '/health' : 'http://acquia.com/network';
        $requirements['acquia_subscription_status'] = array(
          'title' => t('Acquia subscription status'),
          'severity' => REQUIREMENT_WARNING,
          'value' => t('Inactive'),
          'description' => t('Your subscription is expired or you are using an invalid identifier and key pair. You can check the subscription identifier and the subscription key at the <a href="@settings">Acquia settings</a> page. Check <a href="@acquia-network">your Acquia Subscription</a> for further status information.', array(
            '@settings' => url('admin/config/system/acquia-agent'),
            '@acquia-network' => $href,
          )),
        );
      }

      // During runtime, we can't override the PHP memory limit provided by
      // Drupal core, so we supplement it with our own warning instead (but
      // only when necessary to do so).
      if (IS_ACQUIA_DRUPAL && $memory_limit && parse_size($memory_limit) < parse_size(ACQUIA_DRUPAL_MINIMUM_PHP_MEMORY)) {
        $description = t('Drupal core requires @drupal_php_memory_limit, but to take advantage of all the features of Acquia Drupal, we recommend @acquia_php_memory_limit (or more).', array(
          '@drupal_php_memory_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT,
          '@acquia_php_memory_limit' => ACQUIA_DRUPAL_MINIMUM_PHP_MEMORY,
        ));

        // Only append our instructions if they don't already have the ones
        // from Drupal core appearing on the screen.
        if (parse_size($memory_limit) >= parse_size(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT)) {
          if ($php_ini_path = get_cfg_var('cfg_file_path')) {
            $description .= ' ' . t('Increase the memory limit by editing the memory_limit parameter in the file %configuration-file and then restart your web server (or contact your system administrator or hosting provider for assistance).', array(
              '%configuration-file' => $php_ini_path,
            ));
          }
          else {
            $description .= ' ' . t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.');
          }
        }
        $requirements['acquia_php_memory_limit'] = array(
          'title' => t('PHP memory limit (Acquia Drupal)'),
          'description' => $description,
          'severity' => REQUIREMENT_WARNING,
          'value' => t('@memory_minimum_limit (or more) is recommended', array(
            '@memory_minimum_limit' => ACQUIA_DRUPAL_MINIMUM_PHP_MEMORY,
          )),
        );
      }
      break;
    case 'install':
      $t = get_t();
      if (IS_ACQUIA_DRUPAL && $memory_limit && parse_size($memory_limit) < parse_size(ACQUIA_DRUPAL_MINIMUM_PHP_MEMORY)) {

        // Override the PHP memory limit warning provided by Drupal core.
        $description = $t('Your PHP memory limit is currently set at %current_memory_limit. Increasing this to %memory_minimum_limit (or more) is recommended to help prevent errors in the installation process and later during operation of the site.', array(
          '%current_memory_limit' => $memory_limit,
          '%memory_minimum_limit' => ACQUIA_DRUPAL_MINIMUM_PHP_MEMORY,
        ));
        if ($php_ini_path = get_cfg_var('cfg_file_path')) {
          $description .= ' ' . $t('Increase the memory limit by editing the memory_limit parameter in the file %configuration-file and then restart your web server (or contact your system administrator or hosting provider for assistance).', array(
            '%configuration-file' => $php_ini_path,
          ));
        }
        else {
          $description .= ' ' . $t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.');
        }
        $requirements['php_memory_limit'] = array(
          'description' => $description,
          'severity' => REQUIREMENT_WARNING,
        );
      }

      // Ensure this module is compatible with the currently installed version of PHP.
      if (version_compare(phpversion(), 5.0) < 0) {
        $requirements['acquia_php_version'] = array(
          'description' => $t('The Acquia Connector modules require a PHP version of at least 5.0.'),
          'severity' => REQUIREMENT_ERROR,
        );
      }
      break;
  }
  return $requirements;
}

Functions

Namesort descending Description
acquia_agent_alter_module_updates Alter a list of module updates so that Acquia's updates run first.
acquia_agent_disable Implementation of hook_disable().
acquia_agent_requirements Implementation of hook_requirements()
acquia_agent_uninstall Implementation of hook_uninstall().
_acquia_agent_alter_module_updates_cmp Comparison function for sorting module updates.

Constants

Namesort descending Description
ACQUIA_DRUPAL_MINIMUM_PHP_MEMORY The minimum PHP memory recommended to install Acquia Drupal.