3 * IBM_DB2-specific installer.
10 * Class for setting up the MediaWiki database using IBM_DB2.
15 class Ibm_db2Installer
extends DatabaseInstaller
{
18 protected $globalNames = array(
28 * Get the DB2 database extension name
31 public function getName(){
36 * Determine whether the DB2 database extension is currently available in PHP
39 public function isCompiled() {
40 return self
::checkExtension( 'ibm_db2' );
44 * Generate a connection form for a DB2 database
47 public function getConnectForm() {
49 $this->getTextBox( 'wgDBserver', 'config-db-host', array(), $this->parent
->getHelpBox( 'config-db-host-help' ) ) .
50 $this->getTextBox( 'wgDBport', 'config-db-port', array(), $this->parent
->getHelpBox( 'config-db-port' ) ) .
51 Html
::openElement( 'fieldset' ) .
52 Html
::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
53 $this->getTextBox( 'wgDBname', 'config-db-name', array(), $this->parent
->getHelpBox( 'config-db-name-help' ) ) .
54 $this->getTextBox( 'wgDBmwschema', 'config-db-schema', array(), $this->parent
->getHelpBox( 'config-db-schema-help' ) ) .
55 Html
::closeElement( 'fieldset' ) .
56 $this->getInstallUserBox();
60 * Validate and then execute the connection form for a DB2 database
63 public function submitConnectForm() {
64 // Get variables from the request
65 $newValues = $this->setVarsFromRequest(
66 array( 'wgDBserver', 'wgDBport', 'wgDBname',
67 'wgDBmwschema', 'wgDBuser', 'wgDBpassword' ) );
70 $status = Status
::newGood();
71 if ( !strlen( $newValues['wgDBname'] ) ) {
72 $status->fatal( 'config-missing-db-name' );
73 } elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {
74 $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
76 if ( !strlen( $newValues['wgDBmwschema'] ) ) {
77 $status->fatal( 'config-invalid-schema' );
79 elseif ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
80 $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
82 if ( !strlen( $newValues['wgDBport'] ) ) {
83 $status->fatal( 'config-invalid-port' );
85 elseif ( !preg_match( '/^[0-9_]*$/', $newValues['wgDBport'] ) ) {
86 $status->fatal( 'config-invalid-port', $newValues['wgDBport'] );
90 if ( $status->isOK() ) {
91 $status->merge( $this->submitInstallUserBox() );
93 if ( !$status->isOK() ) {
98 $wgDBport = $newValues['wgDBport'];
101 $status->merge( $this->getConnection() );
102 if ( !$status->isOK() ) {
106 $this->parent
->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
107 $this->parent
->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
113 * Open a DB2 database connection
116 public function openConnection() {
117 $status = Status
::newGood();
119 $db = new DatabaseIbm_db2(
120 $this->getVar( 'wgDBserver' ),
121 $this->getVar( '_InstallUser' ),
122 $this->getVar( '_InstallPassword' ),
123 $this->getVar( 'wgDBname' ),
125 $this->getVar( 'wgDBmwschema' )
127 $status->value
= $db;
128 } catch ( DBConnectionError
$e ) {
129 $status->fatal( 'config-connection-error', $e->getMessage() );
135 * Create a DB2 database for MediaWiki
138 public function setupDatabase() {
139 $status = $this->getConnection();
140 if ( !$status->isOK() ) {
143 $conn = $status->value
;
144 $dbName = $this->getVar( 'wgDBname' );
145 if( !$conn->selectDB( $dbName ) ) {
146 $conn->query( "CREATE DATABASE "
147 . $conn->addIdentifierQuotes( $dbName )
148 . " AUTOMATIC STORAGE YES"
149 . " USING CODESET UTF-8 TERRITORY US COLLATE USING SYSTEM"
150 . " PAGESIZE 32768", __METHOD__
);
151 $conn->selectDB( $dbName );
153 $this->setupSchemaVars();
158 * Create tables from scratch.
159 * First check if pagesize >= 32k.
163 public function createTables() {
164 $status = $this->getConnection();
165 if ( !$status->isOK() ) {
168 $this->db
->selectDB( $this->getVar( 'wgDBname' ) );
170 if( $this->db
->tableExists( 'user' ) ) {
171 $status->warning( 'config-install-tables-exist' );
175 /* Check for pagesize */
176 $status = $this->checkPageSize();
177 if ( !$status->isOK() ) {
181 $this->db
->setFlag( DBO_DDLMODE
); // For Oracle's handling of schema files
182 $this->db
->begin( __METHOD__
);
184 $error = $this->db
->sourceFile( $this->db
->getSchema() );
185 if( $error !== true ) {
186 $this->db
->reportQueryError( $error, 0, '', __METHOD__
);
187 $this->db
->rollback( __METHOD__
);
188 $status->fatal( 'config-install-tables-failed', $error );
190 $this->db
->commit( __METHOD__
);
192 // Resume normal operations
193 if( $status->isOk() ) {
200 * Check if database has a tablspace with pagesize >= 32k.
204 public function checkPageSize() {
205 $status = $this->getConnection();
206 if ( !$status->isOK() ) {
209 $this->db
->selectDB( $this->getVar( 'wgDBname' ) );
212 $result = $this->db
->query( 'SELECT PAGESIZE FROM SYSCAT.TABLESPACES' );
213 if( $result == false ) {
214 $status->fatal( 'config-connection-error', '' );
217 while ( $row = $this->db
->fetchRow( $result ) ) {
218 if( $row[0] >= 32768 ) {
222 $status->fatal( 'config-ibm_db2-low-db-pagesize', '' );
224 } catch ( DBUnexpectedError
$e ) {
225 $status->fatal( 'config-connection-error', $e->getMessage() );
232 * Generate the code to store the DB2-specific settings defined by the configuration form
235 public function getLocalSettings() {
236 $schema = LocalSettingsGenerator
::escapePhpString( $this->getVar( 'wgDBmwschema' ) );
237 $port = LocalSettingsGenerator
::escapePhpString( $this->getVar( 'wgDBport' ) );
239 "# IBM_DB2 specific settings
240 \$wgDBmwschema = \"{$schema}\";
241 \$wgDBport = \"{$port}\";";
244 public function __construct($parent) {
245 parent
::__construct($parent);