function hackedProjectWebDevDownloader::download in Hacked! 7.2
Download the version of the project to compare.
Return value
boolean TRUE if the download was successful; FALSE otherwise.
Overrides hackedProjectWebDownloader::download
File
- includes/
hackedProjectWebDevDownloader.inc, line 50
Class
- hackedProjectWebDevDownloader
- Downloads the dev version of a project.
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.
if (!$this
->git_clone($giturl, $destination, $branch)) {
watchdog('hacked', 'Could not clone project %project into path %path at branch %branch.', array(
'%project' => $module,
'%path' => $destination,
'%branch' => $branch,
), WATCHDOG_ERROR);
return FALSE;
}
// Attempt to checkout the last commit before timestamp on the local version.
if (!$this
->git_checkout($destination, $branch, $timestamp)) {
watchdog('hacked', 'Could not check out latest commit before %timestamp in Git repository %repository.', array(
'%timestamp' => $timestamp,
'%repository' => $destination,
), WATCHDOG_ERROR);
return FALSE;
}
// Add package information.
$lines = array();
$fp = fopen(drupal_get_path('module', $module) . "/{$module}.info", 'r');
$found_generated = FALSE;
while (!feof($fp)) {
$line = fgets($fp, 4096);
if (strrpos($line, '; Information added by', -strlen($line)) !== false) {
array_push($lines, PHP_EOL);
$found_generated = TRUE;
}
if ($found_generated) {
array_push($lines, $line);
}
}
fclose($fp);
if (count($lines)) {
file_put_contents("{$destination}/{$module}.info", $lines, FILE_APPEND);
}
return TRUE;
}