From dc654a3028ace4e1d0cc19653565d66c6602b303 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 8 May 2009 05:43:37 +0000 Subject: [PATCH] (bug 17611) Provide a sensible error message on install when the SQLite data directory is wrong. For backport to 1.15. Achieved by layering another collection of ugly hacks on top of config/index.php, in the hopes that the combined weight of hackishness might convince Brion to allow me to finish the new installer. --- HISTORY | 2 ++ config/index.php | 45 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index 9930adb8e5..234216b68e 100644 --- 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 === diff --git a/config/index.php b/config/index.php index 557090562e..96e8a14fa4 100644 --- a/config/index.php +++ b/config/index.php @@ -819,7 +819,9 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { $wgTitle = Title::newFromText( "Installation script" ); error_reporting( E_ALL ); print "
  • Loading class: " . htmlspecialchars( $dbclass ) . "
  • \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 "
  • 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
  • "; + $errs['SQLiteDataDir'] = 'Enter a valid data directory'; + continue; + } + } + if ( !is_writable( $wgSQLiteDataDir ) ) { + echo ": data directory not writable"; + $errs['SQLiteDataDir'] = 'Enter a writable data directory'; + continue; + } + $dataFile = "$wgSQLiteDataDir/$wgDBname.sqlite"; + if ( file_exists( $dataFile ) && !is_writable( $dataFile ) ) { + echo ": data file not writable"; + $errs['SQLiteDataDir'] = "$wgDBname.sqlite is not writable"; + continue; + } + $wgDatabase = new DatabaseSqlite( false, false, false, $wgDBname, 1 ); + if (!$wgDatabase->isOpen()) { + print ": error: " . htmlspecialchars( $wgDatabase->lastError() ) . "\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\n"; } else { # not mysql error_reporting( E_ALL ); $wgSuperUser = ''; -- 2.20.1