MediaWiki
REL1_19
|
00001 <?php 00015 class Ibm_db2Installer extends DatabaseInstaller { 00016 00017 00018 protected $globalNames = array( 00019 'wgDBserver', 00020 'wgDBport', 00021 'wgDBname', 00022 'wgDBuser', 00023 'wgDBpassword', 00024 'wgDBmwschema', 00025 ); 00026 00027 protected $internalDefaults = array( 00028 '_InstallUser' => 'db2admin' 00029 ); 00030 00035 public function getName(){ 00036 return 'ibm_db2'; 00037 } 00038 00043 public function isCompiled() { 00044 return self::checkExtension( 'ibm_db2' ); 00045 } 00046 00051 public function getConnectForm() { 00052 return 00053 $this->getTextBox( 'wgDBserver', 'config-db-host', array(), $this->parent->getHelpBox( 'config-db-host-help' ) ) . 00054 $this->getTextBox( 'wgDBport', 'config-db-port', array(), $this->parent->getHelpBox( 'config-db-port' ) ) . 00055 Html::openElement( 'fieldset' ) . 00056 Html::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) . 00057 $this->getTextBox( 'wgDBname', 'config-db-name', array(), $this->parent->getHelpBox( 'config-db-name-help' ) ) . 00058 $this->getTextBox( 'wgDBmwschema', 'config-db-schema', array(), $this->parent->getHelpBox( 'config-db-schema-help' ) ) . 00059 Html::closeElement( 'fieldset' ) . 00060 $this->getInstallUserBox(); 00061 } 00062 00067 public function submitConnectForm() { 00068 // Get variables from the request 00069 $newValues = $this->setVarsFromRequest( 00070 array( 'wgDBserver', 'wgDBport', 'wgDBname', 00071 'wgDBmwschema', 'wgDBuser', 'wgDBpassword' ) ); 00072 00073 // Validate them 00074 $status = Status::newGood(); 00075 if ( !strlen( $newValues['wgDBname'] ) ) { 00076 $status->fatal( 'config-missing-db-name' ); 00077 } elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) { 00078 $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] ); 00079 } 00080 if ( !strlen( $newValues['wgDBmwschema'] ) ) { 00081 $status->fatal( 'config-invalid-schema' ); 00082 } 00083 elseif ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) { 00084 $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] ); 00085 } 00086 if ( !strlen( $newValues['wgDBport'] ) ) { 00087 $status->fatal( 'config-invalid-port' ); 00088 } 00089 elseif ( !preg_match( '/^[0-9_]*$/', $newValues['wgDBport'] ) ) { 00090 $status->fatal( 'config-invalid-port', $newValues['wgDBport'] ); 00091 } 00092 00093 // Submit user box 00094 if ( $status->isOK() ) { 00095 $status->merge( $this->submitInstallUserBox() ); 00096 } 00097 if ( !$status->isOK() ) { 00098 return $status; 00099 } 00100 00101 global $wgDBport; 00102 $wgDBport = $newValues['wgDBport']; 00103 00104 // Try to connect 00105 $status->merge( $this->getConnection() ); 00106 if ( !$status->isOK() ) { 00107 return $status; 00108 } 00109 00110 $this->parent->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) ); 00111 $this->parent->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) ); 00112 00113 return $status; 00114 } 00115 00120 public function openConnection() { 00121 $status = Status::newGood(); 00122 try { 00123 $db = new DatabaseIbm_db2( 00124 $this->getVar( 'wgDBserver' ), 00125 $this->getVar( '_InstallUser' ), 00126 $this->getVar( '_InstallPassword' ), 00127 $this->getVar( 'wgDBname' ), 00128 0, 00129 $this->getVar( 'wgDBmwschema' ) 00130 ); 00131 $status->value = $db; 00132 } catch ( DBConnectionError $e ) { 00133 $status->fatal( 'config-connection-error', $e->getMessage() ); 00134 } 00135 return $status; 00136 } 00137 00142 public function setupDatabase() { 00143 $status = $this->getConnection(); 00144 if ( !$status->isOK() ) { 00145 return $status; 00146 } 00150 $conn = $status->value; 00151 $dbName = $this->getVar( 'wgDBname' ); 00152 if( !$conn->selectDB( $dbName ) ) { 00153 $conn->query( "CREATE DATABASE " 00154 . $conn->addIdentifierQuotes( $dbName ) 00155 . " AUTOMATIC STORAGE YES" 00156 . " USING CODESET UTF-8 TERRITORY US COLLATE USING SYSTEM" 00157 . " PAGESIZE 32768", __METHOD__ ); 00158 $conn->selectDB( $dbName ); 00159 } 00160 $this->setupSchemaVars(); 00161 return $status; 00162 } 00163 00170 public function createTables() { 00171 $status = $this->getConnection(); 00172 if ( !$status->isOK() ) { 00173 return $status; 00174 } 00175 $this->db->selectDB( $this->getVar( 'wgDBname' ) ); 00176 00177 if( $this->db->tableExists( 'user' ) ) { 00178 $status->warning( 'config-install-tables-exist' ); 00179 return $status; 00180 } 00181 00182 /* Check for pagesize */ 00183 $status = $this->checkPageSize(); 00184 if ( !$status->isOK() ) { 00185 return $status; 00186 } 00187 00188 $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files 00189 $this->db->begin( __METHOD__ ); 00190 00191 $error = $this->db->sourceFile( $this->db->getSchemaPath() ); 00192 if( $error !== true ) { 00193 $this->db->reportQueryError( $error, 0, '', __METHOD__ ); 00194 $this->db->rollback( __METHOD__ ); 00195 $status->fatal( 'config-install-tables-failed', $error ); 00196 } else { 00197 $this->db->commit( __METHOD__ ); 00198 } 00199 // Resume normal operations 00200 if( $status->isOk() ) { 00201 $this->enableLB(); 00202 } 00203 return $status; 00204 } 00205 00211 public function checkPageSize() { 00212 $status = $this->getConnection(); 00213 if ( !$status->isOK() ) { 00214 return $status; 00215 } 00216 $this->db->selectDB( $this->getVar( 'wgDBname' ) ); 00217 00218 try { 00219 $result = $this->db->query( 'SELECT PAGESIZE FROM SYSCAT.TABLESPACES FOR READ ONLY' ); 00220 if( $result == false ) { 00221 $status->fatal( 'config-connection-error', '' ); 00222 } else { 00223 $row = $this->db->fetchRow( $result ); 00224 while ( $row ) { 00225 if( $row[0] >= 32768 ) { 00226 return $status; 00227 } 00228 $row = $this->db->fetchRow( $result ); 00229 } 00230 $status->fatal( 'config-ibm_db2-low-db-pagesize', '' ); 00231 } 00232 } catch ( DBUnexpectedError $e ) { 00233 $status->fatal( 'config-connection-error', $e->getMessage() ); 00234 } 00235 00236 return $status; 00237 } 00238 00243 public function getLocalSettings() { 00244 $schema = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBmwschema' ) ); 00245 $port = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBport' ) ); 00246 return 00247 "# IBM_DB2 specific settings 00248 \$wgDBmwschema = \"{$schema}\"; 00249 \$wgDBport = \"{$port}\";"; 00250 } 00251 00252 public function __construct( $parent ) { 00253 parent::__construct( $parent ); 00254 } 00255 }