62 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
65 if ( DatabaseSqlite::getFulltextSearchModule() !=
'FTS3' ) {
66 $result->warning(
'config-no-fts3' );
74 $defaults = parent::getGlobalDefaults();
75 if ( !empty( $_SERVER[
'DOCUMENT_ROOT'] ) ) {
76 $path = dirname( $_SERVER[
'DOCUMENT_ROOT'] );
81 $defaults[
'wgSQLiteDataDir'] = str_replace(
92 'config-sqlite-dir', [],
93 $this->parent->getHelpBox(
'config-sqlite-dir-help' )
99 $this->parent->getHelpBox(
'config-sqlite-name-help' )
125 # Try realpath() if the directory already exists
128 if ( $result->isOK() ) {
129 # Try expanding again in case we've just created it
131 $this->
setVar(
'wgSQLiteDataDir', $dir );
133 # Table prefix is not used on SQLite, keep it empty
134 $this->
setVar(
'wgDBprefix',
'' );
145 if ( is_dir( $dir ) ) {
146 if ( !is_readable( $dir ) ) {
151 if ( !is_writable( dirname( $dir ) ) ) {
153 if ( $webserverGroup !==
null ) {
155 'config-sqlite-parent-unwritable-group',
156 $dir, dirname( $dir ), basename( $dir ),
161 'config-sqlite-parent-unwritable-nogroup',
162 $dir, dirname( $dir ), basename( $dir )
175 if ( !is_dir( $dir ) ) {
176 Wikimedia\suppressWarnings();
178 Wikimedia\restoreWarnings();
183 # Put a .htaccess file in case the user didn't take our advice
184 file_put_contents(
"$dir/.htaccess",
"Deny from all\n" );
193 $dir = $this->
getVar(
'wgSQLiteDataDir' );
194 $dbName = $this->
getVar(
'wgDBname' );
196 # @todo FIXME: Need more sensible constructor parameters, e.g. single associative array
197 $db = Database::factory(
'sqlite', [
'dbname' => $dbName,
'dbDirectory' => $dir ] );
198 $status->value =
$db;
200 $status->fatal(
'config-sqlite-connection-error', $e->getMessage() );
210 $dir = $this->
getVar(
'wgSQLiteDataDir' );
211 $dbName = $this->
getVar(
'wgDBname' );
213 if ( !file_exists( DatabaseSqlite::generateFileName( $dir, $dbName ) ) ) {
218 return parent::needsUpgrade();
225 $dir = $this->
getVar(
'wgSQLiteDataDir' );
227 # Sanity check (Only available in web installation). We checked this before but maybe someone
228 # deleted the data dir between then and now
230 if ( $dir_status->isGood() ) {
232 if ( !
$res->isGood() ) {
241 # Make the main and cache stub DB files
245 $status->merge( $this->
makeStubDBFile( $dir,
"{$db}_l10n_cache" ) );
246 $status->merge( $this->
makeStubDBFile( $dir,
"{$db}_jobqueue" ) );
247 if ( !$status->isOK() ) {
251 # Nuke the unused settings for clarity
252 $this->
setVar(
'wgDBserver',
'' );
253 $this->
setVar(
'wgDBuser',
'' );
254 $this->
setVar(
'wgDBpassword',
'' );
257 # Create the l10n cache DB
259 $conn = Database::factory(
260 'sqlite', [
'dbname' =>
"{$db}_l10n_cache",
'dbDirectory' => $dir ] );
261 # @todo: don't duplicate l10n_cache definition, though it's very simple
264 CREATE TABLE l10n_cache (
265 lc_lang BLOB NOT NULL,
266 lc_key TEXT NOT NULL,
267 lc_value BLOB NOT NULL,
268 PRIMARY KEY (lc_lang, lc_key)
271 $conn->query( $sql, __METHOD__ );
272 $conn->query(
"PRAGMA journal_mode=WAL", __METHOD__ );
273 $conn->close( __METHOD__ );
275 return Status::newFatal(
'config-sqlite-connection-error', $e->getMessage() );
278 # Create the job queue DB
280 $conn = Database::factory(
281 'sqlite', [
'dbname' =>
"{$db}_jobqueue",
'dbDirectory' => $dir ] );
282 # @todo: don't duplicate job definition, though it's very static
286 job_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
287 job_cmd BLOB NOT NULL
default '',
288 job_namespace INTEGER NOT NULL,
289 job_title TEXT NOT NULL,
290 job_timestamp BLOB NULL
default NULL,
291 job_params BLOB NOT NULL,
292 job_random integer NOT NULL
default 0,
293 job_attempts integer NOT NULL
default 0,
294 job_token BLOB NOT NULL
default '',
295 job_token_timestamp BLOB NULL
default NULL,
296 job_sha1 BLOB NOT NULL
default ''
298 CREATE INDEX job_sha1 ON job (job_sha1);
299 CREATE INDEX job_cmd_token ON job (job_cmd,job_token,job_random);
300 CREATE INDEX job_cmd_token_id ON job (job_cmd,job_token,job_id);
301 CREATE INDEX job_cmd ON job (job_cmd, job_namespace, job_title, job_params);
302 CREATE INDEX job_timestamp ON job (job_timestamp);
304 $conn->query( $sql, __METHOD__ );
305 $conn->query(
"PRAGMA journal_mode=WAL", __METHOD__ );
306 $conn->close( __METHOD__ );
308 return Status::newFatal(
'config-sqlite-connection-error', $e->getMessage() );
321 $file = DatabaseSqlite::generateFileName( $dir,
$db );
322 if ( file_exists(
$file ) ) {
323 if ( !is_writable(
$file ) ) {
326 } elseif ( file_put_contents(
$file,
'' ) ===
false ) {
337 $status = parent::createTables();
338 if ( $status->isGood() ) {
339 $status = parent::createManualTables();
352 $module = DatabaseSqlite::getFulltextSearchModule();
353 $searchIndexSql = (string)$this->db->selectField(
354 $this->db->addIdentifierQuotes(
'sqlite_master' ),
356 [
'tbl_name' => $this->db->tableName(
'searchindex',
'raw' ) ],
359 $fts3tTable = ( stristr( $searchIndexSql,
'fts' ) !== false );
361 if ( $fts3tTable && !$module ) {
362 $status->warning(
'config-sqlite-fts3-downgrade' );
363 $this->db->sourceFile(
"$IP/maintenance/sqlite/archives/searchindex-no-fts.sql" );
364 } elseif ( !$fts3tTable && $module ==
'FTS3' ) {
365 $this->db->sourceFile(
"$IP/maintenance/sqlite/archives/searchindex-fts3.sql" );
379 return "# SQLite-specific settings
380 \$wgSQLiteDataDir = \"{$dir}\";
381 \$wgObjectCaches[CACHE_DB] = [
382 'class' => SqlBagOStuff::class,
383 'loggroup' => 'SQLBagOStuff',
386 'dbname' => 'wikicache',
388 'variables' => [ 'synchronous' => 'NORMAL' ],
389 'dbDirectory' => \$wgSQLiteDataDir,
390 'trxMode' => 'IMMEDIATE',
394 \$wgLocalisationCacheConf['storeServer'] = [
396 'dbname' => \"{\$wgDBname}_l10n_cache\",
398 'variables' => [ 'synchronous' => 'NORMAL' ],
399 'dbDirectory' => \$wgSQLiteDataDir,
400 'trxMode' => 'IMMEDIATE',
403 \$wgJobTypeConf['default'] = [
404 'class' => 'JobQueueDB',
408 'dbname' => \"{\$wgDBname}_jobqueue\",
410 'variables' => [ 'synchronous' => 'NORMAL' ],
411 'dbDirectory' => \$wgSQLiteDataDir,
412 'trxMode' => 'IMMEDIATE',