You are here

function hackedProjectWebFilesDownloader::download in Hacked! 6.2

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

Download the remote files to the local filesystem.

Overrides hackedProjectWebDownloader::download

File

includes/hacked_project.inc, line 444

Class

hackedProjectWebFilesDownloader
Downloads a project using a standard web method, and unpacking the tar-ball.

Code

function download() {
  $dir = $this
    ->get_destination();
  $release_url = $this
    ->download_link();

  // If our directory already exists, we can just return the path to this cached version
  if (file_exists($dir)) {
    return $dir;
  }

  // We've not downloaded this release before:
  // Let's try to download it:
  $request = drupal_http_request($release_url);

  // If we downloaded it, try to unpack it:
  if ($request->code == 200) {

    // Build the destination folder tree if it doesn't already exists.
    if (!file_check_directory($dir, FILE_CREATE_DIRECTORY) && !mkdir($dir, 0775, TRUE)) {
      watchdog('hacked', 'Failed to create temp directory: %dir', array(
        '%dir' => $dir,
      ), WATCHDOG_ERROR);
      return FALSE;
    }

    // Save the tarball someplace:
    $project_path = file_create_path($dir . '/' . basename($release_url));
    file_save_data($request->data, $project_path);
    shell_exec("cd {$dir}; tar -zxf " . basename($project_path));
    file_delete($project_path);
    return TRUE;
  }

  // Something went wrong:
  return FALSE;
}