update.php 6.54 KB
Newer Older
1
<?php
Dries's avatar
Dries committed
2
// $Id$
3 4 5 6 7 8
/*
** USAGE:
**
** - Point your browser to "http://www.site.com/update.php" and follow
**   the instructions.
**
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!
13 14
*/

15 16 17
// Disable access checking?
$access_check = 1;

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

22
include_once "database/updates.inc";
23 24

function update_data($start) {
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";
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";
  }
}

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">
44
        @import url("misc/drupal.css");
45 46
      </style>
EOF;
47
  $output .= "</head><body>";
48
  $output .= "<div id=\"logo\"><a href=\"http://drupal.org/\"><img src=\"misc/druplicon-small.png\" alt=\"Druplicon - Drupal logo\" title=\"Druplicon - Drupal logo\" /></a></div>";
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() {
58
  global $user, $sql_updates;
59 60

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

62
  switch ($_POST["op"]) {
63 64
    case "Update":
      // make sure we have updates to run.
65
      print update_page_header("Drupal database update");
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);
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"]);
      }
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>.";
77
      print " Otherwise, you may need to update your database manually.";
78
      print update_page_footer();
79 80 81 82 83
      break;
    default:
      $start = variable_get("update_start", 0);
      $dates[] = "All";
      $i = 1;
84
      foreach ($sql_updates as $date => $sql) {
85 86 87 88 89
        $dates[$i++] = $date;
        if ($date == $start) {
          $selected = $i;
        }
      }
90
      $dates[$i] = "No updates available";
91 92

      // make update form and output it.
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 performed.");
94
      $form .= form_submit("Update");
95
      print update_page_header("Drupal database update");
96
      print form($form);
97
      print update_page_footer();
98 99 100 101
      break;
  }
}

102
function update_info() {
103
  print update_page_header("Drupal database update");
Kjartan's avatar
Kjartan committed
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>";
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";
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";
108
  print "<li>Go through the various administration pages to change the existing and new settings to your liking.</li>\n";
Kjartan's avatar
Kjartan committed
109
  print "</ol>";
110 111
  print "Notes:";
  print "<ol>";
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
  print " <li>If you <strong>upgrade from Drupal 4.4.x</strong>, you will need to create the <code>users_roles</code> table manually before upgrading. To create the <code>users_roles</code> table, issue the following SQL commands:

  <p>MySQL specific example:
  <pre>
  CREATE TABLE users_roles (
    uid int(10) unsigned NOT NULL default '0',
    rid int(10) unsigned NOT NULL default '0',
    PRIMARY KEY (uid, rid)
  );
  </pre>
  </p>

  <p>PostgreSQL specific example:
  <pre>
  CREATE TABLE users_roles (
    uid integer NOT NULL default '0',
    rid integer NOT NULL default '0',
    PRIMARY KEY (uid, rid)
  );
  </pre>
  </p>
  </li>";
  print " <li>If you <strong>upgrade from Drupal 4.3.x</strong>, you 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:
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

  <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>";
153 154 155 156 157
  print " <li>If you <strong>upgrade from Drupal 4.2.0</strong>, you will need to create the <code>sessions</code> table manually before upgrading.  After creating the table, you will want to log in and immediately continue the upgrade.  To create the <code>sessions</code> table, issue the following SQL command:

  <p>MySQL specific example:
  <pre>
  CREATE TABLE sessions (
158 159 160 161 162 163 164
  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)),
165 166 167 168
  KEY timestamp (timestamp));
  </pre>
  </p>
  </li>";
169
  print "</ol>";
170
  print update_page_footer();
171
}
172

173
if (isset($_GET["op"])) {
174
  include_once "includes/bootstrap.inc";
Kjartan's avatar
Kjartan committed
175
  include_once "includes/common.inc";
176

177
  // Access check:
178
  if (($access_check == 0) || ($user->uid == 1)) {
Kjartan's avatar
Kjartan committed
179 180 181
    update_page();
  }
  else {
182
    print update_page_header("Access denied");
183
    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.";
184
    print update_page_footer();
Kjartan's avatar
Kjartan committed
185 186 187 188
  }
}
else {
  update_info();
189
}
190
?>