Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
SqliteInstaller | |
0.00% |
0 / 38 |
|
0.00% |
0 / 8 |
156 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isCompiled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getConnectForm | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSettingsForm | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkPrerequisites | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getGlobalDefaults | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
openConnection | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
getLocalSettings | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Sqlite-specific installer. |
5 | * |
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. |
10 | * |
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. |
15 | * |
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 |
20 | * |
21 | * @file |
22 | * @ingroup Installer |
23 | */ |
24 | |
25 | namespace MediaWiki\Installer; |
26 | |
27 | use MediaWiki\MediaWikiServices; |
28 | use MediaWiki\Status\Status; |
29 | use Wikimedia\Rdbms\DatabaseSqlite; |
30 | use Wikimedia\Rdbms\DBConnectionError; |
31 | |
32 | /** |
33 | * Class for setting up the MediaWiki database using SQLLite. |
34 | * |
35 | * @ingroup Installer |
36 | * @since 1.17 |
37 | */ |
38 | class SqliteInstaller extends DatabaseInstaller { |
39 | |
40 | /** @inheritDoc */ |
41 | public static $minimumVersion = '3.24.0'; |
42 | /** @inheritDoc */ |
43 | protected static $notMinimumVersionMessage = 'config-outdated-sqlite'; |
44 | |
45 | /** |
46 | * @var DatabaseSqlite |
47 | */ |
48 | public $db; |
49 | |
50 | /** @inheritDoc */ |
51 | protected $globalNames = [ |
52 | 'wgDBname', |
53 | 'wgSQLiteDataDir', |
54 | ]; |
55 | |
56 | public function getName() { |
57 | return 'sqlite'; |
58 | } |
59 | |
60 | public function isCompiled() { |
61 | return self::checkExtension( 'pdo_sqlite' ); |
62 | } |
63 | |
64 | public function getConnectForm( WebInstaller $webInstaller ): DatabaseConnectForm { |
65 | return new SqliteConnectForm( $webInstaller, $this ); |
66 | } |
67 | |
68 | public function getSettingsForm( WebInstaller $webInstaller ): DatabaseSettingsForm { |
69 | return new DatabaseSettingsForm( $webInstaller, $this ); |
70 | } |
71 | |
72 | /** |
73 | * @return Status |
74 | */ |
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' ); |
82 | } |
83 | |
84 | return $result; |
85 | } |
86 | |
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; |
95 | } |
96 | $defaults['wgSQLiteDataDir'] = str_replace( |
97 | [ '/', '\\' ], |
98 | DIRECTORY_SEPARATOR, |
99 | $path . '/data' |
100 | ); |
101 | return $defaults; |
102 | } |
103 | |
104 | /** |
105 | * @param string $type |
106 | * @return ConnectionStatus |
107 | */ |
108 | public function openConnection( string $type ) { |
109 | $status = new ConnectionStatus; |
110 | $dir = $this->getVar( 'wgSQLiteDataDir' ); |
111 | $dbName = $this->getVar( 'wgDBname' ); |
112 | |
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; |
119 | } |
120 | |
121 | try { |
122 | $db = MediaWikiServices::getInstance()->getDatabaseFactory()->create( |
123 | 'sqlite', [ 'dbname' => $dbName, 'dbDirectory' => $dir ] |
124 | ); |
125 | $status->setDB( $db ); |
126 | } catch ( DBConnectionError $e ) { |
127 | $status->fatal( 'config-sqlite-connection-error', $e->getMessage() ); |
128 | } |
129 | |
130 | return $status; |
131 | } |
132 | |
133 | /** |
134 | * @return string |
135 | */ |
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 |
154 | ] |
155 | ]; |
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 |
164 | ]; |
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 |
176 | ] |
177 | ]; |
178 | "; |
179 | } |
180 | } |