4 * Sqlite-specific installer.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
25 namespace MediaWiki\Installer
;
27 use MediaWiki\MediaWikiServices
;
28 use MediaWiki\Status\Status
;
29 use Wikimedia\Rdbms\DatabaseSqlite
;
30 use Wikimedia\Rdbms\DBConnectionError
;
33 * Class for setting up the MediaWiki database using SQLLite.
38 class SqliteInstaller
extends DatabaseInstaller
{
41 public static $minimumVersion = '3.8.0';
43 protected static $notMinimumVersionMessage = 'config-outdated-sqlite';
51 protected $globalNames = [
56 public function getName() {
60 public function isCompiled() {
61 return self
::checkExtension( 'pdo_sqlite' );
64 public function getConnectForm( WebInstaller
$webInstaller ): DatabaseConnectForm
{
65 return new SqliteConnectForm( $webInstaller, $this );
68 public function getSettingsForm( WebInstaller
$webInstaller ): DatabaseSettingsForm
{
69 return new DatabaseSettingsForm( $webInstaller, $this );
75 public function checkPrerequisites() {
76 // Bail out if SQLite is too old
77 $db = DatabaseSqlite
::newStandaloneInstance( ':memory:' );
78 $result = static::meetsMinimumRequirement( $db );
79 // Check for FTS3 full-text search module
80 if ( DatabaseSqlite
::getFulltextSearchModule() != 'FTS3' ) {
81 $result->warning( 'config-no-fts3' );
87 public function getGlobalDefaults() {
89 $defaults = parent
::getGlobalDefaults();
90 if ( !empty( $_SERVER['DOCUMENT_ROOT'] ) ) {
91 $path = dirname( $_SERVER['DOCUMENT_ROOT'] );
93 // We use $IP when unable to get $_SERVER['DOCUMENT_ROOT']
96 $defaults['wgSQLiteDataDir'] = str_replace(
105 * @param string $type
106 * @return ConnectionStatus
108 public function openConnection( string $type ) {
109 $status = new ConnectionStatus
;
110 $dir = $this->getVar( 'wgSQLiteDataDir' );
111 $dbName = $this->getVar( 'wgDBname' );
113 // Don't implicitly create the file
114 $file = DatabaseSqlite
::generateFileName( $dir, $dbName );
115 if ( !file_exists( $file ) ) {
116 $status->fatal( 'config-sqlite-connection-error',
117 'file does not exist' );
122 $db = MediaWikiServices
::getInstance()->getDatabaseFactory()->create(
123 'sqlite', [ 'dbname' => $dbName, 'dbDirectory' => $dir ]
125 $status->setDB( $db );
126 } catch ( DBConnectionError
$e ) {
127 $status->fatal( 'config-sqlite-connection-error', $e->getMessage() );
136 public function getLocalSettings() {
137 $dir = LocalSettingsGenerator
::escapePhpString( $this->getVar( 'wgSQLiteDataDir' ) );
138 // These tables have frequent writes and are thus split off from the main one.
139 // Since the code using these tables only uses transactions for writes, then set
140 // them to using BEGIN IMMEDIATE. This avoids frequent lock errors on the first write action.
141 return "# SQLite-specific settings
142 \$wgSQLiteDataDir = \"{$dir}\";
143 \$wgObjectCaches[CACHE_DB] = [
144 'class' => SqlBagOStuff::class,
145 'loggroup' => 'SQLBagOStuff',
148 'dbname' => 'wikicache',
150 'variables' => [ 'synchronous' => 'NORMAL' ],
151 'dbDirectory' => \$wgSQLiteDataDir,
152 'trxMode' => 'IMMEDIATE',
156 \$wgLocalisationCacheConf['storeServer'] = [
158 'dbname' => \"{\$wgDBname}_l10n_cache\",
160 'variables' => [ 'synchronous' => 'NORMAL' ],
161 'dbDirectory' => \$wgSQLiteDataDir,
162 'trxMode' => 'IMMEDIATE',
165 \$wgJobTypeConf['default'] = [
166 'class' => 'JobQueueDB',
170 'dbname' => \"{\$wgDBname}_jobqueue\",
172 'variables' => [ 'synchronous' => 'NORMAL' ],
173 'dbDirectory' => \$wgSQLiteDataDir,
174 'trxMode' => 'IMMEDIATE',