r65861 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65860‎ | r65861 | r65862 >
Date:16:01, 3 May 2010
Author:avar
Status:ok
Tags:
Comment:
Make setupDatabase() return Status & account for SQLite inconsistency

If the SQLite database was deleted between submitConnectForm() and
setupDatabase() the installer would panic.

There's still a lot of hairy edge cases like that, but this fixes one
of them.
Modified paths:
  • /branches/new-installer/phase3/includes/installer/InstallerDBType.php (modified) (history)
  • /branches/new-installer/phase3/includes/installer/MysqlInstaller.php (modified) (history)
  • /branches/new-installer/phase3/includes/installer/SqliteInstaller.php (modified) (history)

Diff [purge]

Index: branches/new-installer/phase3/includes/installer/SqliteInstaller.php
@@ -44,6 +44,10 @@
4545 $dir = $this->getVar( 'wgSQLiteDataDir' );
4646 }
4747 $this->setVar( 'wgSQLiteDataDir', $dir );
 48+ return self::dataDirOKmaybeCreate( $dir, true /* create? */ );
 49+ }
 50+
 51+ private static function dataDirOKmaybeCreate( $dir, $create = false ) {
4852 if ( !is_dir( $dir ) ) {
4953 if ( !is_writable( dirname( $dir ) ) ) {
5054 $webserverGroup = Installer::maybeGetWebserverPrimaryGroup();
@@ -53,18 +57,25 @@
5458 return Status::newFatal( 'config-sqlite-parent-unwritable-nogroup', $dir, dirname( $dir ), basename( $dir ) );
5559 }
5660 }
57 - wfSuppressWarnings();
58 - $ok = wfMkdirParents( $dir, 0700 );
59 - wfRestoreWarnings();
60 - if ( !$ok ) {
61 - return Status::newFatal( 'config-sqlite-mkdir-error', $dir );
 61+
 62+ # Called early on in the installer, later we just want to sanity check
 63+ # if it's still writable
 64+ if ( $create ) {
 65+ wfSuppressWarnings();
 66+ $ok = wfMkdirParents( $dir, 0700 );
 67+ wfRestoreWarnings();
 68+ if ( !$ok ) {
 69+ return Status::newFatal( 'config-sqlite-mkdir-error', $dir );
 70+ }
 71+ # Put a .htaccess file in in case the user didn't take our advice
 72+ file_put_contents( "$dir/.htaccess", "Deny from all\n" );
6273 }
63 - # Put a .htaccess file in in case the user didn't take our advice
64 - file_put_contents( "$dir/.htaccess", "Deny from all\n" );
6574 }
6675 if ( !is_writable( $dir ) ) {
6776 return Status::newFatal( 'config-sqlite-dir-unwritable', $dir );
6877 }
 78+
 79+ # We haven't blown up yet, fall through
6980 return Status::newGood();
7081 }
7182
@@ -108,7 +119,17 @@
109120 }
110121
111122 function setupDatabase() {
112 - $file = DatabaseSqlite::generateFileName( $this->getVar( 'wgSQLiteDataDir' ), $this->getVar( 'wgDBname' ) );
 123+ $dir = $this->getVar( 'wgSQLiteDataDir' );
 124+
 125+ # Sanity check. We checked this before but maybe someone deleted the
 126+ # data dir between then and now
 127+ $dir_status = self::dataDirOKmaybeCreate( $dir, false /* create? */ );
 128+ if ( !$dir_status->isOK() ) {
 129+ return $dir_status;
 130+ }
 131+
 132+ $db = $this->getVar( 'wgDBname' );
 133+ $file = DatabaseSqlite::generateFileName( $dir, $db );
113134 if ( file_exists( $file ) ) {
114135 if ( !is_writable( $file ) ) {
115136 return Status::newFatal( 'config-sqlite-readonly', $file );
Index: branches/new-installer/phase3/includes/installer/MysqlInstaller.php
@@ -365,7 +365,7 @@
366366 function setupDatabase() {
367367 $status = $this->getConnection();
368368 if ( !$status->isOK() ) {
369 - return false;
 369+ return $status;
370370 }
371371 $conn = $status->value;
372372 $dbName = $this->getVar( 'wgDBname' );
@@ -373,7 +373,7 @@
374374 $conn->query( "CREATE DATABASE `$dbName`" );
375375 $conn->selectDB( $dbName );
376376 }
377 - return $conn;
 377+ return $status;
378378 }
379379
380380 function createTables() {
Index: branches/new-installer/phase3/includes/installer/InstallerDBType.php
@@ -78,7 +78,10 @@
7979 abstract function getConnection();
8080
8181 /**
82 - * Create the database and return a database object to use it
 82+ * Create the database and return a Status object indicating success or
 83+ * failure.
 84+ *
 85+ * @return Status
8386 */
8487 abstract function setupDatabase();
8588

Status & tagging log