public function checkPrerequisites() {
$result = Status::newGood();
// Bail out if SQLite is too old
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
if ( version_compare( $db->getServerVersion(), self::MINIMUM_VERSION, '<' ) ) {
$result->fatal( 'config-outdated-sqlite', $db->getServerVersion(), self::MINIMUM_VERSION );
}
}
public function getGlobalDefaults() {
+ $defaults = parent::getGlobalDefaults();
if ( isset( $_SERVER['DOCUMENT_ROOT'] ) ) {
$path = str_replace(
array( '/', '\\' ),
dirname( $_SERVER['DOCUMENT_ROOT'] ) . '/data'
);
- return array( 'wgSQLiteDataDir' => $path );
- } else {
- return array();
+ $defaults['wgSQLiteDataDir'] = $path;
}
+ return $defaults;
}
public function getConnectForm() {
# Called early on in the installer, later we just want to sanity check
# if it's still writable
if ( $create ) {
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
$ok = wfMkdirParents( $dir, 0700, __METHOD__ );
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
if ( !$ok ) {
return Status::newFatal( 'config-sqlite-mkdir-error', $dir );
}
# @todo FIXME: Need more sensible constructor parameters, e.g. single associative array
# Setting globals kind of sucks
$wgSQLiteDataDir = $dir;
- $db = new DatabaseSqlite( false, false, false, $dbName );
+ $db = DatabaseBase::factory( 'sqlite', array( 'dbname' => $dbName ) );
$status->value = $db;
} catch ( DBConnectionError $e ) {
$status->fatal( 'config-sqlite-connection-error', $e->getMessage() );
}
$db = $this->getVar( 'wgDBname' );
+
+ # Make the main and cache stub DB files
+ $status = Status::newGood();
+ $status->merge( $this->makeStubDBFile( $dir, $db ) );
+ $status->merge( $this->makeStubDBFile( $dir, "wikicache" ) );
+ if ( !$status->isOK() ) {
+ return $status;
+ }
+
+ # Nuke the unused settings for clarity
+ $this->setVar( 'wgDBserver', '' );
+ $this->setVar( 'wgDBuser', '' );
+ $this->setVar( 'wgDBpassword', '' );
+ $this->setupSchemaVars();
+
+ # Create the global cache DB
+ try {
+ global $wgSQLiteDataDir;
+ # @todo FIXME: setting globals kind of sucks
+ $wgSQLiteDataDir = $dir;
+ $conn = DatabaseBase::factory( 'sqlite', array( 'dbname' => "wikicache" ) );
+ # @todo: don't duplicate objectcache definition, though it's very simple
+ $sql =
+<<<EOT
+ CREATE TABLE IF NOT EXISTS objectcache (
+ keyname BLOB NOT NULL default '' PRIMARY KEY,
+ value BLOB,
+ exptime TEXT
+ )
+EOT;
+ $conn->query( $sql );
+ $conn->query( "CREATE INDEX IF NOT EXISTS exptime ON objectcache (exptime)" );
+ $conn->query( "PRAGMA journal_mode=WAL" ); // this is permanent
+ $conn->close();
+ } catch ( DBConnectionError $e ) {
+ return Status::newFatal( 'config-sqlite-connection-error', $e->getMessage() );
+ }
+
+ # Open the main DB
+ return $this->getConnection();
+ }
+
+ protected function makeStubDBFile( $dir, $db ) {
$file = DatabaseSqlite::generateFileName( $dir, $db );
if ( file_exists( $file ) ) {
if ( !is_writable( $file ) ) {
return Status::newFatal( 'config-sqlite-cant-create-db', $file );
}
}
- // nuke the unused settings for clarity
- $this->setVar( 'wgDBserver', '' );
- $this->setVar( 'wgDBuser', '' );
- $this->setVar( 'wgDBpassword', '' );
- $this->setupSchemaVars();
- return $this->getConnection();
+ return Status::newGood();
}
/**
$dir = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgSQLiteDataDir' ) );
return "# SQLite-specific settings
-\$wgSQLiteDataDir = \"{$dir}\";";
+\$wgSQLiteDataDir = \"{$dir}\";
+\$wgObjectCaches[CACHE_DB] = array(
+ 'class' => 'SqlBagOStuff',
+ 'loggroup' => 'SQLBagOStuff',
+ 'server' => array(
+ 'type' => 'sqlite',
+ 'dbname' => 'wikicache',
+ 'tablePrefix' => '',
+ 'flags' => 0
+ )
+);";
}
}