update.php 5.89 KB
Newer Older
1
<?php
Dries's avatar
Dries committed
2
// $Id$
Dries's avatar
Dries committed
3 4 5 6 7 8
/*
** USAGE:
**
** - Point your browser to "http://www.site.com/update.php" and follow
**   the instructions.
**
Dries's avatar
Dries committed
9 10 11 12
** - If you are not logged in as administrator, you will need to modify the
**   statement below. Change the 1 into a 0 to disable the access check.
**   After finishing the upgrade, open this file and change the 0 back into
**   a 1!
Dries's avatar
Dries committed
13 14
*/

Dries's avatar
Dries committed
15 16 17
// Disable access checking?
$access_check = 1;

18
if (!ini_get("safe_mode")) {
19 20 21
  set_time_limit(180);
}

Dries's avatar
Dries committed
22
include_once "database/updates.inc";
23 24

function update_data($start) {
Dries's avatar
Dries committed
25 26 27
  global $sql_updates;
  $sql_updates = array_slice($sql_updates, ($start-- ? $start : 0));
  foreach ($sql_updates as $date => $func) {
28
    print "<strong>$date</strong><br />\n<pre>\n";
Dries's avatar
Dries committed
29 30 31 32 33
    $ret = $func();
    foreach ($ret as $return) {
      print $return[1];
      print $return[2];
    }
34 35 36 37 38
    variable_set("update_start", $date);
    print "</pre>\n";
  }
}

Dries's avatar
Dries committed
39 40 41 42 43
function update_page_header($title) {
  $output = "<html><head><title>$title</title>";
  $output .= <<<EOF
      <link rel="stylesheet" type="text/css" media="print" href="misc/print.css" />
      <style type="text/css" title="layout" media="Screen">
Dries's avatar
Dries committed
44
        @import url("misc/drupal.css");
Dries's avatar
Dries committed
45 46
      </style>
EOF;
Dries's avatar
Dries committed
47
  $output .= "</head><body>";
Dries's avatar
Dries committed
48
  $output .= "<div id=\"logo\"><a href=\"http://drupal.org/\"><img src=\"misc/druplicon-small.gif\" alt=\"Druplicon - Drupal logo\" title=\"Druplicon - Drupal logo\" /></a></div>";
Dries's avatar
Dries committed
49 50 51 52 53 54 55 56
  $output .= "<div id=\"update\"><h1>$title</h1>";
  return $output;
}

function update_page_footer() {
  return "</div></body></html>";
}

57
function update_page() {
Dries's avatar
Dries committed
58
  global $user, $sql_updates;
Dries's avatar
Dries committed
59 60

  $edit = $_POST["edit"];
61

62
  switch ($_POST["op"]) {
63 64
    case "Update":
      // make sure we have updates to run.
Dries's avatar
Dries committed
65
      print update_page_header("Drupal database update");
Dries's avatar
Dries committed
66 67 68
      $links[] = "<a href=\"index.php\">main page</a>";
      $links[] = "<a href=\"index.php?q=admin\">administration pages</a>";
      print theme("item_list", $links);
Dries's avatar
Dries committed
69
        // NOTE: we can't use l() here because the URL would point to 'update.php?q=admin'.
70 71 72 73 74 75
      if ($edit["start"] == -1) {
        print "No updates to perform.";
      }
      else {
        update_data($edit["start"]);
      }
Dries's avatar
Dries committed
76
      print "<br />Updates were attempted. If you see no failures above, you may proceed happily to the <a href=\"index.php?q=admin\">administration pages</a>.";
Dries's avatar
Dries committed
77
      print " Otherwise, you may need to update your database manually.";
Dries's avatar
Dries committed
78
      print update_page_footer();
79 80 81 82 83
      break;
    default:
      $start = variable_get("update_start", 0);
      $dates[] = "All";
      $i = 1;
Dries's avatar
Dries committed
84
      foreach ($sql_updates as $date => $sql) {
85 86 87 88 89
        $dates[$i++] = $date;
        if ($date == $start) {
          $selected = $i;
        }
      }
Dries's avatar
Dries committed
90
      $dates[$i] = "No updates available";
91 92

      // make update form and output it.
Dries's avatar
Dries committed
93
      $form .= form_select("Perform updates from", "start", (isset($selected) ? $selected : -1), $dates, "This defaults to the first available update since the last update you peformed.");
94
      $form .= form_submit("Update");
Dries's avatar
Dries committed
95
      print update_page_header("Drupal database update");
96
      print form($form);
Dries's avatar
Dries committed
97
      print update_page_footer();
98 99 100 101
      break;
  }
}

102
function update_info() {
Dries's avatar
Dries committed
103
  print update_page_header("Drupal database update");
104
  print "<ol>\n";
105
  print "<li>Use this script to <strong>upgrade an existing Drupal installation</strong>.  You don't need this script when installing Drupal from scratch.</li>";
Dries's avatar
Dries committed
106
  print "<li>Before doing anything, backup your database. This process will change your database and its values, and some things might get lost.</li>\n";
Dries's avatar
Dries committed
107
  print "<li>Update your Drupal sources, check the notes below and <a href=\"update.php?op=update\">run the database upgrade script</a>.  Don't upgrade your database twice as it may cause problems.</p></li>\n";
Dries's avatar
Dries committed
108
  print "<li>Go through the various administration pages to change the existing and new settings to your liking.</li>\n";
109
  print "</ol>";
Dries's avatar
Dries committed
110 111
  print "Notes:";
  print "<ol>";
Dries's avatar
Dries committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  print " <li>If you <strong>upgrade from Drupal 4.3.x</strong>, you have will need to add the <code>bootstrap</code> and <code>throttle</code> fields to the <code>system</code> table manually before upgrading. To add the required fields, issue the following SQL commands:

  <p>MySQL specific example:
  <pre>
  ALTER TABLE system ADD throttle tinyint(1) NOT NULL DEFAULT '0';
  ALTER TABLE system ADD bootstrap int(2);
  </pre>
  </p>

  <p>PostgreSQL specific example:
  <pre>
  ALTER TABLE system ADD throttle smallint;
  ALTER TABLE system ALTER COLUMN throttle SET DEFAULT '0';
  UPDATE system SET throttle = 0;
  ALTER TABLE system ALTER COLUMN throttle SET NOT NULL;
  ALTER TABLE system ADD bootstrap integer;
  </pre>
  </p>
  </li>";
  print " <li>If you <strong>upgrade from Drupal 4.2.0</strong>, you have to create the <code>sessions</code> table manually before upgrading.  After you created the table, you'll want to log in and immediately continue the upgrade.  To create the <code>sessions</code> table, issue the following SQL command (MySQL specific example):<pre>CREATE TABLE sessions (
Dries's avatar
Dries committed
132 133 134 135 136 137 138 139 140
  uid int(10) unsigned NOT NULL,
  sid varchar(32) NOT NULL default '',
  hostname varchar(128) NOT NULL default '',
  timestamp int(11) NOT NULL default '0',
  session text,
  KEY uid (uid),
  KEY sid (sid(4)),
  KEY timestamp (timestamp));</pre></li>";
  print "</ol>";
Dries's avatar
Dries committed
141
  print update_page_footer();
142
}
143

144
if (isset($_GET["op"])) {
Dries's avatar
Dries committed
145
  include_once "includes/bootstrap.inc";
146
  include_once "includes/common.inc";
Dries's avatar
Dries committed
147

Dries's avatar
Dries committed
148
  // Access check:
Dries's avatar
Dries committed
149
  if (($access_check == 0) || ($user->uid == 1)) {
150 151 152
    update_page();
  }
  else {
Dries's avatar
Dries committed
153
    print update_page_header("Access denied");
Dries's avatar
Dries committed
154
    print "Access denied.  You are not authorized to access to this page.  Please log in as the user with user ID #1. If you cannot log-in, you will have to edit <code>update.php</code> to by-pass this access check; in that case, open <code>update.php</code> in a text editor and follow the instructions at the top.";
Dries's avatar
Dries committed
155
    print update_page_footer();
156 157 158 159
  }
}
else {
  update_info();
160
}
Dries's avatar
Dries committed
161
?>