You are here

function hackedProjectWebDevDownloader::download in Hacked! 8.2

Download the version of the project to compare.

Return value

boolean TRUE if the download was successful; FALSE otherwise.

Overrides hackedProjectWebDownloader::download

File

src/hackedProjectWebDevDownloader.php, line 55

Class

hackedProjectWebDevDownloader
Downloads a development snapshot of a project using Git.

Namespace

Drupal\hacked

Code

function download() {

  // Get detailed information about the download.
  $destination = $this
    ->get_destination();
  $info = $this
    ->download_link();
  $giturl = $info['giturl'];
  $branch = $info['branch'];
  $module = $info['module'];
  $timestamp = $info['timestamp'];

  // Return the path if the project version has already been downloaded to
  // the cache.
  if (file_exists($destination)) {
    return $destination;
  }

  // Clone the project repository and check out the appropriate branch.
  try {
    $this
      ->git_clone($giturl, $destination, $branch);
  } catch (Exception $e) {
    \Drupal::logger('hacked')
      ->error($e
      ->getMessage());
    return FALSE;
  }

  // Attempt to checkout the last commit before timestamp on the local version.
  try {
    $this
      ->git_checkout($destination, $branch, $timestamp);
  } catch (Exception $e) {
    \Drupal::logger('hacked')
      ->error($e
      ->getMessage());
    return FALSE;
  }
  return TRUE;
}