DbUpdateController::selection

protected DbUpdateController::selection(Request $request)

Renders a list of available database updates.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

Return value

array A render array.

File

core/modules/system/src/Controller/DbUpdateController.php, line 253

Class

DbUpdateController
Controller routines for database update routes.

Namespace

Drupal\system\Controller

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
protected function selection(Request $request) {
  // Make sure there is no stale theme registry.
  $this->cache->deleteAll();
 
  $count = 0;
  $incompatible_count = 0;
  $build['start'] = array(
    '#tree' => TRUE,
    '#type' => 'details',
  );
 
  // Ensure system.module's updates appear first.
  $build['start']['system'] = array();
 
  $starting_updates = array();
  $incompatible_updates_exist = FALSE;
  $updates_per_module = [];
  foreach (['update', 'post_update'] as $update_type) {
    switch ($update_type) {
      case 'update':
        $updates = update_get_update_list();
        break;
      case 'post_update':
        $updates = $this->postUpdateRegistry->getPendingUpdateInformation();
        break;
    }
    foreach ($updates as $module => $update) {
      if (!isset($update['start'])) {
        $build['start'][$module] = array(
          '#type' => 'item',
          '#title' => $module . ' module',
          '#markup' => $update['warning'],
          '#prefix' => '<div class="messages messages--warning">',
          '#suffix' => '</div>',
        );
        $incompatible_updates_exist = TRUE;
        continue;
      }
      if (!empty($update['pending'])) {
        $updates_per_module += [$module => []];
        $updates_per_module[$module] = array_merge($updates_per_module[$module], $update['pending']);
        $build['start'][$module] = array(
          '#type' => 'hidden',
          '#value' => $update['start'],
        );
        // Store the previous items in order to merge normal updates and
        // post_update functions together.
        $build['start'][$module] = array(
          '#theme' => 'item_list',
          '#items' => $updates_per_module[$module],
          '#title' => $module . ' module',
        );
 
        if ($update_type === 'update') {
          $starting_updates[$module] = $update['start'];
        }
      }
      if (isset($update['pending'])) {
        $count = $count + count($update['pending']);
      }
    }
  }
 
  // Find and label any incompatible updates.
  foreach (update_resolve_dependencies($starting_updates) as $data) {
    if (!$data['allowed']) {
      $incompatible_updates_exist = TRUE;
      $incompatible_count++;
      $module_update_key = $data['module'] . '_updates';
      if (isset($build['start'][$module_update_key]['#items'][$data['number']])) {
        if ($data['missing_dependencies']) {
          $text = $this->t('This update will been skipped due to the following missing dependencies:') . '<em>' . implode(', ', $data['missing_dependencies']) . '</em>';
        }
        else {
          $text = $this->t("This update will be skipped due to an error in the module's code.");
        }
        $build['start'][$module_update_key]['#items'][$data['number']] .= '<div class="warning">' . $text . '</div>';
      }
      // Move the module containing this update to the top of the list.
      $build['start'] = array($module_update_key => $build['start'][$module_update_key]) + $build['start'];
    }
  }
 
  // Warn the user if any updates were incompatible.
  if ($incompatible_updates_exist) {
    drupal_set_message($this->t('Some of the pending updates cannot be applied because their dependencies were not met.'), 'warning');
  }
 
  if (empty($count)) {
    drupal_set_message($this->t('No pending updates.'));
    unset($build);
    $build['links'] = array(
      '#theme' => 'links',
      '#links' => $this->helpfulLinks($request),
    );
 
    // No updates to run, so caches won't get flushed later.  Clear them now.
    drupal_flush_all_caches();
  }
  else {
    $build['help'] = array(
      '#markup' => '<p>' . $this->t('The version of Drupal you are updating from has been automatically detected.') . '</p>',
      '#weight' => -5,
    );
    if ($incompatible_count) {
      $build['start']['#title'] = $this->formatPlural(
      $count,
      '1 pending update (@number_applied to be applied, @number_incompatible skipped)',
      '@count pending updates (@number_applied to be applied, @number_incompatible skipped)',
      array('@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count)
      );
    }
    else {
      $build['start']['#title'] = $this->formatPlural($count, '1 pending update', '@count pending updates');
    }
    // @todo Simplify with https://www.drupal.org/node/2548095
    $base_url = str_replace('/update.php', '', $request->getBaseUrl());
    $url = (new Url('system.db_update', array('op' => 'run')))->setOption('base_url', $base_url);
    $build['link'] = array(
      '#type' => 'link',
      '#title' => $this->t('Apply pending updates'),
      '#attributes' => array('class' => array('button', 'button--primary')),
      '#weight' => 5,
      '#url' => $url,
      '#access' => $url->access($this->currentUser()),
    );
  }
 
  return $build;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.