<?php
-
+/**
+ * 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(
}
public function submitConnectForm() {
- // Get variables from the request
+ // 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' );
$this->getVar( 'wgDBprefix' )
);
$status->value = $this->db;
- return $status;
} catch ( DBConnectionError $e ) {
$status->fatal( 'config-connection-error', $e->getMessage() );
}
return $status;
}
- public 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' );
}
/**
}
$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;
$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;
return $status;
}
- public 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;
- }
-
public function getTableOptions() {
return array( 'engine' => $this->getVar( '_MysqlEngine' ),
'default charset' => $this->getVar( '_MysqlCharset' ) );