wiki.techinc.nl/includes/installer/DatabaseInstaller.php

608 lines
15 KiB
PHP
Raw Normal View History

<?php
/**
* DBMS-specific installation helper.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Installer
*/
namespace MediaWiki\Installer;
use Exception;
use MediaWiki\Status\Status;
use MWException;
use MWLBFactory;
use RuntimeException;
use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\DatabaseDomain;
use Wikimedia\Rdbms\DBConnectionError;
use Wikimedia\Rdbms\DBExpectedError;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\LBFactorySingle;
/**
* Base class for DBMS-specific installation helper classes.
*
* @ingroup Installer
2010-07-29 18:36:39 +00:00
* @since 1.17
*/
abstract class DatabaseInstaller {
2010-12-16 11:20:39 +00:00
2010-07-20 11:17:36 +00:00
/**
* The Installer object.
*
* @var Installer
2010-07-20 11:17:36 +00:00
*/
2010-07-20 11:00:51 +00:00
public $parent;
/**
* @var string Set by subclasses
*/
public static $minimumVersion;
/**
* @var string Set by subclasses
*/
protected static $notMinimumVersionMessage;
2010-07-20 11:17:36 +00:00
/**
* The database connection.
*
* @var Database
2010-07-20 11:17:36 +00:00
*/
public $db = null;
2010-07-20 11:17:36 +00:00
/**
* Internal variables for installation.
*
2010-07-20 11:17:36 +00:00
* @var array
*/
protected $internalDefaults = [];
2010-07-20 11:17:36 +00:00
/**
* Array of MW configuration globals this class uses.
*
2010-07-20 11:17:36 +00:00
* @var array
*/
protected $globalNames = [];
/**
* Whether the provided version meets the necessary requirements for this type
*
* @param IDatabase $conn
* @return Status
* @since 1.30
*/
public static function meetsMinimumRequirement( IDatabase $conn ) {
$serverVersion = $conn->getServerVersion();
if ( version_compare( $serverVersion, static::$minimumVersion ) < 0 ) {
return Status::newFatal(
static::$notMinimumVersionMessage, static::$minimumVersion, $serverVersion
);
}
return Status::newGood();
}
/**
2010-07-20 11:00:51 +00:00
* Return the internal name, e.g. 'mysql', or 'sqlite'.
*/
abstract public function getName();
/**
* @return bool Returns true if the client library is compiled in.
*/
abstract public function isCompiled();
/**
* Checks for installation prerequisites other than those checked by isCompiled()
* @since 1.19
* @return Status
*/
public function checkPrerequisites() {
return Status::newGood();
}
/**
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
* Open a connection to the database using the administrative user/password
2011-02-12 04:06:22 +00:00
* currently defined in the session, without any caching. Returns a status
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
* object. On success, the status object will contain a Database object in
* its value member.
*
* @return ConnectionStatus
*/
abstract public function openConnection();
2010-12-16 11:20:39 +00:00
/**
* Create the database and return a Status object indicating success or
* failure.
*
* @return Status
*/
abstract public function setupDatabase();
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
/**
* Connect to the database using the administrative user/password currently
2011-02-12 04:06:22 +00:00
* defined in the session. Returns a status object. On success, the status
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
* object will contain a Database object in its value member.
2011-02-12 04:06:22 +00:00
*
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
* This will return a cached connection if one is available.
*
* @return ConnectionStatus
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
*/
PostgreSQL install fixes: * Made PG throw a DBQueryError when it gets a query error, instead of DBUnexpectedError. Apparently this mistake goes back to r14625, when exceptions were first introduced. Did it by removing reportQueryError(), the DatabaseBase version works fine. * Fixed several places where there was an attempt to check for a query error by checking if the result of query() was false. This never worked. Used try/catch instead. * Made the DBConnectionError messages go on one line so that they don't mess up the formatting in the installer. * In DatabasePostgres::selectDB(), only disconnect and reconnect if the DB name is actually changing. * Made DatabasePostgres::schemaExists() less weird and scary. * Added DatabasePostgres::roleExists() for use by the installer. * Removed the PostgreSQL-specific hack to make _InstallUser have a default other than "root". Made _InstallUser into a proper DBMS-specific internal variable instead, since every DBMS we support so far needs a different default. * Removed the $dbName parameters from openConnection/getConnection, and got rid of $this->useAdmin. Implemented a more sophisticated caching scheme instead. Partial revert of r89389 and r81440. * When connecting as the install user before DB creation, and when testing the web user's credentials, try a few different database names and use whichever one works. * Instead of connecting as the web user to create tables, I used SET ROLE. It seems cleaner and more like what the other DBMSes do during installation. "SET ROLE wikiuser" requires the same privileges as "CREATE SCHEMA ... AUTHORIZATION wikiuser", so it's unlikely to break anything. * In the area of web account creation, fixed various minor logic errors and introduced more informative error messages at the submit stage, pre-install. Show a helpful error message if the web user exists already and the install user can't do the relevant SET ROLE. * Split schema creation out to a separate install step. * When creating an account as a non-superuser, add the administrative account to the new account's group. This is necessary to avoid a fatal error during installation (bug 28845). * Removed code which alters an existing web user to have appropriate search paths and permissions. This may break other apps and is not necessary. As in other DBMSes, If the web user exists, it is the responsibility of the sysadmin to ensure that it has appropriate permissions. * Rewrote setupPLpgSQL() to use the query builder functions.
2011-06-10 11:32:57 +00:00
public function getConnection() {
if ( $this->db ) {
return new ConnectionStatus( $this->db );
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
}
2011-06-03 03:41:11 +00:00
PostgreSQL install fixes: * Made PG throw a DBQueryError when it gets a query error, instead of DBUnexpectedError. Apparently this mistake goes back to r14625, when exceptions were first introduced. Did it by removing reportQueryError(), the DatabaseBase version works fine. * Fixed several places where there was an attempt to check for a query error by checking if the result of query() was false. This never worked. Used try/catch instead. * Made the DBConnectionError messages go on one line so that they don't mess up the formatting in the installer. * In DatabasePostgres::selectDB(), only disconnect and reconnect if the DB name is actually changing. * Made DatabasePostgres::schemaExists() less weird and scary. * Added DatabasePostgres::roleExists() for use by the installer. * Removed the PostgreSQL-specific hack to make _InstallUser have a default other than "root". Made _InstallUser into a proper DBMS-specific internal variable instead, since every DBMS we support so far needs a different default. * Removed the $dbName parameters from openConnection/getConnection, and got rid of $this->useAdmin. Implemented a more sophisticated caching scheme instead. Partial revert of r89389 and r81440. * When connecting as the install user before DB creation, and when testing the web user's credentials, try a few different database names and use whichever one works. * Instead of connecting as the web user to create tables, I used SET ROLE. It seems cleaner and more like what the other DBMSes do during installation. "SET ROLE wikiuser" requires the same privileges as "CREATE SCHEMA ... AUTHORIZATION wikiuser", so it's unlikely to break anything. * In the area of web account creation, fixed various minor logic errors and introduced more informative error messages at the submit stage, pre-install. Show a helpful error message if the web user exists already and the install user can't do the relevant SET ROLE. * Split schema creation out to a separate install step. * When creating an account as a non-superuser, add the administrative account to the new account's group. This is necessary to avoid a fatal error during installation (bug 28845). * Removed code which alters an existing web user to have appropriate search paths and permissions. This may break other apps and is not necessary. As in other DBMSes, If the web user exists, it is the responsibility of the sysadmin to ensure that it has appropriate permissions. * Rewrote setupPLpgSQL() to use the query builder functions.
2011-06-10 11:32:57 +00:00
$status = $this->openConnection();
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
if ( $status->isOK() ) {
$this->db = $status->value;
// Enable autocommit
$this->db->clearFlag( DBO_TRX );
$this->db->commit( __METHOD__ );
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
}
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
return $status;
}
/**
* Apply a SQL source file to the database as part of running an installation step.
*
* @param string $sourceFileMethod
* @param string $stepName
* @param string|false $tableThatMustNotExist
* @return Status
*/
private function stepApplySourceFile(
$sourceFileMethod,
$stepName,
$tableThatMustNotExist = false
) {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$this->selectDatabase( $this->db, $this->getVar( 'wgDBname' ) );
if ( $tableThatMustNotExist && $this->db->tableExists( $tableThatMustNotExist, __METHOD__ ) ) {
$status->warning( "config-$stepName-tables-exist" );
$this->enableLB();
return $status;
}
$this->db->setFlag( DBO_DDLMODE );
$this->db->begin( __METHOD__ );
$error = $this->db->sourceFile(
call_user_func( [ $this, $sourceFileMethod ], $this->db )
);
if ( $error !== true ) {
2011-01-02 19:04:23 +00:00
$this->db->reportQueryError( $error, 0, '', __METHOD__ );
$this->db->rollback( __METHOD__ );
$status->fatal( "config-$stepName-tables-failed", $error );
} else {
$this->db->commit( __METHOD__ );
}
// Resume normal operations
if ( $status->isOK() ) {
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
$this->enableLB();
}
return $status;
}
/**
* Create database tables from scratch from the automatically generated file
*
* @return Status
*/
public function createTables() {
return $this->stepApplySourceFile( 'getGeneratedSchemaPath', 'install', 'archive' );
}
/**
* Create database tables from scratch.
*
* @return Status
*/
public function createManualTables() {
return $this->stepApplySourceFile( 'getSchemaPath', 'install-manual' );
}
/**
* Insert update keys into table to prevent running unneeded updates.
*
* @return Status
*/
public function insertUpdateKeys() {
return $this->stepApplySourceFile( 'getUpdateKeysPath', 'updates', false );
}
/**
* Return a path to the DBMS-specific SQL file if it exists,
* otherwise default SQL file
*
* @param IDatabase $db
* @param string $filename
* @return string
*/
private function getSqlFilePath( $db, $filename ) {
global $IP;
$dbmsSpecificFilePath = "$IP/maintenance/" . $db->getType() . "/$filename";
if ( file_exists( $dbmsSpecificFilePath ) ) {
return $dbmsSpecificFilePath;
} else {
return "$IP/maintenance/$filename";
}
}
/**
* Return a path to the DBMS-specific schema file,
* otherwise default to tables.sql
*
* @param IDatabase $db
* @return string
*/
public function getSchemaPath( $db ) {
return $this->getSqlFilePath( $db, 'tables.sql' );
}
/**
* Return a path to the DBMS-specific automatically generated schema file.
*
* @param IDatabase $db
* @return string
*/
public function getGeneratedSchemaPath( $db ) {
return $this->getSqlFilePath( $db, 'tables-generated.sql' );
}
/**
* Return a path to the DBMS-specific update key file,
* otherwise default to update-keys.sql
*
* @param IDatabase $db
* @return string
*/
public function getUpdateKeysPath( $db ) {
return $this->getSqlFilePath( $db, 'update-keys.sql' );
}
/**
* Create the tables for each extension the user enabled
* @return Status
*/
public function createExtensionTables() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$this->enableLB();
// Now run updates to create tables for old extensions
$updater = DatabaseUpdater::newForDB( $this->db );
$updater->setAutoExtensionHookContainer( $this->parent->getAutoExtensionHookContainer() );
$updater->doUpdates( [ 'extensions' ] );
return $status;
}
2010-07-20 11:17:36 +00:00
/**
* Get the DBMS-specific options for LocalSettings.php generation.
*
* @return string
2010-07-20 11:17:36 +00:00
*/
abstract public function getLocalSettings();
2010-12-16 11:20:39 +00:00
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
/**
2011-02-12 04:06:22 +00:00
* Override this to provide DBMS-specific schema variables, to be
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
* substituted into tables.sql and other schema files.
2012-02-09 21:35:05 +00:00
* @return array
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
*/
public function getSchemaVars() {
return [];
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
}
/**
* Set appropriate schema variables in the current database connection.
*
* This should be called after any request data has been imported, but before
* any write operations to the database.
*/
public function setupSchemaVars() {
$status = $this->getConnection();
if ( $status->isOK() ) {
$status->getDB()->setSchemaVars( $this->getSchemaVars() );
} else {
$msg = __METHOD__ . ': unexpected error while establishing'
. ' a database connection with message: '
. $status->getMessage()->plain();
throw new RuntimeException( $msg );
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
}
}
/**
* Set up LBFactory so that getPrimaryDatabase() etc. works.
2011-02-12 04:06:22 +00:00
* We set up a special LBFactory instance which returns the current
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
* installer connection.
*/
public function enableLB() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
throw new RuntimeException( __METHOD__ . ': unexpected DB connection error' );
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
}
$connection = $status->value;
$virtualDomains = array_merge(
$this->parent->getVirtualDomains(),
MWLBFactory::CORE_VIRTUAL_DOMAINS
);
$this->parent->resetMediaWikiServices( null, [
'DBLoadBalancerFactory' => static function () use ( $virtualDomains, $connection ) {
return LBFactorySingle::newFromConnection(
$connection,
[ 'virtualDomains' => $virtualDomains ]
);
}
] );
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
}
/**
* Perform database upgrades
*
* @return bool
* @suppress SecurityCheck-XSS Escaping provided by $this->outputHandler
*/
public function doUpgrade() {
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
$this->setupSchemaVars();
$this->enableLB();
$ret = true;
ob_start( [ $this, 'outputHandler' ] );
$up = DatabaseUpdater::newForDB( $this->db );
try {
$up->doUpdates();
$up->purgeCache();
} catch ( MWException $e ) {
// TODO: Remove special casing in favour of MWExceptionRenderer
echo "\nAn error occurred:\n";
echo $e->getText();
$ret = false;
} catch ( Exception $e ) {
echo "\nAn error occurred:\n";
echo $e->getMessage();
$ret = false;
}
ob_end_flush();
return $ret;
}
2010-12-16 11:20:39 +00:00
2010-07-20 11:17:36 +00:00
/**
* Allow DB installers a chance to make last-minute changes before installation
* occurs. This happens before setupDatabase() or createTables() is called, but
* 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() {
}
2010-07-20 11:17:36 +00:00
/**
* Get an array of MW configuration globals that will be configured by this class.
2012-02-09 21:35:05 +00:00
* @return array
2010-07-20 11:17:36 +00:00
*/
public function getGlobalNames() {
return $this->globalNames;
}
/**
* Construct and initialise parent.
* This is typically only called from Installer::getDBInstaller()
* @param WebInstaller $parent
*/
2010-07-20 11:00:51 +00:00
public function __construct( $parent ) {
$this->parent = $parent;
}
/**
2010-07-20 11:17:36 +00:00
* Convenience function.
* Check if a named extension is present.
*
* @param string $name
* @return bool
*/
protected static function checkExtension( $name ) {
return extension_loaded( $name );
}
/**
2010-07-20 11:17:36 +00:00
* Get the internationalised name for this DBMS.
* @return string
*/
2010-07-20 11:00:51 +00:00
public function getReadableName() {
// Messages: config-type-mysql, config-type-postgres, config-type-sqlite
return wfMessage( 'config-type-' . $this->getName() )->text();
}
2010-12-16 11:20:39 +00:00
/**
* Get a name=>value map of MW configuration globals for the default values.
2012-02-09 21:35:05 +00:00
* @return array
* @return-taint none
*/
2010-07-20 11:00:51 +00:00
public function getGlobalDefaults() {
$defaults = [];
foreach ( $this->getGlobalNames() as $var ) {
if ( isset( $GLOBALS[$var] ) ) {
$defaults[$var] = $GLOBALS[$var];
}
}
return $defaults;
}
/**
2010-07-20 11:17:36 +00:00
* Get a name=>value map of internal variables used during installation.
2012-02-09 21:35:05 +00:00
* @return array
*/
public function getInternalDefaults() {
return $this->internalDefaults;
}
/**
2010-07-20 11:17:36 +00:00
* Get a variable, taking local defaults into account.
* @param string $var
* @param mixed|null $default
* @return mixed
*/
2010-07-20 11:00:51 +00:00
public function getVar( $var, $default = null ) {
$defaults = $this->getGlobalDefaults();
$internal = $this->getInternalDefaults();
if ( isset( $defaults[$var] ) ) {
$default = $defaults[$var];
} elseif ( isset( $internal[$var] ) ) {
$default = $internal[$var];
}
return $this->parent->getVar( $var, $default );
}
/**
* Convenience alias for $this->parent->setVar()
* @param string $name
* @param mixed $value
*/
2010-07-20 11:00:51 +00:00
public function setVar( $name, $value ) {
$this->parent->setVar( $name, $value );
}
abstract public function getConnectForm( WebInstaller $webInstaller ): DatabaseConnectForm;
abstract public function getSettingsForm( WebInstaller $webInstaller ): DatabaseSettingsForm;
/**
* Determine whether an existing installation of MediaWiki is present in
* the configured administrative connection. Returns true if there is
* such a wiki, false if the database doesn't exist.
*
* Traditionally, this is done by testing for the existence of either
* the revision table or the cur table.
*
* @return bool
*/
2010-07-20 11:00:51 +00:00
public function needsUpgrade() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return false;
}
try {
$this->selectDatabase( $this->db, $this->getVar( 'wgDBname' ) );
} catch ( DBConnectionError $e ) {
// Don't catch DBConnectionError
throw $e;
} catch ( DBExpectedError $e ) {
return false;
}
return $this->db->tableExists( 'cur', __METHOD__ ) ||
$this->db->tableExists( 'revision', __METHOD__ );
}
/**
* Common function for databases that don't understand the MySQLish syntax of interwiki.list.
2011-02-03 23:09:42 +00:00
*
* @return Status
*/
public function populateInterwikiTable() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$this->selectDatabase( $this->db, $this->getVar( 'wgDBname' ) );
$row = $this->db->newSelectQueryBuilder()
->select( '1' )
->from( 'interwiki' )
->caller( __METHOD__ )->fetchRow();
if ( $row ) {
$status->warning( 'config-install-interwiki-exists' );
return $status;
}
global $IP;
AtEase::suppressWarnings();
$rows = file( "$IP/maintenance/interwiki.list",
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
AtEase::restoreWarnings();
if ( !$rows ) {
return Status::newFatal( 'config-install-interwiki-list' );
}
$insert = $this->db->newInsertQueryBuilder()
->insertInto( 'interwiki' );
foreach ( $rows as $row ) {
$row = preg_replace( '/^\s*([^#]*?)\s*(#.*)?$/', '\\1', $row ); // strip comments - whee
if ( $row == "" ) {
continue;
}
$row .= "|";
$insert->row(
array_combine(
[ 'iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid' ],
explode( '|', $row )
)
);
}
$insert->caller( __METHOD__ )->execute();
return Status::newGood();
}
2010-09-01 18:16:05 +00:00
public function outputHandler( $string ) {
return htmlspecialchars( $string );
}
/**
* @param Database $conn
* @param string $database
* @return bool
* @since 1.39
*/
protected function selectDatabase( Database $conn, string $database ) {
$schema = $conn->dbSchema();
$prefix = $conn->tablePrefix();
$conn->selectDomain( new DatabaseDomain(
$database,
// DatabaseDomain uses null for unspecified schemas
( $schema !== '' ) ? $schema : null,
$prefix
) );
return true;
}
2010-09-01 18:16:05 +00:00
}