Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / installer / SqliteInstaller.php
blob29339b712a93b565811d3cdae60190083fb91759
1 <?php
3 /**
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
21 * @file
22 * @ingroup Installer
25 namespace MediaWiki\Installer;
27 use MediaWiki\MediaWikiServices;
28 use MediaWiki\Status\Status;
29 use Wikimedia\Rdbms\DatabaseSqlite;
30 use Wikimedia\Rdbms\DBConnectionError;
32 /**
33 * Class for setting up the MediaWiki database using SQLLite.
35 * @ingroup Installer
36 * @since 1.17
38 class SqliteInstaller extends DatabaseInstaller {
40 /** @inheritDoc */
41 public static $minimumVersion = '3.8.0';
42 /** @inheritDoc */
43 protected static $notMinimumVersionMessage = 'config-outdated-sqlite';
45 /**
46 * @var DatabaseSqlite
48 public $db;
50 /** @inheritDoc */
51 protected $globalNames = [
52 'wgDBname',
53 'wgSQLiteDataDir',
56 public function getName() {
57 return 'sqlite';
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 );
72 /**
73 * @return Status
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' );
84 return $result;
87 public function getGlobalDefaults() {
88 global $IP;
89 $defaults = parent::getGlobalDefaults();
90 if ( !empty( $_SERVER['DOCUMENT_ROOT'] ) ) {
91 $path = dirname( $_SERVER['DOCUMENT_ROOT'] );
92 } else {
93 // We use $IP when unable to get $_SERVER['DOCUMENT_ROOT']
94 $path = $IP;
96 $defaults['wgSQLiteDataDir'] = str_replace(
97 [ '/', '\\' ],
98 DIRECTORY_SEPARATOR,
99 $path . '/data'
101 return $defaults;
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' );
118 return $status;
121 try {
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() );
130 return $status;
134 * @return string
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',
146 'server' => [
147 'type' => 'sqlite',
148 'dbname' => 'wikicache',
149 'tablePrefix' => '',
150 'variables' => [ 'synchronous' => 'NORMAL' ],
151 'dbDirectory' => \$wgSQLiteDataDir,
152 'trxMode' => 'IMMEDIATE',
153 'flags' => 0
156 \$wgLocalisationCacheConf['storeServer'] = [
157 'type' => 'sqlite',
158 'dbname' => \"{\$wgDBname}_l10n_cache\",
159 'tablePrefix' => '',
160 'variables' => [ 'synchronous' => 'NORMAL' ],
161 'dbDirectory' => \$wgSQLiteDataDir,
162 'trxMode' => 'IMMEDIATE',
163 'flags' => 0
165 \$wgJobTypeConf['default'] = [
166 'class' => 'JobQueueDB',
167 'claimTTL' => 3600,
168 'server' => [
169 'type' => 'sqlite',
170 'dbname' => \"{\$wgDBname}_jobqueue\",
171 'tablePrefix' => '',
172 'variables' => [ 'synchronous' => 'NORMAL' ],
173 'dbDirectory' => \$wgSQLiteDataDir,
174 'trxMode' => 'IMMEDIATE',
175 'flags' => 0