2001-11-15 22:53:06 +00:00
< ? php
2003-09-25 07:27:22 +00:00
// $Id$
2004-08-21 06:42:38 +00:00
/**
* @ 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 !
*/
2001-12-16 14:42:51 +00:00
2003-10-03 06:22:12 +00:00
// Disable access checking?
2004-08-21 06:42:38 +00:00
$access_check = TRUE ;
2003-10-03 06:22:12 +00:00
2003-12-29 11:25:02 +00:00
if ( ! ini_get ( " safe_mode " )) {
2001-11-15 22:53:06 +00:00
set_time_limit ( 180 );
}
2004-02-25 22:20:09 +00:00
include_once " database/updates.inc " ;
2001-11-15 22:53:06 +00:00
function update_data ( $start ) {
2004-02-25 22:20:09 +00:00
global $sql_updates ;
$sql_updates = array_slice ( $sql_updates , ( $start -- ? $start : 0 ));
foreach ( $sql_updates as $date => $func ) {
2003-12-29 17:14:27 +00:00
print " <strong> $date </strong><br /> \n <pre> \n " ;
2004-02-25 22:20:09 +00:00
$ret = $func ();
foreach ( $ret as $return ) {
print $return [ 1 ];
print $return [ 2 ];
}
2001-11-15 22:53:06 +00:00
variable_set ( " update_start " , $date );
print " </pre> \n " ;
}
2005-01-16 23:16:19 +00:00
db_query ( 'DELETE FROM {cache}' );
2001-11-15 22:53:06 +00:00
}
2003-05-20 04:52:06 +00:00
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 " >
2003-10-01 21:55:19 +00:00
@ import url ( " misc/drupal.css " );
2003-05-20 04:52:06 +00:00
</ style >
EOF ;
2003-10-20 19:21:17 +00:00
$output .= " </head><body> " ;
2004-06-20 20:04:28 +00:00
$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> " ;
2003-05-20 04:52:06 +00:00
$output .= " <div id= \" update \" ><h1> $title </h1> " ;
return $output ;
}
function update_page_footer () {
return " </div></body></html> " ;
}
2001-11-15 22:53:06 +00:00
function update_page () {
2004-02-25 22:20:09 +00:00
global $user , $sql_updates ;
2003-05-13 18:36:38 +00:00
2004-12-24 06:52:02 +00:00
if ( isset ( $_POST [ 'edit' ])) {
$edit = $_POST [ 'edit' ];
}
if ( isset ( $_POST [ 'op' ])) {
$op = $_POST [ 'op' ];
}
2001-11-15 22:53:06 +00:00
2004-12-24 06:52:02 +00:00
switch ( $op ) {
2001-11-15 22:53:06 +00:00
case " Update " :
// make sure we have updates to run.
2003-05-20 04:52:06 +00:00
print update_page_header ( " Drupal database update " );
2003-11-18 19:44:36 +00:00
$links [] = " <a href= \" index.php \" >main page</a> " ;
$links [] = " <a href= \" index.php?q=admin \" >administration pages</a> " ;
print theme ( " item_list " , $links );
2003-02-23 21:11:03 +00:00
// NOTE: we can't use l() here because the URL would point to 'update.php?q=admin'.
2001-11-15 22:53:06 +00:00
if ( $edit [ " start " ] == - 1 ) {
print " No updates to perform. " ;
}
else {
update_data ( $edit [ " start " ]);
}
2003-02-23 21:11:03 +00:00
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>. " ;
2003-01-07 05:56:47 +00:00
print " Otherwise, you may need to update your database manually. " ;
2003-05-20 04:52:06 +00:00
print update_page_footer ();
2001-11-15 22:53:06 +00:00
break ;
default :
2005-01-13 19:24:27 +00:00
// NOTE: We need the following five lines in order to fix a bug with
// database.mysql (issue #15337). We should be able to remove
// this work around in the future.
2005-02-07 14:25:17 +00:00
$result = db_query ( " SELECT * FROM { variable} WHERE name = 'update_start' AND value LIKE '%; \" ' " );
2005-01-13 19:24:27 +00:00
if ( $variable = db_fetch_object ( $result )) {
$variable -> value = unserialize ( substr ( $variable -> value , 0 , - 2 ) . '";' );
variable_set ( 'update_start' , $variable -> value );
}
2001-11-15 22:53:06 +00:00
$start = variable_get ( " update_start " , 0 );
$dates [] = " All " ;
$i = 1 ;
2004-02-25 22:20:09 +00:00
foreach ( $sql_updates as $date => $sql ) {
2001-11-15 22:53:06 +00:00
$dates [ $i ++ ] = $date ;
if ( $date == $start ) {
$selected = $i ;
}
}
2002-11-24 13:04:28 +00:00
$dates [ $i ] = " No updates available " ;
2001-11-15 22:53:06 +00:00
// make update form and output it.
2004-09-08 18:53:57 +00:00
$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. " );
2001-11-15 22:53:06 +00:00
$form .= form_submit ( " Update " );
2003-05-20 04:52:06 +00:00
print update_page_header ( " Drupal database update " );
2001-11-15 22:53:06 +00:00
print form ( $form );
2003-05-20 04:52:06 +00:00
print update_page_footer ();
2001-11-15 22:53:06 +00:00
break ;
}
}
2002-05-11 17:23:45 +00:00
function update_info () {
2003-05-20 04:52:06 +00:00
print update_page_header ( " Drupal database update " );
2002-05-15 22:36:30 +00:00
print " <ol> \n " ;
2003-12-29 17:14:27 +00:00
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> " ;
2003-01-07 05:56:47 +00:00
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 " ;
2003-10-21 07:59:04 +00:00
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 " ;
2002-12-07 11:24:16 +00:00
print " <li>Go through the various administration pages to change the existing and new settings to your liking.</li> \n " ;
2002-05-15 22:36:30 +00:00
print " </ol> " ;
2003-10-01 21:55:19 +00:00
print " Notes: " ;
print " <ol> " ;
2004-08-11 11:26:20 +00:00
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:
2004-05-10 20:34:25 +00:00
< 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 )
);
2004-08-11 11:26:20 +00:00
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 )
);
2004-05-10 20:34:25 +00:00
</ 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 )
);
2004-08-11 11:26:20 +00:00
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 )
);
2004-05-10 20:34:25 +00:00
</ 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:
2004-02-23 17:45:03 +00:00
< 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 > " ;
2004-05-10 20:34:25 +00:00
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 (
2003-10-01 21:55:19 +00:00
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 )),
2004-05-10 20:34:25 +00:00
KEY timestamp ( timestamp ));
</ pre >
</ p >
</ li > " ;
2003-10-01 21:55:19 +00:00
print " </ol> " ;
2003-05-20 04:52:06 +00:00
print update_page_footer ();
2001-11-15 22:53:06 +00:00
}
2002-05-11 17:23:45 +00:00
2003-05-19 15:30:12 +00:00
if ( isset ( $_GET [ " op " ])) {
2003-11-18 19:44:36 +00:00
include_once " includes/bootstrap.inc " ;
2002-05-15 22:36:30 +00:00
include_once " includes/common.inc " ;
2003-01-07 05:56:47 +00:00
2002-12-07 11:24:16 +00:00
// Access check:
2003-10-03 06:22:12 +00:00
if (( $access_check == 0 ) || ( $user -> uid == 1 )) {
2002-05-15 22:36:30 +00:00
update_page ();
}
else {
2003-05-20 04:52:06 +00:00
print update_page_header ( " Access denied " );
2003-10-03 06:22:12 +00:00
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. " ;
2003-05-20 04:52:06 +00:00
print update_page_footer ();
2002-05-15 22:36:30 +00:00
}
}
else {
update_info ();
2001-11-15 22:53:06 +00:00
}
2003-01-14 20:33:42 +00:00
?>