function update_results_page() { drupal_set_title('Drupal database update'); $links = update_helpful_links(); update_task_list(); // Report end result if (module_exists('dblog')) { $log_message = ' All errors have been <a href="' . base_path() . '?q=admin/reports/dblog">logged</a>.'; } else { $log_message = ' All errors have been logged.'; } if ($_SESSION['update_success']) { $output = '<p>Updates were attempted. If you see no failures below, you may proceed happily to the <a href="' . base_path() . '?q=admin">administration pages</a>. Otherwise, you may need to update your database manually.' . $log_message . '</p>'; } else { list($module, $version) = array_pop(reset($_SESSION['updates_remaining'])); $output = '<p class="error">The update process was aborted prematurely while running <strong>update #' . $version . ' in ' . $module . '.module</strong>.' . $log_message; if (module_exists('dblog')) { $output .= ' You may need to check the <code>watchdog</code> database table manually.'; } $output .= '</p>'; } if (!empty($GLOBALS['update_free_access'])) { $output .= "<p><strong>Reminder: don't forget to set the <code>\$update_free_access</code> value in your <code>settings.php</code> file back to <code>FALSE</code>.</strong></p>"; } $output .= theme('item_list', array('items' => $links)); // Output a list of queries executed if (!empty($_SESSION['update_results'])) { $output .= '<div id="update-results">'; $output .= '<h2>The following updates returned messages</h2>'; foreach ($_SESSION['update_results'] as $module => $updates) { $output .= '<h3>' . $module . ' module</h3>'; foreach ($updates as $number => $queries) { if ($number != '#abort') { $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[] = '<li class="success">' . $query['query'] . '</li>'; } else { $messages[] = '<li class="failure"><strong>Failed:</strong> ' . $query['query'] . '</li>'; } } if ($messages) { $output .= '<h4>Update #' . $number . "</h4>\n"; $output .= '<ul>' . implode("\n", $messages) . "</ul>\n"; } } $output .= '</ul>'; } } $output .= '</div>'; } unset($_SESSION['update_results']); unset($_SESSION['update_success']); return $output; }
/** * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { $count = 0; $incompatible_count = 0; $form['start'] = array('#tree' => TRUE, '#type' => 'details'); // Ensure system.module's updates appear first. $form['start']['system'] = array(); $updates = update_get_update_list(); $starting_updates = array(); $incompatible_updates_exist = FALSE; foreach ($updates as $module => $update) { if (!isset($update['start'])) { $form['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'])) { $starting_updates[$module] = $update['start']; $form['start'][$module] = array('#type' => 'hidden', '#value' => $update['start']); $form['start'][$module . '_updates'] = array('#theme' => 'item_list', '#items' => $update['pending'], '#title' => $module . ' module'); } 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($form['start'][$module_update_key]['#items'][$data['number']])) { $text = $data['missing_dependencies'] ? 'This update will been skipped due to the following missing dependencies: <em>' . implode(', ', $data['missing_dependencies']) . '</em>' : "This update will be skipped due to an error in the module's code."; $form['start'][$module_update_key]['#items'][$data['number']] .= '<div class="warning">' . $text . '</div>'; } // Move the module containing this update to the top of the list. $form['start'] = array($module_update_key => $form['start'][$module_update_key]) + $form['start']; } } // Warn the user if any updates were incompatible. if ($incompatible_updates_exist) { drupal_set_message('Some of the pending updates cannot be applied because their dependencies were not met.', 'warning'); } if (empty($count)) { drupal_set_message(t('No pending updates.')); unset($form); $form['links'] = array('#theme' => 'links', '#links' => update_helpful_links()); // No updates to run, so caches won't get flushed later. Clear them now. update_flush_all_caches(); } else { $form['help'] = array('#markup' => '<p>The version of Drupal you are updating from has been automatically detected.</p>', '#weight' => -5); if ($incompatible_count) { $form['start']['#title'] = format_plural($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 { $form['start']['#title'] = format_plural($count, '1 pending update', '@count pending updates'); } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Apply pending updates', '#button_type' => 'primary'); } return $form; }
/** * Displays results of the update script with any accompanying errors. */ function update_results_page() { // Report end result. if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) { $log_message = ' All errors have been <a href="' . base_path() . '?q=admin/reports/dblog">logged</a>.'; } else { $log_message = ' All errors have been logged.'; } if ($_SESSION['update_success']) { $output = '<p>Updates were attempted. If you see no failures below, you may proceed happily back to your <a href="' . base_path() . '">site</a>. Otherwise, you may need to update your database manually.' . $log_message . '</p>'; } else { $last = reset($_SESSION['updates_remaining']); list($module, $version) = array_pop($last); $output = '<p class="error">The update process was aborted prematurely while running <strong>update #' . $version . ' in ' . $module . '.module</strong>.' . $log_message; if (\Drupal::moduleHandler()->moduleExists('dblog')) { $output .= ' You may need to check the <code>watchdog</code> database table manually.'; } $output .= '</p>'; } if (Settings::get('update_free_access')) { $output .= "<p><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>"; } $links = array('#theme' => 'links', '#links' => update_helpful_links()); $output .= drupal_render($links); // Output a list of queries executed. if (!empty($_SESSION['update_results'])) { $all_messages = ''; foreach ($_SESSION['update_results'] as $module => $updates) { if ($module != '#abort') { $module_has_message = FALSE; $query_messages = ''; foreach ($updates as $number => $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[] = '<li class="success">' . $query['query'] . '</li>'; } else { $messages[] = '<li class="failure"><strong>Failed:</strong> ' . $query['query'] . '</li>'; } } if ($messages) { $module_has_message = TRUE; $query_messages .= '<h4>Update #' . $number . "</h4>\n"; $query_messages .= '<ul>' . implode("\n", $messages) . "</ul>\n"; } } // If there were any messages in the queries then prefix them with the // module name and add it to the global message list. if ($module_has_message) { $all_messages .= '<h3>' . $module . " module</h3>\n" . $query_messages; } } } if ($all_messages) { $output .= '<div class="update-results"><h2>The following updates returned messages</h2>'; $output .= $all_messages; $output .= '</div>'; } } unset($_SESSION['update_results']); unset($_SESSION['update_success']); $build = array('#title' => 'Drupal database update', '#markup' => $output); return $build; }