[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/admin/ -> upgrade_unattended.php (source)

   1  <?php
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis is free software: you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation, either version 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20      # --------------------------------------------------------
  21      # $Id: upgrade_unattended.php,v 1.1.2.1 2007-10-13 22:34:59 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      set_time_limit ( 0 ) ;
  25  
  26      $g_skip_open_db = true;  # don't open the database in database_api.php
  27      require_once ( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );
  28      $g_error_send_page_header = false; # suppress page headers in the error handler
  29  
  30      define( 'BAD', 0 );
  31      define( 'GOOD', 1 );
  32  
  33      $g_failed = false;
  34  
  35      # -------
  36      # print test result
  37  	function print_test_result( $p_result, $p_hard_fail=true, $p_message='' ) {
  38          global $g_failed;
  39          if ( BAD == $p_result ) {
  40              if ( $p_hard_fail ) {
  41                  $g_failed = true;
  42                  echo " - ERROR: ";
  43              } else {
  44                  echo " - WARNING: ";
  45              }
  46              if ( '' != $p_message ) {
  47                  echo $p_message;
  48              }
  49          }
  50  
  51          if ( GOOD == $p_result ) {
  52              echo " - GOOD";
  53          }
  54          echo "\n";
  55      }
  56  
  57      # @@@ upgrade list moved to the bottom of upgrade_inc.php
  58      $result = @db_connect( config_get_global( 'dsn', false ), config_get_global( 'hostname' ), 
  59              config_get_global( 'db_username' ), config_get_global( 'db_password' ), 
  60              config_get_global( 'database_name' ) );
  61  
  62      if ( false == $result ) {
  63          echo "Opening connection to database " . 
  64              config_get_global( 'database_name' ) .
  65              " on host " . config_get_global( 'hostname' ) . 
  66              " with username " . config_get_global( 'db_username' ) .
  67              " failed: " . db_error_msg() . "\n";
  68          exit(1);
  69      }
  70  
  71      # check to see if the new installer was used
  72      if ( -1 == config_get( 'database_version', -1 ) ) {
  73          # Old database detected: run the old style upgrade set
  74          if ( ! db_table_exists( config_get( 'mantis_upgrade_table' ) ) ) {
  75              # Create the upgrade table if it does not exist
  76              $query = "CREATE TABLE " . config_get( 'mantis_upgrade_table' ) .
  77                  "(upgrade_id char(20) NOT NULL,
  78                  description char(255) NOT NULL,
  79                  PRIMARY KEY (upgrade_id))";
  80  
  81              $result = db_query( $query );
  82          }
  83  
  84          # link the data structures and upgrade list
  85          require_once  ( 'upgrade_inc.php' );
  86          $error = $upgrade_set->run_all_unattended();
  87  
  88          if ( true == $error ) {
  89              exit (1);
  90          }
  91      }
  92  
  93      # read control variables with defaults
  94      $f_hostname = gpc_get( 'hostname', config_get( 'hostname', 'localhost' ) );
  95      $f_db_type = gpc_get( 'db_type', config_get( 'db_type', '' ) );
  96      $f_database_name = gpc_get( 'database_name', config_get( 'database_name', 'bugtrack') );
  97      $f_db_username = gpc_get( 'db_username', config_get( 'db_username', '' ) );
  98      $f_db_password = gpc_get( 'db_password', config_get( 'db_password', '' ) );
  99      $f_db_exists = gpc_get_bool( 'db_exists', false );
 100  
 101      # install the tables
 102      $GLOBALS['g_db_type'] = $f_db_type; # database_api references this
 103      require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'schema.php' );
 104      $g_db = ADONewConnection( $f_db_type );
 105  
 106      echo "\nPost 1.0 schema changes\n";
 107      echo "Connecting to database... ";
 108      $t_result = @$g_db->Connect( $f_hostname, $f_db_username, $f_db_password, $f_database_name );
 109  
 110      if (false == $t_result ) {
 111          echo "failed\n";
 112          exit (1);
 113      }
 114  
 115      echo "OK\n";
 116  
 117      $g_db_connected = true; # fake out database access routines used by config_get
 118      $t_last_update = config_get( 'database_version', -1, ALL_USERS, ALL_PROJECTS );
 119      $lastid = sizeof( $upgrade ) - 1;
 120      $i = $t_last_update + 1;
 121  
 122      while ( ( $i <= $lastid ) && ! $g_failed ) {
 123          echo 'Create Schema ( ' . $upgrade[$i][0] . ' on ' . $upgrade[$i][1][0] . ' )';
 124          $dict = NewDataDictionary($g_db);
 125  
 126          if ( $upgrade[$i][0] == 'InsertData' ) {
 127              $sqlarray = call_user_func_array( $upgrade[$i][0], $upgrade[$i][1] );
 128          } else {
 129              $sqlarray = call_user_func_array(Array($dict,$upgrade[$i][0]),$upgrade[$i][1]);
 130          }
 131  
 132          $ret = $dict->ExecuteSQLArray($sqlarray);
 133          if ( $ret == 2 ) {
 134              print_test_result( GOOD );
 135              config_set( 'database_version', $i );
 136          } else {
 137              print_test_result( BAD, true, $sqlarray[0] . '<br />' . $g_db->ErrorMsg() );
 138          }
 139  
 140          $i++;
 141      }
 142  
 143      if ( false == $g_failed ) {
 144          exit (0);
 145      }
 146  
 147      exit (1)
 148  # vim: noexpandtab tabstop=4 softtabstop=0:
 149  ?>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics