You are here

function _print_drush_download_lib in Printer, email and PDF versions 7.2

Download and extract the lib.

Parameters

string $library: Library to download.

string $url: URL of the file to download.

2 calls to _print_drush_download_lib()
drush_print_epub_download in print_epub/print_epub.drush.inc
Download and extract EPUB archive.
drush_print_pdf_download in print_pdf/print_pdf.drush.inc
Download and extract PDF archive.

File

includes/print.drush.inc, line 16
Common drush functions for the print submodules.

Code

function _print_drush_download_lib($library, $url) {
  $path = drush_get_option('path');
  if (empty($path)) {
    $path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries/' . $library;
  }

  // Create the path if it does not exist.
  if (!is_dir($path)) {
    drush_op('mkdir', $path);
    drush_log(dt('Directory @path was created', array(
      '@path' => $path,
    )), 'notice');
  }

  // Chdir to the download location.
  $olddir = getcwd();
  drush_op('chdir', $path);

  // Warn about an existing dir.
  if (is_dir($library)) {
    drush_log(dt('An existing @library was overwritten at @path', array(
      '@library' => $library,
      '@path' => $path . '/' . $library,
    )), 'notice');
  }
  if (preg_match('!api.github.com/repos/.*/releases/latest!', $url)) {
    $url = _print_drush_github_latest_url($url);
  }

  // Download the archive.
  $filename = _print_drush_download_file($url);
  if ($filename) {
    $extract_ret = _print_drush_download_extract($filename);
    if ($extract_ret) {

      // Remove the archive.
      drush_op('unlink', $filename);
      drush_log(dt('@file has been downloaded and extracted in @path', array(
        '@file' => $filename,
        '@path' => $path,
      )), 'success');
    }
    else {
      drush_log(dt('@file has been downloaded to @path, but extract failed. Check that you have the necessary program installed, and if necessary extract it manually.', array(
        '@file' => $filename,
        '@path' => $path,
      )), 'warning');
    }
  }
  else {
    drush_log(dt('Drush was unable to download @library to @path', array(
      '@library' => $library,
      '@path' => $path,
    )), 'error');
  }

  // Set working directory back to the previous working directory.
  drush_op('chdir', $olddir);
}