X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Finstaller%2FSqliteInstaller.php;h=6e1a74f61be2f3dbe7676aed073ef85e90aa4241;hb=4190fe5b697d927427d8026177d479f582e933aa;hp=fe7f5c2b5b80883a8bfae4d29fe7d9b364639c8a;hpb=04f68827d0e3e53ba2924ff7e9f67f6a7e485656;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/installer/SqliteInstaller.php b/includes/installer/SqliteInstaller.php index fe7f5c2b5b..6e1a74f61b 100644 --- a/includes/installer/SqliteInstaller.php +++ b/includes/installer/SqliteInstaller.php @@ -1,7 +1,40 @@ getServerVersion(), self::MINIMUM_VERSION, '<' ) ) { + $result->fatal( 'config-outdated-sqlite', $db->getServerVersion(), self::MINIMUM_VERSION ); + } + // Check for FTS3 full-text search module + if( DatabaseSqlite::getFulltextSearchModule() != 'FTS3' ) { + $result->warning( 'config-no-fts3' ); + } + return $result; + } + public function getGlobalDefaults() { if ( isset( $_SERVER['DOCUMENT_ROOT'] ) ) { $path = str_replace( @@ -29,24 +80,47 @@ class SqliteInstaller extends DatabaseInstaller { } public function getConnectForm() { - return $this->getTextBox( 'wgSQLiteDataDir', 'config-sqlite-dir' ) . - $this->parent->getHelpBox( 'config-sqlite-dir-help' ) . - $this->getTextBox( 'wgDBname', 'config-db-name' ) . - $this->parent->getHelpBox( 'config-sqlite-name-help' ); + return $this->getTextBox( 'wgSQLiteDataDir', 'config-sqlite-dir', array(), $this->parent->getHelpBox( 'config-sqlite-dir-help' ) ) . + $this->getTextBox( 'wgDBname', 'config-db-name', array(), $this->parent->getHelpBox( 'config-sqlite-name-help' ) ); } + /** + * Safe wrapper for PHP's realpath() that fails gracefully if it's unable to canonicalize the path. + * + * @param $path string + * + * @return string + */ + private static function realpath( $path ) { + $result = realpath( $path ); + if ( !$result ) { + return $path; + } + return $result; + } + + /** + * @return Status + */ public function submitConnectForm() { $this->setVarsFromRequest( array( 'wgSQLiteDataDir', 'wgDBname' ) ); - $dir = realpath( $this->getVar( 'wgSQLiteDataDir' ) ); - if ( !$dir ) { - // realpath() sometimes fails, especially on Windows - $dir = $this->getVar( 'wgSQLiteDataDir' ); + # Try realpath() if the directory already exists + $dir = self::realpath( $this->getVar( 'wgSQLiteDataDir' ) ); + $result = self::dataDirOKmaybeCreate( $dir, true /* create? */ ); + if ( $result->isOK() ) { + # Try expanding again in case we've just created it + $dir = self::realpath( $dir ); + $this->setVar( 'wgSQLiteDataDir', $dir ); } - $this->setVar( 'wgSQLiteDataDir', $dir ); - return self::dataDirOKmaybeCreate( $dir, true /* create? */ ); + return $result; } + /** + * @param $dir + * @param $create bool + * @return Status + */ private static function dataDirOKmaybeCreate( $dir, $create = false ) { if ( !is_dir( $dir ) ) { if ( !is_writable( dirname( $dir ) ) ) { @@ -62,7 +136,7 @@ class SqliteInstaller extends DatabaseInstaller { # if it's still writable if ( $create ) { wfSuppressWarnings(); - $ok = wfMkdirParents( $dir, 0700 ); + $ok = wfMkdirParents( $dir, 0700, __METHOD__ ); wfRestoreWarnings(); if ( !$ok ) { return Status::newFatal( 'config-sqlite-mkdir-error', $dir ); @@ -79,25 +153,30 @@ class SqliteInstaller extends DatabaseInstaller { return Status::newGood(); } - public function getConnection() { + /** + * @return Status + */ + public function openConnection() { global $wgSQLiteDataDir; $status = Status::newGood(); $dir = $this->getVar( 'wgSQLiteDataDir' ); $dbName = $this->getVar( 'wgDBname' ); - try { - # FIXME: need more sensible constructor parameters, e.g. single associative array + # @todo FIXME: Need more sensible constructor parameters, e.g. single associative array # Setting globals kind of sucks $wgSQLiteDataDir = $dir; - $this->db = new DatabaseSqlite( false, false, false, $dbName ); - $status->value = $this->db; + $db = new DatabaseSqlite( false, false, false, $dbName ); + $status->value = $db; } catch ( DBConnectionError $e ) { $status->fatal( 'config-sqlite-connection-error', $e->getMessage() ); } return $status; } + /** + * @return bool + */ public function needsUpgrade() { $dir = $this->getVar( 'wgSQLiteDataDir' ); $dbName = $this->getVar( 'wgDBname' ); @@ -110,14 +189,9 @@ class SqliteInstaller extends DatabaseInstaller { return parent::needsUpgrade(); } - public function getSettingsForm() { - return false; - } - - public function submitSettingsForm() { - return Status::newGood(); - } - + /** + * @return Status + */ public function setupDatabase() { $dir = $this->getVar( 'wgSQLiteDataDir' ); @@ -143,63 +217,43 @@ class SqliteInstaller extends DatabaseInstaller { $this->setVar( 'wgDBserver', '' ); $this->setVar( 'wgDBuser', '' ); $this->setVar( 'wgDBpassword', '' ); + $this->setupSchemaVars(); return $this->getConnection(); } + /** + * @return Status + */ public function createTables() { - global $IP; - $status = $this->getConnection(); - if ( !$status->isOK() ) { - return $status; - } - // Process common MySQL/SQLite table definitions - $err = $this->db->sourceFile( "$IP/maintenance/tables.sql" ); - if ( $err !== true ) { - //@todo or...? - $this->db->reportQueryError( $err, 0, $sql, __FUNCTION__ ); - } - return $this->setupSearchIndex(); + $status = parent::createTables(); + return $this->setupSearchIndex( $status ); } - public function setupSearchIndex() { + /** + * @param $status Status + * @return Status + */ + public function setupSearchIndex( &$status ) { global $IP; - $status = Status::newGood(); - - $module = $this->db->getFulltextSearchModule(); + $module = DatabaseSqlite::getFulltextSearchModule(); $fts3tTable = $this->db->checkForEnabledSearch(); if ( $fts3tTable && !$module ) { $status->warning( 'config-sqlite-fts3-downgrade' ); $this->db->sourceFile( "$IP/maintenance/sqlite/archives/searchindex-no-fts.sql" ); } elseif ( !$fts3tTable && $module == 'FTS3' ) { - $status->warning( 'config-sqlite-fts3-add' ); $this->db->sourceFile( "$IP/maintenance/sqlite/archives/searchindex-fts3.sql" ); - } else { - $status->warning( 'config-sqlite-fts3-ok' ); } - return $status; } - public function doUpgrade() { - global $wgDatabase; - LBFactory::enableBackend(); - $wgDatabase = wfGetDB( DB_MASTER ); - ob_start( array( 'SqliteInstaller', 'outputHandler' ) ); - do_all_updates( false, true ); - ob_end_flush(); - return true; - } - - public static function outputHandler( $string ) { - return htmlspecialchars( $string ); - } - + /** + * @return string + */ public function getLocalSettings() { $dir = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgSQLiteDataDir' ) ); return "# SQLite-specific settings \$wgSQLiteDataDir = \"{$dir}\";"; } - -} \ No newline at end of file +}