(bug 17611) Provide a sensible error message on install when the SQLite data director...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 8 May 2009 05:43:37 +0000 (05:43 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 8 May 2009 05:43:37 +0000 (05:43 +0000)
HISTORY
config/index.php

diff --git a/HISTORY b/HISTORY
index 9930adb..234216b 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -327,6 +327,8 @@ Change notes from older releases. For current info see RELEASE-NOTES.
 * (bug 18601) generator=backlinks returns invalid continue parameter
 * (bug 18597) Internal error with empty generator= parameter
 * (bug 18617) Add xml:space="preserve" attribute to relevant tags in XML output
+* (bug 17611) Provide a sensible error message on install when the SQLite data
+  directory is wrong.
 
 === Languages updated in 1.15 ===
 
index 5570905..96e8a14 100644 (file)
@@ -819,7 +819,9 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                $wgTitle = Title::newFromText( "Installation script" );
                error_reporting( E_ALL );
                print "<li>Loading class: " . htmlspecialchars( $dbclass ) . "</li>\n";
-               $dbc = new $dbclass;
+               if ( $conf->DBtype != 'sqlite' ) {
+                       $dbc = new $dbclass;
+               }
 
                if( $conf->DBtype == 'mysql' ) {
                        $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
@@ -903,7 +905,46 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                $myver = $wgDatabase->getServerVersion();
                        }
                        if (is_callable(array($wgDatabase, 'initial_setup'))) $wgDatabase->initial_setup('', $wgDBname);
-                       
+
+               } elseif ( $conf->DBtype == 'sqlite' ) {
+                       if ("$wgSQLiteDataDir" == '') {
+                               $wgSQLiteDataDir = dirname($_SERVER['DOCUMENT_ROOT']).'/data';
+                       }
+                       echo "<li>Attempting to connect to SQLite database at \"" . 
+                               htmlspecialchars( $wgSQLiteDataDir ) .  "\"";
+                       if ( !is_dir( $wgSQLiteDataDir ) ) {
+                               if ( is_writable( dirname( $wgSQLiteDataDir ) ) ) {
+                                       $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 = "$wgSQLiteDataDir/$wgDBname.sqlite";
+                       if ( file_exists( $dataFile ) && !is_writable( $dataFile ) ) {
+                               echo ": data file not writable</li>";
+                               $errs['SQLiteDataDir'] = "$wgDBname.sqlite is not writable";
+                               continue;
+                       }
+                       $wgDatabase = new DatabaseSqlite( false, false, false, $wgDBname, 1 );
+                       if (!$wgDatabase->isOpen()) {
+                               print ": error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
+                               $errs['SQLiteDataDir'] = 'Could not connect to database';
+                               continue;
+                       } else {
+                               $myver = $wgDatabase->getServerVersion();
+                       }
+                       if (is_callable(array($wgDatabase, 'initial_setup'))) $wgDatabase->initial_setup('', $wgDBname);
+                       echo "ok</li>\n";
                } else { # not mysql
                        error_reporting( E_ALL );
                        $wgSuperUser = '';