protected function DbUpdateController::results in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/src/Controller/DbUpdateController.php \Drupal\system\Controller\DbUpdateController::results()
- 9 core/modules/system/src/Controller/DbUpdateController.php \Drupal\system\Controller\DbUpdateController::results()
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.
1 call to DbUpdateController::results()
- DbUpdateController::handle in core/
modules/ system/ src/ Controller/ DbUpdateController.php - Returns a database update page.
File
- core/
modules/ system/ src/ Controller/ DbUpdateController.php, line 396
Class
- DbUpdateController
- Controller routines for database update routes.
Namespace
Drupal\system\ControllerCode
protected function results(Request $request) {
// @todo Simplify with https://www.drupal.org/node/2548095
$base_url = str_replace('/update.php', '', $request
->getBaseUrl());
// Retrieve and remove session information.
$session = $request
->getSession();
$update_results = $session
->remove('update_results');
$update_success = $session
->remove('update_success');
$session
->remove('update_ignore_warnings');
// 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>.', [
':url' => Url::fromRoute('dblog.overview')
->setOption('base_url', $base_url)
->toString(TRUE)
->getGeneratedUrl(),
]);
}
else {
$log_message = $this
->t('All errors have been logged.');
}
if ($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.', [
':url' => Url::fromRoute('<front>')
->setOption('base_url', $base_url)
->toString(TRUE)
->getGeneratedUrl(),
]) . ' ' . $log_message . '</p>';
}
else {
$last = $session
->get('updates_remaining');
$last = reset($last);
[
$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>.', [
'@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'] = [
'#markup' => $message,
];
$build['links'] = [
'#theme' => 'links',
'#links' => $this
->helpfulLinks($request),
];
// Output a list of info messages.
if (!empty($update_results)) {
$all_messages = [];
foreach ($update_results as $extension => $updates) {
if ($extension != '#abort') {
$extension_has_message = FALSE;
$info_messages = [];
foreach ($updates as $name => $queries) {
$messages = [];
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[] = [
'#wrapper_attributes' => [
'class' => [
'success',
],
],
'#markup' => $query['query'],
];
}
else {
$messages[] = [
'#wrapper_attributes' => [
'class' => [
'failure',
],
],
'#markup' => '<strong>' . $this
->t('Failed:') . '</strong> ' . $query['query'],
];
}
}
if ($messages) {
$extension_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[] = [
'#theme' => 'item_list',
'#items' => $messages,
'#title' => $title,
];
}
}
// If there were any messages then prefix them with the extension name
// and add it to the global message list.
if ($extension_has_message) {
$header = $this->moduleHandler
->moduleExists($extension) ? $this
->t('@module module', [
'@module' => $extension,
]) : $this
->t('@theme theme', [
'@theme' => $extension,
]);
$all_messages[] = [
'#type' => 'container',
'#prefix' => '<h3>' . $header . '</h3>',
'#children' => $info_messages,
];
}
}
}
if ($all_messages) {
$build['query_messages'] = [
'#type' => 'container',
'#children' => $all_messages,
'#attributes' => [
'class' => [
'update-results',
],
],
'#prefix' => '<h2>' . $this
->t('The following updates returned messages:') . '</h2>',
];
}
}
return $build;
}