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
2005-07-29 20:31:05 +00:00
// Enforce 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 ;
2005-07-29 20:31:05 +00:00
$output = '' ;
2004-02-25 22:20:09 +00:00
$sql_updates = array_slice ( $sql_updates , ( $start -- ? $start : 0 ));
foreach ( $sql_updates as $date => $func ) {
2005-07-29 20:31:05 +00:00
$output .= '<h3 class="update">' . $date . '</h3><pre class="update">' ;
2004-02-25 22:20:09 +00:00
$ret = $func ();
foreach ( $ret as $return ) {
2005-07-29 20:31:05 +00:00
$output .= $return [ 1 ];
2004-02-25 22:20:09 +00:00
}
2001-11-15 22:53:06 +00:00
variable_set ( " update_start " , $date );
2005-07-29 20:31:05 +00:00
$output .= " </pre> \n " ;
2001-11-15 22:53:06 +00:00
}
2005-01-16 23:16:19 +00:00
db_query ( 'DELETE FROM {cache}' );
2003-05-20 04:52:06 +00:00
return $output ;
}
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.
2005-07-29 20:31:05 +00:00
drupal_set_title ( '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> " ;
2005-07-29 20:31:05 +00:00
$output = theme ( 'item_list' , $links );
// 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 ) {
2005-07-29 20:31:05 +00:00
$output .= 'No updates to perform.' ;
2001-11-15 22:53:06 +00:00
}
else {
2005-07-29 20:31:05 +00:00
$output .= update_data ( $edit [ 'start' ]);
2001-11-15 22:53:06 +00:00
}
2005-07-29 20:31:05 +00:00
$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 );
2001-11-15 22:53:06 +00:00
break ;
2005-07-29 20:31:05 +00:00
2001-11-15 22:53:06 +00:00
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 );
$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 " );
2005-07-29 20:31:05 +00:00
drupal_set_title ( 'Drupal database update' );
print theme ( 'maintenance_page' , form ( $form ));
2001-11-15 22:53:06 +00:00
break ;
}
}
2002-05-11 17:23:45 +00:00
function update_info () {
2005-07-29 20:31:05 +00:00
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> " ;
$output .= " <li>Before doing anything, backup your database. This process will change your database and its values, and some things might get lost.</li> \n " ;
$output .= " <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.</li> \n " ;
$output .= " <li>Go through the various administration pages to change the existing and new settings to your liking.</li> \n " ;
$output .= " </ol> " ;
$output .= " Notes: " ;
$output .= " <ol> " ;
$output .= " <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:
< p > MySQL specific example :</ p >
2004-05-10 20:34:25 +00:00
< 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 >
2005-07-29 20:31:05 +00:00
< p > PostgreSQL specific example :</ p >
2004-05-10 20:34:25 +00:00
< 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 >
</ li > " ;
2005-07-29 20:31:05 +00:00
$output .= " <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
2005-07-29 20:31:05 +00:00
< p > MySQL specific example :</ p >
2004-02-23 17:45:03 +00:00
< pre >
ALTER TABLE system ADD throttle tinyint ( 1 ) NOT NULL DEFAULT '0' ;
ALTER TABLE system ADD bootstrap int ( 2 );
</ pre >
2005-07-29 20:31:05 +00:00
< p > PostgreSQL specific example :</ p >
2004-02-23 17:45:03 +00:00
< 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 >
</ li > " ;
2005-07-29 20:31:05 +00:00
$output .= " <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:
2004-05-10 20:34:25 +00:00
2005-07-29 20:31:05 +00:00
< p > MySQL specific example :</ p >
2004-05-10 20:34:25 +00:00
< 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 >
</ li > " ;
2005-07-29 20:31:05 +00:00
$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 );
2001-11-15 22:53:06 +00:00
}
2002-05-11 17:23:45 +00:00
2005-07-29 20:31:05 +00:00
include_once " includes/bootstrap.inc " ;
drupal_maintenance_theme ();
2003-05-19 15:30:12 +00:00
if ( isset ( $_GET [ " op " ])) {
2005-07-23 05:57:27 +00:00
drupal_bootstrap ( DRUPAL_BOOTSTRAP_FULL );
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 {
2005-07-29 20:31:05 +00:00
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 > ' );
2002-05-15 22:36:30 +00:00
}
}
else {
update_info ();
2001-11-15 22:53:06 +00:00
}
2005-07-29 20:31:05 +00:00
2003-01-14 20:33:42 +00:00
?>