summaryrefslogtreecommitdiff
path: root/update.php
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2005-08-17 01:44:14 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2005-08-17 01:44:14 +0000
commit05014a31353af85cb549a87c03604114eac9b13c (patch)
treebfe801404331098e6f951166b37f2047b2be69cd /update.php
parente5a8977ac12393b93e67389c4d67135f8aec97b2 (diff)
downloadbrdo-05014a31353af85cb549a87c03604114eac9b13c.tar.gz
brdo-05014a31353af85cb549a87c03604114eac9b13c.tar.bz2
- #29006: Reorganize code in update.php to be cleaner.
Diffstat (limited to 'update.php')
-rw-r--r--update.php118
1 files changed, 60 insertions, 58 deletions
diff --git a/update.php b/update.php
index 025cf4762..876f1b6b5 100644
--- a/update.php
+++ b/update.php
@@ -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 @@ if (isset($_GET["op"])) {
// 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);
}
?>