/** * @return Status */ public function setupDatabase() { $dir = $this->getVar('wgSQLiteDataDir'); # Sanity check. We checked this before but maybe someone deleted the # data dir between then and now $dir_status = self::dataDirOKmaybeCreate($dir, false); if (!$dir_status->isOK()) { return $dir_status; } $db = $this->getVar('wgDBname'); $file = DatabaseSqlite::generateFileName($dir, $db); if (file_exists($file)) { if (!is_writable($file)) { return Status::newFatal('config-sqlite-readonly', $file); } } else { if (file_put_contents($file, '') === false) { 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(); }
$ok = wfMkdirParents($wgSQLiteDataDir, $wgSQLiteDataDirMode); } else { $ok = false; } if (!$ok) { echo "cannot create data directory</li>"; $errs['SQLiteDataDir'] = 'Enter a valid data directory'; continue; } } if (!is_writable($wgSQLiteDataDir)) { echo "data directory not writable</li>"; $errs['SQLiteDataDir'] = 'Enter a writable data directory'; continue; } $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);
protected function makeStubDBFile($dir, $db) { $file = DatabaseSqlite::generateFileName($dir, $db); if (file_exists($file)) { if (!is_writable($file)) { return Status::newFatal('config-sqlite-readonly', $file); } } else { if (file_put_contents($file, '') === false) { return Status::newFatal('config-sqlite-cant-create-db', $file); } } return Status::newGood(); }