123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- <?php
- use Symfony\Component\HttpFoundation\RedirectResponse;
- function update_manager_download_batch_finished($success, $results) {
- if (!empty($results['errors'])) {
- $item_list = [
- '#theme' => 'item_list',
- '#title' => t('Downloading updates failed:'),
- '#items' => $results['errors'],
- ];
- drupal_set_message(\Drupal::service('renderer')->render($item_list), 'error');
- }
- elseif ($success) {
- drupal_set_message(t('Updates downloaded successfully.'));
- $_SESSION['update_manager_update_projects'] = $results['projects'];
- return new RedirectResponse(\Drupal::url('update.confirmation_page', [], ['absolute' => TRUE]));
- }
- else {
-
-
- drupal_set_message(t('Fatal error trying to download.'), 'error');
- }
- }
- function _update_manager_check_backends(&$form, $operation) {
-
-
-
-
- if (update_manager_local_transfers_allowed()) {
- return TRUE;
- }
-
- $form['available_backends'] = [
- '#prefix' => '<p>',
- '#suffix' => '</p>',
- ];
- $available_backends = drupal_get_filetransfer_info();
- if (empty($available_backends)) {
- if ($operation == 'update') {
- $form['available_backends']['#markup'] = t('Your server does not support updating modules and themes from this interface. Instead, update modules and themes by uploading the new versions directly to the server, as documented in <a href=":doc_url">Extending Drupal 8</a>.', [':doc_url' => 'https://www.drupal.org/docs/8/extending-drupal-8/overview']);
- }
- else {
- $form['available_backends']['#markup'] = t('Your server does not support installing modules and themes from this interface. Instead, install modules and themes by uploading them directly to the server, as documented in <a href=":doc_url">Extending Drupal 8</a>.', [':doc_url' => 'https://www.drupal.org/docs/8/extending-drupal-8/overview']);
- }
- return FALSE;
- }
- $backend_names = [];
- foreach ($available_backends as $backend) {
- $backend_names[] = $backend['title'];
- }
- if ($operation == 'update') {
- $form['available_backends']['#markup'] = \Drupal::translation()->formatPlural(
- count($available_backends),
- 'Updating modules and themes requires <strong>@backends access</strong> to your server. See <a href=":doc_url">Extending Drupal 8</a> for other update methods.',
- 'Updating modules and themes requires access to your server via one of the following methods: <strong>@backends</strong>. See <a href=":doc_url">Extending Drupal 8</a> for other update methods.',
- [
- '@backends' => implode(', ', $backend_names),
- ':doc_url' => 'https://www.drupal.org/docs/8/extending-drupal-8/overview',
- ]);
- }
- else {
- $form['available_backends']['#markup'] = \Drupal::translation()->formatPlural(
- count($available_backends),
- 'Installing modules and themes requires <strong>@backends access</strong> to your server. See <a href=":doc_url">Extending Drupal 8</a> for other installation methods.',
- 'Installing modules and themes requires access to your server via one of the following methods: <strong>@backends</strong>. See <a href=":doc_url">Extending Drupal 8</a> for other installation methods.',
- [
- '@backends' => implode(', ', $backend_names),
- ':doc_url' => 'https://www.drupal.org/docs/8/extending-drupal-8/overview',
- ]);
- }
- return TRUE;
- }
- function update_manager_archive_extract($file, $directory) {
- $archiver = archiver_get_archiver($file);
- if (!$archiver) {
- throw new Exception(t('Cannot extract %file, not a valid archive.', ['%file' => $file]));
- }
-
-
-
- $files = $archiver->listContents();
-
-
-
- $project = strtok($files[0], '/\\');
- $extract_location = $directory . '/' . $project;
- if (file_exists($extract_location)) {
- file_unmanaged_delete_recursive($extract_location);
- }
- $archiver->extract($directory);
- return $archiver;
- }
- function update_manager_archive_verify($project, $archive_file, $directory) {
- return \Drupal::moduleHandler()->invokeAll('verify_update_archive', [$project, $archive_file, $directory]);
- }
- function update_manager_file_get($url) {
- $parsed_url = parse_url($url);
- $remote_schemes = ['http', 'https', 'ftp', 'ftps', 'smb', 'nfs'];
- if (!isset($parsed_url['scheme']) || !in_array($parsed_url['scheme'], $remote_schemes)) {
-
- return drupal_realpath($url);
- }
-
- $cache_directory = _update_manager_cache_directory();
- $local = $cache_directory . '/' . drupal_basename($parsed_url['path']);
- if (!file_exists($local) || update_delete_file_if_stale($local)) {
- return system_retrieve_file($url, $local, FALSE, FILE_EXISTS_REPLACE);
- }
- else {
- return $local;
- }
- }
- function update_manager_batch_project_get($project, $url, &$context) {
-
- if (!isset($context['sandbox']['started'])) {
- $context['sandbox']['started'] = TRUE;
- $context['message'] = t('Downloading %project', ['%project' => $project]);
- $context['finished'] = 0;
- return;
- }
-
- if (!($local_cache = update_manager_file_get($url))) {
- $context['results']['errors'][$project] = t('Failed to download %project from %url', ['%project' => $project, '%url' => $url]);
- return;
- }
-
- $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;
- }
-
- $archive_errors = update_manager_archive_verify($project, $local_cache, $extract_directory);
- if (!empty($archive_errors)) {
-
-
- foreach ($archive_errors as $key => $error) {
- $context['results']['errors']["$project-$key"] = $error;
- }
- return;
- }
-
- $context['results']['projects'][$project] = $url;
- $context['finished'] = 1;
- }
- function update_manager_local_transfers_allowed() {
-
-
-
- $temporary_file = drupal_tempnam('temporary://', 'update_');
- $site_path = \Drupal::service('site.path');
- $local_transfers_allowed = fileowner($temporary_file) === fileowner($site_path);
-
-
- @drupal_unlink($temporary_file);
- return $local_transfers_allowed;
- }
|