[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/admin/ -> upgrade_unattended.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   4  # MantisBT is free software: you can redistribute it and/or modify
   5  # it under the terms of the GNU General Public License as published by
   6  # the Free Software Foundation, either version 2 of the License, or
   7  # (at your option) any later version.
   8  #
   9  # MantisBT is distributed in the hope that it will be useful,
  10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  # GNU General Public License for more details.
  13  #
  14  # You should have received a copy of the GNU General Public License
  15  # along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * @package MantisBT
  19   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  20   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  21   * @link http://www.mantisbt.org
  22   */
  23  
  24  @set_time_limit( 0 );
  25  
  26  # Load the MantisDB core in maintenance mode. This mode will assume that
  27  # config_inc.php hasn't been specified. Thus the database will not be opened
  28  # and plugins will not be loaded.
  29  define( 'MANTIS_MAINTENANCE_MODE', true );
  30  
  31  /**
  32   * MantisBT Core API's
  33   */
  34  require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );
  35  $g_error_send_page_header = false; # suppress page headers in the error handler
  36  
  37  $g_failed = false;
  38  
  39  /* This script is probably meant to be executed from PHP CLI and hence should
  40   * not be interpreted as text/html. However saying that, we do call gpc_
  41   * functions that only make sense in PHP CGI mode. Given this mismatch we'll
  42   * just assume for now that this script is meant to be used from PHP CGI and
  43   * the output is meant to be text/plain. We also need to prevent Internet
  44   * Explorer from ignoring our MIME type and using it's own MIME sniffing.
  45   */
  46  header( 'Content-Type: text/plain' );
  47  header( 'X-Content-Type-Options: nosniff' );
  48  
  49  /**
  50   * Print the result of an upgrade step.
  51   *
  52   * @param integer $result       GOOD or BAD.
  53   * @param bool    $p_hard_fail  If result is BAD, sets the global failure flag.
  54   * @param string  $p_message    The message describing the upgrade step.
  55   * @access private
  56   */
  57  function print_test_result( $p_result, $p_hard_fail = true, $p_message = '' ) {
  58      global $g_failed;
  59      if( BAD == $p_result ) {
  60          if( $p_hard_fail ) {
  61              $g_failed = true;
  62              echo " - ERROR: ";
  63          } else {
  64              echo " - WARNING: ";
  65          }
  66          if( '' != $p_message ) {
  67              echo $p_message;
  68          }
  69      }
  70  
  71      if( GOOD == $p_result ) {
  72          echo " - GOOD";
  73      }
  74      echo "\n";
  75  }
  76  
  77  $result = @db_connect( config_get_global( 'dsn', false ), config_get_global( 'hostname' ),
  78      config_get_global( 'db_username' ), config_get_global( 'db_password' ),
  79      config_get_global( 'database_name' ) );
  80  
  81  if( false == $result ) {
  82      echo "Opening connection to database " .
  83          config_get_global( 'database_name' ) .
  84          " on host " . config_get_global( 'hostname' ) .
  85          " with username " . config_get_global( 'db_username' ) .
  86          " failed: " . db_error_msg() . "\n";
  87      exit( 1 );
  88  }
  89  
  90  # check to see if the new installer was used
  91  if ( -1 == config_get( 'database_version', -1 ) ) {
  92      echo "Upgrade from the current installed MantisBT version is no longer supported.  If you are using MantisBT version older than 1.0.0, then upgrade to v1.0.0 first.";
  93      exit( 1 );
  94  }
  95  
  96  # read control variables with defaults
  97  $f_hostname = gpc_get( 'hostname', config_get( 'hostname', 'localhost' ) );
  98  $f_db_type = gpc_get( 'db_type', config_get( 'db_type', '' ) );
  99  $f_database_name = gpc_get( 'database_name', config_get( 'database_name', 'bugtrack' ) );
 100  $f_db_username = gpc_get( 'db_username', config_get( 'db_username', '' ) );
 101  $f_db_password = gpc_get( 'db_password', config_get( 'db_password', '' ) );
 102  $f_db_exists = gpc_get_bool( 'db_exists', false );
 103  
 104  # install the tables
 105  if ( !preg_match( '/^[a-zA-Z0-9_]+$/', $f_db_type ) ||
 106       !file_exists( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'adodb' . DIRECTORY_SEPARATOR . 'drivers' . DIRECTORY_SEPARATOR . 'adodb-' . $f_db_type . '.inc.php' ) ) {
 107      echo 'Invalid db type ' . htmlspecialchars( $f_db_type ) . '.';
 108      exit;
 109  }
 110  
 111  $GLOBALS['g_db_type'] = $f_db_type; # database_api references this
 112  require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'schema.php' );
 113  $g_db = ADONewConnection( $f_db_type );
 114  
 115  echo "\nPost 1.0 schema changes\n";
 116  echo "Connecting to database... ";
 117  $t_result = @$g_db->Connect( $f_hostname, $f_db_username, $f_db_password, $f_database_name );
 118  
 119  if( false == $t_result ) {
 120      echo "failed\n";
 121      exit( 1 );
 122  }
 123  
 124  echo "OK\n";
 125  
 126  $g_db_connected = true; # fake out database access routines used by config_get
 127  $t_last_update = config_get( 'database_version', -1, ALL_USERS, ALL_PROJECTS );
 128  $lastid = count( $upgrade ) - 1;
 129  $i = $t_last_update + 1;
 130  
 131  while(( $i <= $lastid ) && !$g_failed ) {
 132      echo 'Create Schema ( ' . $upgrade[$i][0] . ' on ' . $upgrade[$i][1][0] . ' )';
 133      $dict = NewDataDictionary( $g_db );
 134  
 135      if( $upgrade[$i][0] == 'InsertData' ) {
 136          $sqlarray = call_user_func_array( $upgrade[$i][0], $upgrade[$i][1] );
 137      } else {
 138          $sqlarray = call_user_func_array( Array( $dict, $upgrade[$i][0] ), $upgrade[$i][1] );
 139      }
 140  
 141      $ret = $dict->ExecuteSQLArray( $sqlarray );
 142      if( $ret == 2 ) {
 143          print_test_result( GOOD );
 144          config_set( 'database_version', $i );
 145      } else {
 146          print_test_result( BAD, true, $sqlarray[0] . '<br />' . $g_db->ErrorMsg() );
 147      }
 148  
 149      $i++;
 150  }
 151  
 152  if( false == $g_failed ) {
 153      exit( 0 );
 154  }
 155  
 156  exit( 1 );
 157  
 158  # vim: noexpandtab tabstop=4 softtabstop=0:


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7