<?php
-
-class MysqlInstaller extends InstallerDBType {
+/**
+ * MySQL-specific installer.
+ *
+ * @file
+ * @ingroup Deployment
+ */
+
+/**
+ * Class for setting up the MediaWiki database using MySQL.
+ *
+ * @ingroup Deployment
+ * @since 1.17
+ */
+class MysqlInstaller extends DatabaseInstaller {
+
protected $globalNames = array(
'wgDBserver',
'wgDBname',
'_MysqlCharset' => 'binary',
);
- var $supportedEngines = array( 'InnoDB', 'MyISAM' );
+ public $supportedEngines = array( 'InnoDB', 'MyISAM' );
- var $minimumVersion = '4.0.14';
+ public $minimumVersion = '4.0.14';
- var $webUserPrivs = array(
+ public $webUserPrivs = array(
'DELETE',
'INSERT',
'SELECT',
'CREATE TEMPORARY TABLES',
);
- function getName() {
+ public function getName() {
return 'mysql';
}
- function __construct( $parent ) {
+ public function __construct( $parent ) {
parent::__construct( $parent );
}
return self::checkExtension( 'mysql' );
}
- function getGlobalDefaults() {
+ public function getGlobalDefaults() {
return array();
}
- function getConnectForm() {
+ public function getConnectForm() {
return
$this->getTextBox( 'wgDBserver', 'config-db-host' ) .
$this->parent->getHelpBox( 'config-db-host-help' ) .
$this->getInstallUserBox();
}
- function submitConnectForm() {
- // Get variables from the request
+ public function submitConnectForm() {
+ // Get variables from the request.
$newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBname', 'wgDBprefix' ) );
- // Validate them
+ // Validate them.
$status = Status::newGood();
if ( !strlen( $newValues['wgDBname'] ) ) {
$status->fatal( 'config-missing-db-name' );
return $status;
}
- function getConnection() {
+ public function getConnection() {
$status = Status::newGood();
try {
$this->db = new DatabaseMysql(
$this->getVar( 'wgDBprefix' )
);
$status->value = $this->db;
- return $status;
} catch ( DBConnectionError $e ) {
$status->fatal( 'config-connection-error', $e->getMessage() );
}
return $status;
}
- function doUpgrade() {
+ public function preUpgrade() {
+ global $wgDBuser, $wgDBpassword;
+
$status = $this->getConnection();
if ( !$status->isOK() ) {
$this->parent->showStatusError( $status );
return;
}
$conn = $status->value;
+ $conn->selectDB( $this->getVar( 'wgDBname' ) );
# Determine existing default character set
if ( $conn->tableExists( "revision" ) ) {
$revision = $conn->escapeLike( $this->getVar( 'wgDBprefix' ) . 'revision' );
- $res = $conn->query( "SHOW TABLE STATUS LIKE '$revision'" );
+ $res = $conn->query( "SHOW TABLE STATUS LIKE '$revision'", __METHOD__ );
$row = $conn->fetchObject( $res );
if ( !$row ) {
$this->parent->showMessage( 'config-show-table-status' );
$existingEngine = $row->Type;
}
}
+ } else {
+ $existingSchema = false;
+ $existingEngine = false;
}
-
- // TODO
+
+ if ( $existingSchema && $existingSchema != $this->getVar( '_MysqlCharset' ) ) {
+ $this->parent->showMessage( 'config-mysql-charset-mismatch', $this->getVar( '_MysqlCharset' ), $existingSchema );
+ $this->setVar( '_MysqlCharset', $existingSchema );
+ }
+ if ( $existingEngine && $existingEngine != $this->getVar( '_MysqlEngine' ) ) {
+ $this->parent->showMessage( 'config-mysql-egine-mismatch', $this->getVar( '_MysqlEngine' ), $existingEngine );
+ $this->setVar( '_MysqlEngine', $existingEngine );
+ }
+
+ # Normal user and password are selected after this step, so for now
+ # just copy these two
+ $wgDBuser = $this->getVar( '_InstallUser' );
+ $wgDBpassword = $this->getVar( '_InstallPassword' );
}
/**
* Get a list of storage engines that are available and supported
*/
- function getEngines() {
+ public function getEngines() {
$engines = array( 'InnoDB', 'MyISAM' );
$status = $this->getConnection();
if ( !$status->isOK() ) {
}
$engines = array();
- $res = $conn->query( 'SHOW ENGINES' );
+ $res = $conn->query( 'SHOW ENGINES', __METHOD__ );
foreach ( $res as $row ) {
if ( $row->Support == 'YES' || $row->Support == 'DEFAULT' ) {
$engines[] = $row->Engine;
/**
* Get a list of character sets that are available and supported
*/
- function getCharsets() {
+ public function getCharsets() {
$status = $this->getConnection();
$mysql5 = array( 'binary', 'utf8' );
$mysql4 = array( 'mysql4' );
/**
* Return true if the install user can create accounts
*/
- function canCreateAccounts() {
+ public function canCreateAccounts() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return false;
return true;
}
- function getSettingsForm() {
+ public function getSettingsForm() {
if ( $this->canCreateAccounts() ) {
$noCreateMsg = false;
} else {
return $s;
}
- function submitSettingsForm() {
+ public function submitSettingsForm() {
$newValues = $this->setVarsFromRequest( array( '_MysqlEngine', '_MysqlCharset' ) );
$status = $this->submitWebUserBox();
if ( !$status->isOK() ) {
$this->parent->addInstallStepFollowing( "tables", $callback );
}
- function setupDatabase() {
+ public function setupDatabase() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
$conn = $status->value;
$dbName = $this->getVar( 'wgDBname' );
if( !$conn->selectDB( $dbName ) ) {
- $conn->query( "CREATE DATABASE `$dbName`" );
+ $conn->query( "CREATE DATABASE `$dbName`", __METHOD__ );
$conn->selectDB( $dbName );
}
return $status;
}
- function setupUser() {
+ public function setupUser() {
global $IP;
if ( !$this->getVar( '_CreateDBAccount' ) ) {
return $status;
}
- function createTables() {
- global $IP;
- $status = $this->getConnection();
- if ( !$status->isOK() ) {
- return $status;
- }
- $this->db->selectDB( $this->getVar( 'wgDBname' ) );
-
- if( $this->db->tableExists( 'user' ) ) {
- $status->warning( 'config-install-tables-exist' );
- return $status;
- }
-
- $error = $this->db->sourceFile( "$IP/maintenance/tables.sql" );
- if( $error !== true ) {
- $status->fatal( 'config-install-tables-failed', $error );
- }
- return $status;
- }
-
- function getTableOptions() {
+ public function getTableOptions() {
return array( 'engine' => $this->getVar( '_MysqlEngine' ),
'default charset' => $this->getVar( '_MysqlCharset' ) );
}
- function getLocalSettings() {
+ public function getLocalSettings() {
$dbmysql5 = wfBoolToStr( $this->getVar( 'wgDBmysql5', true ) );
$prefix = $this->getVar( 'wgDBprefix' );
$opts = $this->getTableOptions();