update.php 7.27 KB
Newer Older
1
<?php
2
// $Id$
3 4 5 6 7 8 9 10 11 12 13 14 15

/**
 * @file
 * Administrative page for handling updates from one Drupal version to another.
 *
 * Point your browser to "http://www.site.com/update.php" and follow the
 * instructions.
 *
 * If you are not logged in as administrator, you will need to modify the access
 * check statement below. Change the TRUE into a FALSE to disable the access
 * check. After finishing the upgrade, be sure to open this file and change the
 * FALSE back into a TRUE!
 */
16

17
// Disable access checking?
18
$access_check = TRUE;
19

20
if (!ini_get("safe_mode")) {
21 22 23
  set_time_limit(180);
}

24
include_once "database/updates.inc";
25 26

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

41 42 43 44 45
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">
46
        @import url("misc/drupal.css");
47 48
      </style>
EOF;
49
  $output .= "</head><body>";
50
  $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>";
51 52 53 54 55 56 57 58
  $output .= "<div id=\"update\"><h1>$title</h1>";
  return $output;
}

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

59
function update_page() {
60
  global $user, $sql_updates;
61 62

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

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

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

104
function update_info() {
105
  print update_page_header("Drupal database update");
106
  print "<ol>\n";
107
  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>";
108
  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";
109
  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";
110
  print "<li>Go through the various administration pages to change the existing and new settings to your liking.</li>\n";
111
  print "</ol>";
112 113
  print "Notes:";
  print "<ol>";
114
  print " <li>If you <strong>upgrade from Drupal 4.4.x</strong>, you will need to create the <code>users_roles</code> and <code>locales_meta</code> tables manually before upgrading. To create these tables, issue the following SQL commands:
115 116 117 118 119 120 121 122

  <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)
  );
123 124 125 126 127 128 129 130 131
  CREATE TABLE locales_meta (
    locale varchar(12) NOT NULL default '',
    name varchar(64) NOT NULL default '',
    enabled int(2) NOT NULL default '0',
    isdefault int(2) NOT NULL default '0',
    plurals int(1) NOT NULL default '0',
    formula varchar(128) NOT NULL default '',
    PRIMARY KEY  (locale)
  );
132 133 134 135 136 137 138 139 140 141
  </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)
  );
142 143 144 145 146 147 148 149 150
  CREATE TABLE locales_meta (
    locale varchar(12) NOT NULL default '',
    name varchar(64) NOT NULL default '',
    enabled int4 NOT NULL default '0',
    isdefault int4 NOT NULL default '0',
    plurals int4 NOT NULL default '0',
    formula varchar(128) NOT NULL default '',
    PRIMARY KEY  (locale)
  );
151 152 153 154
  </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:
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

  <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>";
173 174 175 176 177
  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 (
178 179 180 181 182 183 184
  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)),
185 186 187 188
  KEY timestamp (timestamp));
  </pre>
  </p>
  </li>";
189
  print "</ol>";
190
  print update_page_footer();
191
}
192

193
if (isset($_GET["op"])) {
194
  include_once "includes/bootstrap.inc";
195
  include_once "includes/common.inc";
196

197
  // Access check:
198
  if (($access_check == 0) || ($user->uid == 1)) {
199 200 201
    update_page();
  }
  else {
202
    print update_page_header("Access denied");
203
    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.";
204
    print update_page_footer();
205 206 207 208
  }
}
else {
  update_info();
209
}
210
?>