summaryrefslogtreecommitdiff
path: root/includes/installer/DatabaseInstaller.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/installer/DatabaseInstaller.php')
-rw-r--r--includes/installer/DatabaseInstaller.php87
1 files changed, 55 insertions, 32 deletions
diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php
index de59b2d6..0110ac52 100644
--- a/includes/installer/DatabaseInstaller.php
+++ b/includes/installer/DatabaseInstaller.php
@@ -32,7 +32,7 @@ abstract class DatabaseInstaller {
/**
* The Installer object.
*
- * TODO: naming this parent is confusing, 'installer' would be clearer.
+ * @todo Naming this parent is confusing, 'installer' would be clearer.
*
* @var WebInstaller
*/
@@ -62,12 +62,12 @@ abstract class DatabaseInstaller {
/**
* Return the internal name, e.g. 'mysql', or 'sqlite'.
*/
- public abstract function getName();
+ abstract public function getName();
/**
* @return bool Returns true if the client library is compiled in.
*/
- public abstract function isCompiled();
+ abstract public function isCompiled();
/**
* Checks for installation prerequisites other than those checked by isCompiled()
@@ -85,7 +85,7 @@ abstract class DatabaseInstaller {
*
* If this is called, $this->parent can be assumed to be a WebInstaller.
*/
- public abstract function getConnectForm();
+ abstract public function getConnectForm();
/**
* Set variables based on the request array, assuming it was submitted
@@ -96,7 +96,7 @@ abstract class DatabaseInstaller {
*
* @return Status
*/
- public abstract function submitConnectForm();
+ abstract public function submitConnectForm();
/**
* Get HTML for a web form that retrieves settings used for installation.
@@ -127,7 +127,7 @@ abstract class DatabaseInstaller {
*
* @return Status
*/
- public abstract function openConnection();
+ abstract public function openConnection();
/**
* Create the database and return a Status object indicating success or
@@ -135,7 +135,7 @@ abstract class DatabaseInstaller {
*
* @return Status
*/
- public abstract function setupDatabase();
+ abstract public function setupDatabase();
/**
* Connect to the database using the administrative user/password currently
@@ -158,6 +158,7 @@ abstract class DatabaseInstaller {
$this->db->clearFlag( DBO_TRX );
$this->db->commit( __METHOD__ );
}
+
return $status;
}
@@ -173,9 +174,10 @@ abstract class DatabaseInstaller {
}
$this->db->selectDB( $this->getVar( 'wgDBname' ) );
- if( $this->db->tableExists( 'archive', __METHOD__ ) ) {
+ if ( $this->db->tableExists( 'archive', __METHOD__ ) ) {
$status->warning( 'config-install-tables-exist' );
$this->enableLB();
+
return $status;
}
@@ -183,7 +185,7 @@ abstract class DatabaseInstaller {
$this->db->begin( __METHOD__ );
$error = $this->db->sourceFile( $this->db->getSchemaPath() );
- if( $error !== true ) {
+ if ( $error !== true ) {
$this->db->reportQueryError( $error, 0, '', __METHOD__ );
$this->db->rollback( __METHOD__ );
$status->fatal( 'config-install-tables-failed', $error );
@@ -191,9 +193,10 @@ abstract class DatabaseInstaller {
$this->db->commit( __METHOD__ );
}
// Resume normal operations
- if( $status->isOk() ) {
+ if ( $status->isOk() ) {
$this->enableLB();
}
+
return $status;
}
@@ -218,7 +221,7 @@ abstract class DatabaseInstaller {
*
* @return String
*/
- public abstract function getLocalSettings();
+ abstract public function getLocalSettings();
/**
* Override this to provide DBMS-specific schema variables, to be
@@ -240,7 +243,7 @@ abstract class DatabaseInstaller {
if ( $status->isOK() ) {
$status->value->setSchemaVars( $this->getSchemaVars() );
} else {
- throw new MWException( __METHOD__.': unexpected DB connection error' );
+ throw new MWException( __METHOD__ . ': unexpected DB connection error' );
}
}
@@ -252,7 +255,7 @@ abstract class DatabaseInstaller {
public function enableLB() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
- throw new MWException( __METHOD__.': unexpected DB connection error' );
+ throw new MWException( __METHOD__ . ': unexpected DB connection error' );
}
LBFactory::setInstance( new LBFactory_Single( array(
'connection' => $status->value ) ) );
@@ -269,15 +272,17 @@ abstract class DatabaseInstaller {
$ret = true;
ob_start( array( $this, 'outputHandler' ) );
+ $up = DatabaseUpdater::newForDB( $this->db );
try {
- $up = DatabaseUpdater::newForDB( $this->db );
$up->doUpdates();
} catch ( MWException $e ) {
echo "\nAn error occurred:\n";
echo $e->getText();
$ret = false;
}
+ $up->purgeCache();
ob_end_flush();
+
return $ret;
}
@@ -287,14 +292,12 @@ abstract class DatabaseInstaller {
* long after the constructor. Helpful for things like modifying setup steps :)
*/
public function preInstall() {
-
}
/**
* Allow DB installers a chance to make checks before upgrade.
*/
public function preUpgrade() {
-
}
/**
@@ -318,15 +321,11 @@ abstract class DatabaseInstaller {
* Convenience function.
* Check if a named extension is present.
*
- * @see wfDl
* @param $name
* @return bool
*/
protected static function checkExtension( $name ) {
- wfSuppressWarnings();
- $compiled = wfDl( $name );
- wfRestoreWarnings();
- return $compiled;
+ return extension_loaded( $name );
}
/**
@@ -334,6 +333,8 @@ abstract class DatabaseInstaller {
* @return String
*/
public function getReadableName() {
+ // Messages: config-type-mysql, config-type-postgres, config-type-sqlite,
+ // config-type-oracle
return wfMessage( 'config-type-' . $this->getName() )->text();
}
@@ -368,6 +369,7 @@ abstract class DatabaseInstaller {
} elseif ( isset( $internal[$var] ) ) {
$default = $internal[$var];
}
+
return $this->parent->getVar( $var, $default );
}
@@ -395,6 +397,7 @@ abstract class DatabaseInstaller {
if ( !isset( $attribs ) ) {
$attribs = array();
}
+
return $this->parent->getTextBox( array(
'var' => $var,
'label' => $label,
@@ -421,6 +424,7 @@ abstract class DatabaseInstaller {
if ( !isset( $attribs ) ) {
$attribs = array();
}
+
return $this->parent->getPasswordBox( array(
'var' => $var,
'label' => $label,
@@ -439,6 +443,7 @@ abstract class DatabaseInstaller {
public function getCheckBox( $var, $label, $attribs = array(), $helpData = "" ) {
$name = $this->getName() . '_' . $var;
$value = $this->getVar( $var );
+
return $this->parent->getCheckBox( array(
'var' => $var,
'label' => $label,
@@ -446,7 +451,7 @@ abstract class DatabaseInstaller {
'controlName' => $name,
'value' => $value,
'help' => $helpData
- ));
+ ) );
}
/**
@@ -465,6 +470,7 @@ abstract class DatabaseInstaller {
public function getRadioSet( $params ) {
$params['controlName'] = $this->getName() . '_' . $params['var'];
$params['value'] = $this->getVar( $params['var'] );
+
return $this->parent->getRadioSet( $params );
}
@@ -498,7 +504,9 @@ abstract class DatabaseInstaller {
if ( !$this->db->selectDB( $this->getVar( 'wgDBname' ) ) ) {
return false;
}
- return $this->db->tableExists( 'cur', __METHOD__ ) || $this->db->tableExists( 'revision', __METHOD__ );
+
+ return $this->db->tableExists( 'cur', __METHOD__ ) ||
+ $this->db->tableExists( 'revision', __METHOD__ );
}
/**
@@ -507,11 +515,20 @@ abstract class DatabaseInstaller {
* @return String
*/
public function getInstallUserBox() {
- return
- Html::openElement( 'fieldset' ) .
+ return Html::openElement( 'fieldset' ) .
Html::element( 'legend', array(), wfMessage( 'config-db-install-account' )->text() ) .
- $this->getTextBox( '_InstallUser', 'config-db-username', array( 'dir' => 'ltr' ), $this->parent->getHelpBox( 'config-db-install-username' ) ) .
- $this->getPasswordBox( '_InstallPassword', 'config-db-password', array( 'dir' => 'ltr' ), $this->parent->getHelpBox( 'config-db-install-password' ) ) .
+ $this->getTextBox(
+ '_InstallUser',
+ 'config-db-username',
+ array( 'dir' => 'ltr' ),
+ $this->parent->getHelpBox( 'config-db-install-username' )
+ ) .
+ $this->getPasswordBox(
+ '_InstallPassword',
+ 'config-db-password',
+ array( 'dir' => 'ltr' ),
+ $this->parent->getHelpBox( 'config-db-install-password' )
+ ) .
Html::closeElement( 'fieldset' );
}
@@ -521,12 +538,13 @@ abstract class DatabaseInstaller {
*/
public function submitInstallUserBox() {
$this->setVarsFromRequest( array( '_InstallUser', '_InstallPassword' ) );
+
return Status::newGood();
}
/**
* Get a standard web-user fieldset
- * @param $noCreateMsg String: Message to display instead of the creation checkbox.
+ * @param string $noCreateMsg Message to display instead of the creation checkbox.
* Set this to false to show a creation checkbox.
*
* @return String
@@ -549,6 +567,7 @@ abstract class DatabaseInstaller {
$s .= $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create' );
}
$s .= Html::closeElement( 'div' ) . Html::closeElement( 'fieldset' );
+
return $s;
}
@@ -567,7 +586,7 @@ abstract class DatabaseInstaller {
$this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
}
- if( $this->getVar( '_CreateDBAccount' ) && strval( $this->getVar( 'wgDBpassword' ) ) == '' ) {
+ if ( $this->getVar( '_CreateDBAccount' ) && strval( $this->getVar( 'wgDBpassword' ) ) == '' ) {
return Status::newFatal( 'config-db-password-empty', $this->getVar( 'wgDBuser' ) );
}
@@ -586,8 +605,9 @@ abstract class DatabaseInstaller {
}
$this->db->selectDB( $this->getVar( 'wgDBname' ) );
- if( $this->db->selectRow( 'interwiki', '*', array(), __METHOD__ ) ) {
+ if ( $this->db->selectRow( 'interwiki', '*', array(), __METHOD__ ) ) {
$status->warning( 'config-install-interwiki-exists' );
+
return $status;
}
global $IP;
@@ -599,9 +619,11 @@ abstract class DatabaseInstaller {
if ( !$rows ) {
return Status::newFatal( 'config-install-interwiki-list' );
}
- foreach( $rows as $row ) {
+ foreach ( $rows as $row ) {
$row = preg_replace( '/^\s*([^#]*?)\s*(#.*)?$/', '\\1', $row ); // strip comments - whee
- if ( $row == "" ) continue;
+ if ( $row == "" ) {
+ continue;
+ }
$row .= "||";
$interwikis[] = array_combine(
array( 'iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid' ),
@@ -609,6 +631,7 @@ abstract class DatabaseInstaller {
);
}
$this->db->insert( 'interwiki', $interwikis, __METHOD__ );
+
return Status::newGood();
}