3 * IBM_DB2-specific installer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Class for setting up the MediaWiki database using IBM_DB2.
30 class Ibm_db2Installer
extends DatabaseInstaller
{
33 protected $globalNames = array(
42 protected $internalDefaults = array(
43 '_InstallUser' => 'db2admin'
47 * Get the DB2 database extension name
50 public function getName(){
55 * Determine whether the DB2 database extension is currently available in PHP
58 public function isCompiled() {
59 return self
::checkExtension( 'ibm_db2' );
63 * Generate a connection form for a DB2 database
66 public function getConnectForm() {
68 $this->getTextBox( 'wgDBserver', 'config-db-host', array(), $this->parent
->getHelpBox( 'config-db-host-help' ) ) .
69 $this->getTextBox( 'wgDBport', 'config-db-port', array(), $this->parent
->getHelpBox( 'config-db-port' ) ) .
70 Html
::openElement( 'fieldset' ) .
71 Html
::element( 'legend', array(), wfMessage( 'config-db-wiki-settings' )->text() ) .
72 $this->getTextBox( 'wgDBname', 'config-db-name', array(), $this->parent
->getHelpBox( 'config-db-name-help' ) ) .
73 $this->getTextBox( 'wgDBmwschema', 'config-db-schema', array(), $this->parent
->getHelpBox( 'config-db-schema-help' ) ) .
74 Html
::closeElement( 'fieldset' ) .
75 $this->getInstallUserBox();
79 * Validate and then execute the connection form for a DB2 database
82 public function submitConnectForm() {
83 // Get variables from the request
84 $newValues = $this->setVarsFromRequest(
85 array( 'wgDBserver', 'wgDBport', 'wgDBname',
86 'wgDBmwschema', 'wgDBuser', 'wgDBpassword' ) );
89 $status = Status
::newGood();
90 if ( !strlen( $newValues['wgDBname'] ) ) {
91 $status->fatal( 'config-missing-db-name' );
92 } elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {
93 $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
95 if ( !strlen( $newValues['wgDBmwschema'] ) ) {
96 $status->fatal( 'config-invalid-schema' );
98 elseif ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
99 $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
101 if ( !strlen( $newValues['wgDBport'] ) ) {
102 $status->fatal( 'config-invalid-port' );
104 elseif ( !preg_match( '/^[0-9_]*$/', $newValues['wgDBport'] ) ) {
105 $status->fatal( 'config-invalid-port', $newValues['wgDBport'] );
109 if ( $status->isOK() ) {
110 $status->merge( $this->submitInstallUserBox() );
112 if ( !$status->isOK() ) {
117 $wgDBport = $newValues['wgDBport'];
120 $status->merge( $this->getConnection() );
121 if ( !$status->isOK() ) {
125 $this->parent
->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
126 $this->parent
->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
132 * Open a DB2 database connection
135 public function openConnection() {
136 $status = Status
::newGood();
138 $db = new DatabaseIbm_db2(
139 $this->getVar( 'wgDBserver' ),
140 $this->getVar( '_InstallUser' ),
141 $this->getVar( '_InstallPassword' ),
142 $this->getVar( 'wgDBname' ),
144 $this->getVar( 'wgDBmwschema' )
146 $status->value
= $db;
147 } catch ( DBConnectionError
$e ) {
148 $status->fatal( 'config-connection-error', $e->getMessage() );
154 * Create a DB2 database for MediaWiki
157 public function setupDatabase() {
158 $status = $this->getConnection();
159 if ( !$status->isOK() ) {
163 * @var $conn DatabaseBase
165 $conn = $status->value
;
166 $dbName = $this->getVar( 'wgDBname' );
167 if( !$conn->selectDB( $dbName ) ) {
168 $conn->query( "CREATE DATABASE "
169 . $conn->addIdentifierQuotes( $dbName )
170 . " AUTOMATIC STORAGE YES"
171 . " USING CODESET UTF-8 TERRITORY US COLLATE USING SYSTEM"
172 . " PAGESIZE 32768", __METHOD__
);
173 $conn->selectDB( $dbName );
175 $this->setupSchemaVars();
180 * Create tables from scratch.
181 * First check if pagesize >= 32k.
185 public function createTables() {
186 $status = $this->getConnection();
187 if ( !$status->isOK() ) {
190 $this->db
->selectDB( $this->getVar( 'wgDBname' ) );
192 if( $this->db
->tableExists( 'user' ) ) {
193 $status->warning( 'config-install-tables-exist' );
197 /* Check for pagesize */
198 $status = $this->checkPageSize();
199 if ( !$status->isOK() ) {
203 $this->db
->setFlag( DBO_DDLMODE
); // For Oracle's handling of schema files
204 $this->db
->begin( __METHOD__
);
206 $error = $this->db
->sourceFile( $this->db
->getSchemaPath() );
207 if( $error !== true ) {
208 $this->db
->reportQueryError( $error, 0, '', __METHOD__
);
209 $this->db
->rollback( __METHOD__
);
210 $status->fatal( 'config-install-tables-failed', $error );
212 $this->db
->commit( __METHOD__
);
214 // Resume normal operations
215 if( $status->isOk() ) {
222 * Check if database has a tablspace with pagesize >= 32k.
226 public function checkPageSize() {
227 $status = $this->getConnection();
228 if ( !$status->isOK() ) {
231 $this->db
->selectDB( $this->getVar( 'wgDBname' ) );
234 $result = $this->db
->query( 'SELECT PAGESIZE FROM SYSCAT.TABLESPACES FOR READ ONLY' );
235 if( $result == false ) {
236 $status->fatal( 'config-connection-error', '' );
238 $row = $this->db
->fetchRow( $result );
240 if( $row[0] >= 32768 ) {
243 $row = $this->db
->fetchRow( $result );
245 $status->fatal( 'config-ibm_db2-low-db-pagesize', '' );
247 } catch ( DBUnexpectedError
$e ) {
248 $status->fatal( 'config-connection-error', $e->getMessage() );
255 * Generate the code to store the DB2-specific settings defined by the configuration form
258 public function getLocalSettings() {
259 $schema = LocalSettingsGenerator
::escapePhpString( $this->getVar( 'wgDBmwschema' ) );
260 $port = LocalSettingsGenerator
::escapePhpString( $this->getVar( 'wgDBport' ) );
262 "# IBM_DB2 specific settings
263 \$wgDBmwschema = \"{$schema}\";
264 \$wgDBport = \"{$port}\";";
267 public function __construct( $parent ) {
268 parent
::__construct( $parent );