DbUpdateController::results

protected DbUpdateController::results(Request $request)

Displays results of the update script with any accompanying errors.

Parameters

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

Return value

array A render array.

File

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

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
protected function results(Request $request) {
  // @todo Simplify with https://www.drupal.org/node/2548095
  $base_url = str_replace('/update.php', '', $request->getBaseUrl());
 
  // Report end result.
  $dblog_exists = $this->moduleHandler->moduleExists('dblog');
  if ($dblog_exists && $this->account->hasPermission('access site reports')) {
    $log_message = $this->t('All errors have been <a href=":url">logged</a>.', array(
      ':url' => Url::fromRoute('dblog.overview')->setOption('base_url', $base_url)->toString(TRUE)->getGeneratedUrl(),
    ));
  }
  else {
    $log_message = $this->t('All errors have been logged.');
  }
 
  if (!empty($_SESSION['update_success'])) {
    $message = '<p>' . $this->t('Updates were attempted. If you see no failures below, you may proceed happily back to your <a href=":url">site</a>. Otherwise, you may need to update your database manually.', array(':url' => Url::fromRoute('<front>')->setOption('base_url', $base_url)->toString(TRUE)->getGeneratedUrl())) . ' ' . $log_message . '</p>';
  }
  else {
    $last = reset($_SESSION['updates_remaining']);
    list($module, $version) = array_pop($last);
    $message = '<p class="error">' . $this->t('The update process was aborted prematurely while running <strong>update #@version in @module.module</strong>.', array(
      '@version' => $version,
      '@module' => $module,
    )) . ' ' . $log_message;
    if ($dblog_exists) {
      $message .= ' ' . $this->t('You may need to check the <code>watchdog</code> database table manually.');
    }
    $message .= '</p>';
  }
 
  if (Settings::get('update_free_access')) {
    $message .= '<p>' . $this->t("<strong>Reminder: don't forget to set the <code>\$settings['update_free_access']</code> value in your <code>settings.php</code> file back to <code>FALSE</code>.</strong>") . '</p>';
  }
 
  $build['message'] = array(
    '#markup' => $message,
  );
  $build['links'] = array(
    '#theme' => 'links',
    '#links' => $this->helpfulLinks($request),
  );
 
  // Output a list of info messages.
  if (!empty($_SESSION['update_results'])) {
    $all_messages = array();
    foreach ($_SESSION['update_results'] as $module => $updates) {
      if ($module != '#abort') {
        $module_has_message = FALSE;
        $info_messages = array();
        foreach ($updates as $name => $queries) {
          $messages = array();
          foreach ($queries as $query) {
            // If there is no message for this update, don't show anything.
            if (empty($query['query'])) {
              continue;
            }
 
            if ($query['success']) {
              $messages[] = array(
                '#wrapper_attributes' => array('class' => array('success')),
                '#markup' => $query['query'],
              );
            }
            else {
              $messages[] = array(
                '#wrapper_attributes' => array('class' => array('failure')),
                '#markup' => '<strong>' . $this->t('Failed:') . '</strong> ' . $query['query'],
              );
            }
          }
 
          if ($messages) {
            $module_has_message = TRUE;
            if (is_numeric($name)) {
              $title = $this->t('Update #@count', ['@count' => $name]);
            }
            else {
              $title = $this->t('Update @name', ['@name' => trim($name, '_')]);
            }
            $info_messages[] = array(
              '#theme' => 'item_list',
              '#items' => $messages,
              '#title' => $title,
            );
          }
        }
 
        // If there were any messages then prefix them with the module name
        // and add it to the global message list.
        if ($module_has_message) {
          $all_messages[] = array(
            '#type' => 'container',
            '#prefix' => '<h3>' . $this->t('@module module', array('@module' => $module)) . '</h3>',
            '#children' => $info_messages,
          );
        }
      }
    }
    if ($all_messages) {
      $build['query_messages'] = array(
        '#type' => 'container',
        '#children' => $all_messages,
        '#attributes' => array('class' => array('update-results')),
        '#prefix' => '<h2>' . $this->t('The following updates returned messages:') . '</h2>',
      );
    }
  }
  unset($_SESSION['update_results']);
  unset($_SESSION['update_success']);
  unset($_SESSION['update_ignore_warnings']);
 
  return $build;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.