<?php

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

/**
 * Implements hook_requirements().
 */
function uc_authorizenet_requirements($phase) {
  $t = get_t();

  $has_curl = function_exists('curl_init');

  $requirements['uc_authorizenet_curl'] = array(
    'title' => $t('cURL'),
    'value' => $has_curl ? $t('Enabled') : $t('Not found'),
  );
  if (!$has_curl) {
    $requirements['uc_authorizenet_curl']['severity'] = REQUIREMENT_ERROR;
    $requirements['uc_authorizenet_curl']['description'] = $t("Authorize.net requires the PHP <a href='!curl_url'>cURL</a> library.", array('!curl_url' => 'http://php.net/manual/en/curl.setup.php'));
  }

  return $requirements;
}

/**
 * Implements hook_uninstall().
 */
function uc_authorizenet_uninstall() {
  // Delete related variables all at once.
  db_delete('variable')
    ->condition('name', 'uc_authnet_%', 'LIKE')
    ->execute();
}

/**
 * Implements hook_update_last_removed().
 */
function uc_authorizenet_update_last_removed() {
  return 3;
}
