2001-11-15 22:53:06 +00:00
< ? php
2003-09-25 07:27:22 +00:00
// $Id$
2001-12-16 14:42:51 +00:00
/*
** USAGE :
**
** - Point your browser to " http://www.site.com/update.php " and follow
** the instructions .
**
2003-10-03 06:22:12 +00:00
** - 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 !
2001-12-16 14:42:51 +00:00
*/
2003-10-03 06:22:12 +00:00
// Disable access checking?
$access_check = 1 ;
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 " ;
}
}
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> " ;
2003-06-15 19:06:25 +00:00
$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> " ;
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
$edit = $_POST [ " edit " ];
2001-11-15 22:53:06 +00:00
2003-05-19 15:30:12 +00:00
switch ( $_POST [ " 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 :
$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.
2003-05-20 04:52:06 +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 peformed. " );
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-02-23 17:45:03 +00:00
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 (
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 )),
KEY timestamp ( timestamp )); </ pre ></ li > " ;
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
?>