update_manager_batch_project_get

7 update.manager.inc update_manager_batch_project_get($project, $url, &$context)
8 update.manager.inc update_manager_batch_project_get($project, $url, &$context)

Batch operation: download, unpack, and verify 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 BatchAPI storage.

See also

update_manager_download_page()

Related topics

1 string reference to 'update_manager_batch_project_get'

File

modules/update/update.manager.inc, line 845
Administrative screens and processing functions for the update manager. This allows site administrators with the 'administer software updates' permission to either upgrade existing projects, or download and install new ones, so long as the…

Code

function update_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 = update_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 = _update_manager_extract_directory();
  try {
    update_manager_archive_extract($local_cache, $extract_directory);
  }
  catch (Exception $e) {
    $context['results']['errors'][$project] = $e->getMessage();
    return;
  }

  // Verify it.
  $archive_errors = update_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;
}
Login or register to post comments