You are here

function drush_stripe_library_download in Stripe 7

Command callback for drush_stripe_library_download.

File

./stripe.drush.inc, line 32
Drush commands for Stripe module.

Code

function drush_stripe_library_download() {
  $destination = DRUPAL_ROOT . '/sites/all/libraries';
  drush_log($destination);

  // Create sites/all/libraries if necessary.
  if (!is_dir($destination)) {
    drush_log(dt('The sites/all/libraries directory does not exist.'), 'warning');
    $confirm = drush_confirm(dt('Would you like to create it?'));
    if (!$confirm || !drush_mkdir($destination)) {
      drush_log(dt('Unable to download Stripe to sites/all/libraries.'), 'error');
      return FALSE;
    }
  }
  $path = drush_download_file('https://code.stripe.com/stripe-php-latest.tar.gz');
  drush_log($path);
  $file_list = drush_tarball_extract($path, $destination, TRUE);
  dlm($file_list);
  if (empty($file_list)) {
    drush_log(dt('Unable to extract the Stripe PHP Library.'), 'error');
    return FALSE;
  }

  // Now move the directory to sites/all/libraries/stripe-php.
  $directory = reset($file_list);
  if (!drush_move_dir("{$destination}/{$directory}", "{$destination}/stripe-php", TRUE)) {
    drush_log(dt('Unable to move the Stripe PHP Library to sites/all/libraries/stripe-php'), 'error');
    return FALSE;
  }

  // Parse the version number from the original directory.
  $version = str_replace('stripe-php-', '', $directory);
  $dt_args = array(
    '@version' => rtrim($version, '/'),
  );
  $message = dt('Copied the Stripe PHP Library version @version to sites/all/libraries/stripe-php.', $dt_args);
  drush_log($message, 'success');
}