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(
27 protected $internalDefaults = array(
28 '_InstallUser' => 'db2admin'
32 * Get the DB2 database extension name
35 public function getName(){
40 * Determine whether the DB2 database extension is currently available in PHP
43 public function isCompiled() {
44 return self
::checkExtension( 'ibm_db2' );
48 * Generate a connection form for a DB2 database
51 public function getConnectForm() {
53 $this->getTextBox( 'wgDBserver', 'config-db-host', array(), $this->parent
->getHelpBox( 'config-db-host-help' ) ) .
54 $this->getTextBox( 'wgDBport', 'config-db-port', array(), $this->parent
->getHelpBox( 'config-db-port' ) ) .
55 Html
::openElement( 'fieldset' ) .
56 Html
::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
57 $this->getTextBox( 'wgDBname', 'config-db-name', array(), $this->parent
->getHelpBox( 'config-db-name-help' ) ) .
58 $this->getTextBox( 'wgDBmwschema', 'config-db-schema', array(), $this->parent
->getHelpBox( 'config-db-schema-help' ) ) .
59 Html
::closeElement( 'fieldset' ) .
60 $this->getInstallUserBox();
64 * Validate and then execute the connection form for a DB2 database
67 public function submitConnectForm() {
68 // Get variables from the request
69 $newValues = $this->setVarsFromRequest(
70 array( 'wgDBserver', 'wgDBport', 'wgDBname',
71 'wgDBmwschema', 'wgDBuser', 'wgDBpassword' ) );
74 $status = Status
::newGood();
75 if ( !strlen( $newValues['wgDBname'] ) ) {
76 $status->fatal( 'config-missing-db-name' );
77 } elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {
78 $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
80 if ( !strlen( $newValues['wgDBmwschema'] ) ) {
81 $status->fatal( 'config-invalid-schema' );
83 elseif ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
84 $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
86 if ( !strlen( $newValues['wgDBport'] ) ) {
87 $status->fatal( 'config-invalid-port' );
89 elseif ( !preg_match( '/^[0-9_]*$/', $newValues['wgDBport'] ) ) {
90 $status->fatal( 'config-invalid-port', $newValues['wgDBport'] );
94 if ( $status->isOK() ) {
95 $status->merge( $this->submitInstallUserBox() );
97 if ( !$status->isOK() ) {
102 $wgDBport = $newValues['wgDBport'];
105 $status->merge( $this->getConnection() );
106 if ( !$status->isOK() ) {
110 $this->parent
->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
111 $this->parent
->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
117 * Open a DB2 database connection
120 public function openConnection() {
121 $status = Status
::newGood();
123 $db = new DatabaseIbm_db2(
124 $this->getVar( 'wgDBserver' ),
125 $this->getVar( '_InstallUser' ),
126 $this->getVar( '_InstallPassword' ),
127 $this->getVar( 'wgDBname' ),
129 $this->getVar( 'wgDBmwschema' )
131 $status->value
= $db;
132 } catch ( DBConnectionError
$e ) {
133 $status->fatal( 'config-connection-error', $e->getMessage() );
139 * Create a DB2 database for MediaWiki
142 public function setupDatabase() {
143 $status = $this->getConnection();
144 if ( !$status->isOK() ) {
148 * @var $conn DatabaseBase
150 $conn = $status->value
;
151 $dbName = $this->getVar( 'wgDBname' );
152 if( !$conn->selectDB( $dbName ) ) {
153 $conn->query( "CREATE DATABASE "
154 . $conn->addIdentifierQuotes( $dbName )
155 . " AUTOMATIC STORAGE YES"
156 . " USING CODESET UTF-8 TERRITORY US COLLATE USING SYSTEM"
157 . " PAGESIZE 32768", __METHOD__
);
158 $conn->selectDB( $dbName );
160 $this->setupSchemaVars();
165 * Create tables from scratch.
166 * First check if pagesize >= 32k.
170 public function createTables() {
171 $status = $this->getConnection();
172 if ( !$status->isOK() ) {
175 $this->db
->selectDB( $this->getVar( 'wgDBname' ) );
177 if( $this->db
->tableExists( 'user' ) ) {
178 $status->warning( 'config-install-tables-exist' );
182 /* Check for pagesize */
183 $status = $this->checkPageSize();
184 if ( !$status->isOK() ) {
188 $this->db
->setFlag( DBO_DDLMODE
); // For Oracle's handling of schema files
189 $this->db
->begin( __METHOD__
);
191 $error = $this->db
->sourceFile( $this->db
->getSchemaPath() );
192 if( $error !== true ) {
193 $this->db
->reportQueryError( $error, 0, '', __METHOD__
);
194 $this->db
->rollback( __METHOD__
);
195 $status->fatal( 'config-install-tables-failed', $error );
197 $this->db
->commit( __METHOD__
);
199 // Resume normal operations
200 if( $status->isOk() ) {
207 * Check if database has a tablspace with pagesize >= 32k.
211 public function checkPageSize() {
212 $status = $this->getConnection();
213 if ( !$status->isOK() ) {
216 $this->db
->selectDB( $this->getVar( 'wgDBname' ) );
219 $result = $this->db
->query( 'SELECT PAGESIZE FROM SYSCAT.TABLESPACES' );
220 if( $result == false ) {
221 $status->fatal( 'config-connection-error', '' );
223 $row = $this->db
->fetchRow( $result );
225 if( $row[0] >= 32768 ) {
228 $row = $this->db
->fetchRow( $result );
230 $status->fatal( 'config-ibm_db2-low-db-pagesize', '' );
232 } catch ( DBUnexpectedError
$e ) {
233 $status->fatal( 'config-connection-error', $e->getMessage() );
240 * Generate the code to store the DB2-specific settings defined by the configuration form
243 public function getLocalSettings() {
244 $schema = LocalSettingsGenerator
::escapePhpString( $this->getVar( 'wgDBmwschema' ) );
245 $port = LocalSettingsGenerator
::escapePhpString( $this->getVar( 'wgDBport' ) );
247 "# IBM_DB2 specific settings
248 \$wgDBmwschema = \"{$schema}\";
249 \$wgDBport = \"{$port}\";";
252 public function __construct($parent) {
253 parent
::__construct($parent);