You are here

function hackedProjectWebFilesDownloader::download in Hacked! 7.2

Same name and namespace in other branches
  1. 6.2 includes/hacked_project.inc \hackedProjectWebFilesDownloader::download()

Download the remote files to the local filesystem.

Overrides hackedProjectWebDownloader::download

File

includes/hackedProjectWebFilesDownloader.inc, line 15

Class

hackedProjectWebFilesDownloader
Downloads a project using a standard Drupal method.

Code

function download() {
  $dir = $this
    ->get_destination();
  if (!($release_url = $this
    ->download_link())) {
    return FALSE;
  }

  // If our directory already exists, we can just return the path to this cached version
  if (file_exists($dir) && count(hacked_file_scan_directory($dir, '/.*/', array(
    '.',
    '..',
    'CVS',
    '.svn',
    '.git',
  )))) {
    return $dir;
  }

  // Build the destination folder tree if it doesn't already exists.
  if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY) && !mkdir($dir, 0775, TRUE)) {
    watchdog('hacked', 'Failed to create temp directory: %dir', array(
      '%dir' => $dir,
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  if (!($local_file = $this
    ->file_get($release_url))) {
    watchdog('hacked', 'Could not download the project: @name from URL: @url', array(
      '@name' => $this->project
        ->title(),
      '@url' => $release_url,
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  try {
    $this
      ->archive_extract($local_file, $dir);
  } catch (Exception $e) {
    watchdog('hacked', 'Could not extract the project: @name. Error was: !error', array(
      '@name' => $this->project
        ->title(),
      '!error' => $e
        ->getMessage(),
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  return TRUE;
}