You are here

class hackedProjectWebFilesDownloader in Hacked! 6.2

Same name and namespace in other branches
  1. 7.2 includes/hackedProjectWebFilesDownloader.inc \hackedProjectWebFilesDownloader

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

Hierarchy

Expanded class hierarchy of hackedProjectWebFilesDownloader

File

includes/hacked_project.inc, line 437

View source
class hackedProjectWebFilesDownloader extends hackedProjectWebDownloader {
  function download_link() {
    $this_release = $this->project->project_info['releases'][$this->project->existing_version];
    return $this_release['download_link'];
  }
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
hackedProjectWebDownloader::$project property
hackedProjectWebDownloader::get_destination function Returns a directory to save the downloaded project into. 1
hackedProjectWebDownloader::get_final_destination function Returns the final destination of the unpacked project.
hackedProjectWebDownloader::get_temp_directory function Returns a temp directory to work in.
hackedProjectWebDownloader::hackedProjectWebDownloader function Constructor, pass in the project this downloaded is expected to download.
hackedProjectWebDownloader::remove_dir function Recursively delete all files and folders in the specified filepath, then delete the containing folder.
hackedProjectWebFilesDownloader::download function Download the remote files to the local filesystem. Overrides hackedProjectWebDownloader::download
hackedProjectWebFilesDownloader::download_link function