1 installer.manager.inc installer_manager_batch_project_get($project, $url, &$context)

Batch callback: Downloads, unpacks, and verifies a project.

This function assumes that the provided URL points to a file archive of some sort. The URL can have any scheme that we have a file stream wrapper to support. The file is downloaded to a local cache.

Parameters

string $project: The short name of the project to download.

string $url: The URL to download a specific project release archive file.

array $context: Reference to an array used for Batch API storage.

See also

installer_manager_download_page()

Related topics

File

core/modules/installer/installer.manager.inc, line 1098
Administrative screens and processing functions of the Installer module.

Code

function installer_manager_batch_project_get($project, $url, &$context) {
  // This is here to show the user that we are in the process of downloading.
  if (!isset($context['sandbox']['started'])) {
    $context['sandbox']['started'] = TRUE;
    $context['message'] = t('Downloading %project', array('%project' => $project));
    $context['finished'] = 0;
    return;
  }

  // Actually try to download the file.
  if (!($local_cache = installer_manager_file_get($url))) {
    $context['results']['errors'][$project] = t('Failed to download %project from %url', array('%project' => $project, '%url' => $url));
    return;
  }

  // Extract it.
  $extract_directory = _installer_manager_extract_directory();
  try {
    installer_manager_archive_extract($local_cache, $extract_directory);
  }
  catch (Exception $e) {
    $context['results']['errors'][$project] = $e->getMessage();
    return;
  }

  // Verify it.
  $archive_errors = installer_manager_archive_verify($project, $local_cache, $extract_directory);
  if (!empty($archive_errors)) {
    // We just need to make sure our array keys don't collide, so use the
    // numeric keys from the $archive_errors array.
    foreach ($archive_errors as $key => $error) {
      $context['results']['errors']["$project-$key"] = $error;
    }
    return;
  }

  // Yay, success.
  $context['results']['projects'][$project] = $url;
  $context['finished'] = 1;
}