Commit 5a01d850 authored by Addshore's avatar Addshore 🏄 Committed by Michael Große
Browse files

dev: Nicer error from MW if the DB doesn't exist

parent e4268295
......@@ -49,11 +49,15 @@ $mwddServices = [
################################
# MWDD Database
################################
// TODO cache the DB existance checks somehow so as not to run on every request...
// Figure out if we are using sqlite, or if this should be mysql..?
if( file_exists( $IP . '/data/' . $dockerDb . '.sqlite' ) ) {
$dockerDbType = 'sqlite';
} else {
// TODO cache this check somehow so that we don't need a query every time...
}
// Figure out if we are using mysql
if(!isset($dockerDbType)){
try{
$mysqlPdo = new PDO(
"mysql:host=mysql;dbname=" . $dockerDb,
......@@ -72,14 +76,34 @@ if( file_exists( $IP . '/data/' . $dockerDb . '.sqlite' ) ) {
$dockerDbType = 'mysql';
}
} catch ( Exception $e ) {
// TODO set the timeout on connection to be much shorter, so that when mysql doesnt exist, it doenst hang for a while
// do nothing
}
// If no other magic detection happened, we must be in postgres (or some generic error state)
if(!isset($dockerDbType)){
}
// Figure out if we are using postgres
if(!isset($dockerDbType)){
$pvars = [
'dbname' => $dockerDb,
'user' => 'root',
'password' => 'toor',
'host' => 'postgres',
];
$pconnString = '';
foreach ( $pvars as $name => $value ) {
$pconnString .= "$name='" . str_replace( "'", "\\'", $value ) . "' ";
}
$postgresConn = @pg_connect( $pconnString . ' connect_timeout=1', PGSQL_CONNECT_FORCE_NEW );
if($postgresConn !== false){
$dockerDbType = 'postgres';
}
}
// Otherwise something must be wrong
if(!isset($dockerDbType)){
die("Is your database running and wiki database created / installed?");
}
$wgDBname = $dockerDb;
if( $dockerDbType === 'sqlite' ) {
......
......@@ -14,9 +14,7 @@ trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
# Validate the basic stuff
./bin/mw docker docker-compose ps
./bin/mw docker env list
# TODO enable logo check again once the page no longer shown "Unable to connect to PostgreSQL server"
#CURL=$(curl -s -L -N http://default.mediawiki.mwdd.localhost:8080) && echo $CURL && echo $CURL | grep -q "The MediaWiki logo"
CURL=$(curl -s -L -N http://default.mediawiki.mwdd.localhost:8080) && echo $CURL && echo $CURL | grep -q "Unable to connect to PostgreSQL server"
CURL=$(curl -s -L -N http://default.mediawiki.mwdd.localhost:8080) && echo $CURL && echo $CURL | grep -q "Is your database running and wiki database created"
# Install sqlite & check
./bin/mw docker mediawiki install
......
......@@ -13,9 +13,7 @@ trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
# Create: Validate the basic stuff
./bin/mw docker docker-compose ps
# TODO enable logo check again once the page no longer shown "Unable to connect to PostgreSQL server"
#CURL=$(curl -s -L -N http://default.mediawiki.mwdd.localhost:8080) && echo $CURL && echo $CURL | grep -q "The MediaWiki logo"
CURL=$(curl -s -L -N http://default.mediawiki.mwdd.localhost:8080) && echo $CURL && echo $CURL | grep -q "Unable to connect to PostgreSQL server"
CURL=$(curl -s -L -N http://default.mediawiki.mwdd.localhost:8080) && echo $CURL && echo $CURL | grep -q "Is your database running and wiki database created"
# Turn on all of the services
./bin/mw docker mysql-replica create
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment