if ("$wgSQLiteDataDir" == '') {
$wgSQLiteDataDir = dirname($_SERVER['DOCUMENT_ROOT']).'/data';
}
- echo "<li>Attempting to connect to SQLite database at \"" .
- htmlspecialchars( $wgSQLiteDataDir ) . "\"";
+ echo '<li>Attempting to connect to SQLite database at "' .
+ htmlspecialchars( $wgSQLiteDataDir ) . '": ';
if ( !is_dir( $wgSQLiteDataDir ) ) {
if ( is_writable( dirname( $wgSQLiteDataDir ) ) ) {
$ok = wfMkdirParents( $wgSQLiteDataDir, $wgSQLiteDataDirMode );
$ok = false;
}
if ( !$ok ) {
- echo ": cannot create data directory</li>";
+ echo "cannot create data directory</li>";
$errs['SQLiteDataDir'] = 'Enter a valid data directory';
continue;
}
}
if ( !is_writable( $wgSQLiteDataDir ) ) {
- echo ": data directory not writable</li>";
+ echo "data directory not writable</li>";
$errs['SQLiteDataDir'] = 'Enter a writable data directory';
continue;
}
- $dataFile = "$wgSQLiteDataDir/$wgDBname.sqlite";
- if ( file_exists( $dataFile ) && !is_writable( $dataFile ) ) {
- echo ": data file not writable</li>";
- $errs['SQLiteDataDir'] = "$wgDBname.sqlite is not writable";
+ $dataFile = DatabaseSqlite::generateFileName( $wgSQLiteDataDir, $wgDBname );
+ if ( file_exists( $dataFile ) ) {
+ if ( !is_writable( $dataFile ) ) {
+ echo "data file not writable</li>";
+ $errs['SQLiteDataDir'] = basename( $dataFile ) . " is not writable";
+ continue;
+ }
+ } else {
+ if ( file_put_contents( $dataFile, '' ) === false ) {
+ echo 'could not create database file "' . htmlspecialchars( basename( $dataFile ) ) . "\"</li>\n";
+ $errs['SQLiteDataDir'] = "couldn't create " . basename( $dataFile );
+ continue;
+ }
+ }
+ try {
+ $wgDatabase = new DatabaseSqlite( false, false, false, $wgDBname, 1 );
+ }
+ catch( MWException $ex ) {
+ echo 'error: ' . htmlspecialchars( $ex->getMessage() ) . "</li>\n";
continue;
}
- $wgDatabase = new DatabaseSqlite( false, false, false, $wgDBname, 1 );
+
if (!$wgDatabase->isOpen()) {
- print ": error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
+ print "error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
$errs['SQLiteDataDir'] = 'Could not connect to database';
continue;
} else {
global $wgSQLiteDataDir;
$this->mFailFunction = $failFunction;
$this->mFlags = $flags;
- $this->mDatabaseFile = "$wgSQLiteDataDir/$dbName.sqlite";
+ $this->mDatabaseFile = self::generateFileName( $wgSQLiteDataDir, $dbName );
if( !is_readable( $this->mDatabaseFile ) )
throw new DBConnectionError( $this, "SQLite database not accessible" );
$this->mName = $dbName;
return true;
}
+ /**
+ * Generates a database file name. Explicitly public for installer.
+ * @param $dir String: Directory where database resides
+ * @param $dbName String: Database name
+ * @return String
+ */
+ public static function generateFileName( $dir, $dbName ) {
+ return "$dir/$dbName.sqlite";
+ }
+
/**
* SQLite doesn't allow buffered results or data seeking etc, so we'll use fetchAll as the result
*/
* - this is the same way PostgreSQL works, MySQL reads in tables.sql and interwiki.sql using dbsource (which calls db->sourceFile)
*/
public function setup_database() {
- global $IP, $wgSQLiteDataDir, $wgDBTableOptions;
- $wgDBTableOptions = '';
+ global $IP;
# Process common MySQL/SQLite table definitions
$err = $this->sourceFile( "$IP/maintenance/tables.sql" );