Skip to content
Snippets Groups Projects
Commit 05014a31 authored by Steven Wittens's avatar Steven Wittens
Browse files

- #29006: Reorganize code in update.php to be cleaner.

parent e5a8977a
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -40,58 +40,43 @@ function update_data($start) {
return $output;
}
function update_page() {
global $user, $sql_updates;
function update_selection_page() {
global $sql_updates;
if (isset($_POST['edit'])) {
$edit = $_POST['edit'];
}
if (isset($_POST['op'])) {
$op = $_POST['op'];
$start = variable_get("update_start", 0);
$i = 1;
foreach ($sql_updates as $date => $sql) {
$dates[$i++] = $date;
if ($date == $start) {
$selected = $i;
}
}
$dates[$i] = "No updates available";
// make update form and output it.
$form = form_select("Perform updates from", "start", (isset($selected) ? $selected : -1), $dates, "This defaults to the first available update since the last update you performed.");
$form .= form_submit("Update");
switch ($op) {
case "Update":
// make sure we have updates to run.
drupal_set_title('Drupal database update');
$links[] = "<a href=\"index.php\">main page</a>";
$links[] = "<a href=\"index.php?q=admin\">administration pages</a>";
$output = theme('item_list', $links);
// NOTE: we can't use l() here because the URL would point to 'update.php?q=admin'.
if ($edit["start"] == -1) {
$output .= 'No updates to perform.';
}
else {
$output .= update_data($edit['start']);
}
$output .= '<p>Updates were attempted. If you see no failures above, you may proceed happily to the <a href="index.php?q=admin">administration pages</a>. Otherwise, you may need to update your database manually.</p>';
if ($GLOBALS['access_check'] == FALSE) {
$output .= "<p><strong>Reminder: don't forget to set the <code>\$access_check</code> value at the top of <code>update.php</code> back to <code>TRUE</code>.</strong>";
}
print theme('maintenance_page', $output);
break;
default:
$start = variable_get("update_start", 0);
$i = 1;
foreach ($sql_updates as $date => $sql) {
$dates[$i++] = $date;
if ($date == $start) {
$selected = $i;
}
}
$dates[$i] = "No updates available";
// make update form and output it.
$form = form_select("Perform updates from", "start", (isset($selected) ? $selected : -1), $dates, "This defaults to the first available update since the last update you performed.");
$form .= form_submit("Update");
drupal_set_title('Drupal database update');
print theme('maintenance_page', form($form));
break;
drupal_set_title('Drupal database update');
return form($form);
}
function update_do_updates() {
$edit = $_POST['edit'];
drupal_set_title('Drupal database update');
// NOTE: we can't use l() here because the URL would point to 'update.php?q=admin'.
$links[] = "<a href=\"index.php\">main page</a>";
$links[] = "<a href=\"index.php?q=admin\">administration pages</a>";
$output = theme('item_list', $links);
$output .= update_data($edit['start']);
$output .= '<p>Updates were attempted. If you see no failures above, you may proceed happily to the <a href="index.php?q=admin">administration pages</a>. Otherwise, you may need to update your database manually.</p>';
if ($GLOBALS['access_check'] == FALSE) {
$output .= "<p><strong>Reminder: don't forget to set the <code>\$access_check</code> value at the top of <code>update.php</code> back to <code>TRUE</code>.</strong>";
}
return $output;
}
function update_info() {
function update_info_page() {
drupal_set_title('Drupal database update');
$output = "<ol>\n";
$output .= "<li>Use this script to <strong>upgrade an existing Drupal installation</strong>. You don't need this script when installing Drupal from scratch.</li>";
......@@ -171,9 +156,20 @@ function update_info() {
KEY timestamp (timestamp));
</pre>
</li>";
$output .= '<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>';
$output .= "</ol>";
print theme('maintenance_page', $output);
$output .= '<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>';
return $output;
}
function update_access_denied_page() {
drupal_set_title('Access denied');
return '<p>Access denied. You are not authorized to access this page. Please log in as the admin user (the first user you created). If you cannot log in, you will have to edit <code>update.php</code> to bypass this access check. To do this:</p>
<ol>
<li>With a text editor find the update.php file on your system. It should be in the main Drupal directory that you installed all the files into.</li>
<li>There is a line near top of update.php that says <code>$access_check = TRUE;</code>. Change it to <code>$access_check = FALSE;</code>.</li>
<li>As soon as the script is done, you must change the update.php script back to its original form to <code>$access_check = TRUE;</code>.</li>
<li>To avoid having this problem in future, remember to log in to your website as the admin user (the user you first created) before you backup your database at the beginning of the update process.</li>
</ol>';
}
include_once "includes/bootstrap.inc";
......@@ -183,21 +179,27 @@ function update_info() {
// Access check:
if (($access_check == 0) || ($user->uid == 1)) {
update_page();
$op = isset($_POST['op']) ? $_POST['op'] : '';
switch ($op) {
case 'Update':
$output = update_do_updates();
break;
default:
$output = update_selection_page();
break;
}
}
else {
drupal_set_title('Access denied');
print theme('maintenance_page', '<p>Access denied. You are not authorized to access this page. Please log in as the admin user (the first user you created). If you cannot log in, you will have to edit <code>update.php</code> to bypass this access check. To do this:</p>
<ol>
<li>With a text editor find the update.php file on your system. It should be in the main Drupal directory that you installed all the files into.</li>
<li>There is a line near top of update.php that says <code>$access_check = TRUE;</code>. Change it to <code>$access_check = FALSE;</code>.</li>
<li>As soon as the script is done, you must change the update.php script back to its original form to <code>$access_check = TRUE;</code>.</li>
<li>To avoid having this problem in future, remember to log in to your website as the admin user (the user you first created) before you backup your database at the beginning of the update process.</li>
</ol>');
$output = update_access_denied_page();
}
}
else {
update_info();
$output = update_info_page();
}
if ($output) {
print theme('maintenance_page', $output);
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment