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 );
}
2005-08-29 18:48:25 +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 ;
}
2005-08-17 01:44:14 +00:00
function update_selection_page () {
global $sql_updates ;
2003-05-13 18:36:38 +00:00
2005-08-17 01:44:14 +00:00
$start = variable_get ( " update_start " , 0 );
$i = 1 ;
foreach ( $sql_updates as $date => $sql ) {
$dates [ $i ++ ] = $date ;
if ( $date == $start ) {
$selected = $i ;
}
2004-12-24 06:52:02 +00:00
}
2005-08-17 01:44:14 +00:00
$dates [ $i ] = " No updates available " ;
// make update form and output it.
2005-10-07 06:11:12 +00:00
$form [ 'start' ] = array (
type => 'select' ,
title => t ( 'Perform updates from' ),
default_value => ( isset ( $selected ) ? $selected : - 1 ),
options => $dates ,
description => t ( 'This defaults to the first available update since the last update you performed.' )
);
$form [ 'submit' ] = array (
type => 'submit' ,
value => t ( 'Update' )
);
2001-11-15 22:53:06 +00:00
2005-08-17 01:44:14 +00:00
drupal_set_title ( 'Drupal database update' );
2005-10-07 06:11:12 +00:00
return drupal_get_form ( 'update_script_selection_form' , $form );
2005-08-17 01:44:14 +00:00
}
function update_do_updates () {
$edit = $_POST [ 'edit' ];
drupal_set_title ( 'Drupal database update' );
// NOTE: we can't use l() here because the URL would point to 'update.php?q=admin'.
$links [] = " <a href= \" index.php \" >main page</a> " ;
$links [] = " <a href= \" index.php?q=admin \" >administration pages</a> " ;
$output = theme ( 'item_list' , $links );
$output .= update_data ( $edit [ 'start' ]);
$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> " ;
2001-11-15 22:53:06 +00:00
}
2005-08-17 01:44:14 +00:00
return $output ;
2001-11-15 22:53:06 +00:00
}
2005-08-17 01:44:14 +00:00
function update_info_page () {
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> " ;
2005-08-17 01:44:14 +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>' ;
return $output ;
}
function update_access_denied_page () {
drupal_set_title ( 'Access denied' );
return ' < 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 > ' ;
2001-11-15 22:53:06 +00:00
}
2002-05-11 17:23:45 +00:00
2005-08-29 18:48:25 +00:00
include_once './includes/bootstrap.inc' ;
2005-07-29 20:31:05 +00:00
drupal_maintenance_theme ();
2005-08-31 17:56:07 +00:00
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 )) {
2005-08-17 01:44:14 +00:00
$op = isset ( $_POST [ 'op' ]) ? $_POST [ 'op' ] : '' ;
switch ( $op ) {
case 'Update' :
$output = update_do_updates ();
break ;
default :
$output = update_selection_page ();
break ;
}
2002-05-15 22:36:30 +00:00
}
else {
2005-08-17 01:44:14 +00:00
$output = update_access_denied_page ();
2002-05-15 22:36:30 +00:00
}
}
else {
2005-08-31 17:56:07 +00:00
drupal_bootstrap ( DRUPAL_BOOTSTRAP_DATABASE );
2005-08-17 01:44:14 +00:00
$output = update_info_page ();
}
2005-08-29 18:48:25 +00:00
if ( isset ( $output )) {
2005-08-17 01:44:14 +00:00
print theme ( 'maintenance_page' , $output );
2001-11-15 22:53:06 +00:00
}
2005-07-29 20:31:05 +00:00