You are here

commerce_braintree.install in Commerce Braintree 7

File

commerce_braintree.install
View source
<?php

/**
 * Implements hook_enable().
 */
function commerce_braintree_enable() {
  $weight = db_select('system', 's')
    ->fields('s', array(
    'weight',
  ))
    ->condition('name', 'commerce_cardonfile', '=')
    ->execute()
    ->fetchField();
  db_update('system')
    ->fields(array(
    'weight' => $weight + 1,
  ))
    ->condition('type', 'module')
    ->condition('name', 'commerce_braintree')
    ->execute();
}

/**
 * Implements hook_requirements().
 *
 * Checks required BrainTree Libraries on Install
 */
function commerce_braintree_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time.
  $t = get_t();

  // Test PHP version.
  if (version_compare(phpversion(), '5.2.1', '<')) {
    $requirements['php']['description'] = $t('Your PHP installation is too old. Braintree requires at least PHP %version.', array(
      '%version' => '5.2.1',
    ));
    $requirements['php']['severity'] = REQUIREMENT_ERROR;
  }

  // Test Required PHP Extensions.
  $requiredExtensions = array(
    'xmlwriter',
    'SimpleXML',
    'openssl',
    'dom',
    'hash',
    'curl',
  );
  $disabled_extensions = array();
  $value = '';
  foreach ($requiredExtensions as $ext) {
    $ext_enabled = extension_loaded($ext) ? 'Enabled' : 'Disabled';
    $value .= $ext . ': ' . $ext_enabled . ' ';
    if ($ext_enabled == 'Disabled') {
      $disabled_extensions[] = $ext;
    }
  }
  $requirements['commerce_braintree_php_extensions'] = array(
    'title' => $t('Braintree PHP Extensions'),
    'value' => $phase == 'install' ? '' : $value,
  );
  if ($disabled_extensions) {
    $requirements['commerce_braintree_php_extensions']['severity'] = REQUIREMENT_ERROR;
    $requirements['commerce_braintree_php_extensions']['description'] = $t('The following PHP extensions must be enabled for Braintree: ' . implode(', ', $disabled_extensions));
  }
  return $requirements;
}