Index: branches/new-installer/phase3/includes/installer/SqliteInstaller.php |
— | — | @@ -44,6 +44,10 @@ |
45 | 45 | $dir = $this->getVar( 'wgSQLiteDataDir' ); |
46 | 46 | } |
47 | 47 | $this->setVar( 'wgSQLiteDataDir', $dir ); |
| 48 | + return self::dataDirOKmaybeCreate( $dir, true /* create? */ ); |
| 49 | + } |
| 50 | + |
| 51 | + private static function dataDirOKmaybeCreate( $dir, $create = false ) { |
48 | 52 | if ( !is_dir( $dir ) ) { |
49 | 53 | if ( !is_writable( dirname( $dir ) ) ) { |
50 | 54 | $webserverGroup = Installer::maybeGetWebserverPrimaryGroup(); |
— | — | @@ -53,18 +57,25 @@ |
54 | 58 | return Status::newFatal( 'config-sqlite-parent-unwritable-nogroup', $dir, dirname( $dir ), basename( $dir ) ); |
55 | 59 | } |
56 | 60 | } |
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" ); |
62 | 73 | } |
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" ); |
65 | 74 | } |
66 | 75 | if ( !is_writable( $dir ) ) { |
67 | 76 | return Status::newFatal( 'config-sqlite-dir-unwritable', $dir ); |
68 | 77 | } |
| 78 | + |
| 79 | + # We haven't blown up yet, fall through |
69 | 80 | return Status::newGood(); |
70 | 81 | } |
71 | 82 | |
— | — | @@ -108,7 +119,17 @@ |
109 | 120 | } |
110 | 121 | |
111 | 122 | 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 ); |
113 | 134 | if ( file_exists( $file ) ) { |
114 | 135 | if ( !is_writable( $file ) ) { |
115 | 136 | return Status::newFatal( 'config-sqlite-readonly', $file ); |
Index: branches/new-installer/phase3/includes/installer/MysqlInstaller.php |
— | — | @@ -365,7 +365,7 @@ |
366 | 366 | function setupDatabase() { |
367 | 367 | $status = $this->getConnection(); |
368 | 368 | if ( !$status->isOK() ) { |
369 | | - return false; |
| 369 | + return $status; |
370 | 370 | } |
371 | 371 | $conn = $status->value; |
372 | 372 | $dbName = $this->getVar( 'wgDBname' ); |
— | — | @@ -373,7 +373,7 @@ |
374 | 374 | $conn->query( "CREATE DATABASE `$dbName`" ); |
375 | 375 | $conn->selectDB( $dbName ); |
376 | 376 | } |
377 | | - return $conn; |
| 377 | + return $status; |
378 | 378 | } |
379 | 379 | |
380 | 380 | function createTables() { |
Index: branches/new-installer/phase3/includes/installer/InstallerDBType.php |
— | — | @@ -78,7 +78,10 @@ |
79 | 79 | abstract function getConnection(); |
80 | 80 | |
81 | 81 | /** |
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 |
83 | 86 | */ |
84 | 87 | abstract function setupDatabase(); |
85 | 88 | |