Catch a DB connection exception earlier [MAILPOET-966]

This commit is contained in:
stoletniy
2017-06-29 18:38:15 +03:00
committed by pavel-mailpoet
parent d3db755489
commit fb1a3a80ff
2 changed files with 22 additions and 6 deletions

View File

@ -42,9 +42,17 @@ class Database {
$driver_options[] = $character_set;
}
$current_options = ORM::for_table("")
->raw_query('SELECT @@session.wait_timeout as wait_timeout')
->findOne();
/**
* Rethrow PDOExceptions to prevent exposing sensitive data in stack traces
*/
try {
$current_options = ORM::for_table("")
->raw_query('SELECT @@session.wait_timeout as wait_timeout')
->findOne();
} catch (\PDOException $e) {
throw new \Exception($e->getMessage());
}
if($current_options && (int)$current_options->wait_timeout < $this->driver_option_wait_timeout) {
$driver_options[] = 'SESSION wait_timeout = ' . $this->driver_option_wait_timeout;
}

View File

@ -31,7 +31,12 @@ class Initializer {
return;
}
$this->setupDB();
try {
$this->setupDB();
} catch(\Exception $e) {
$this->handleFailedInitialization($e);
return;
}
// activation function
register_activation_hook(
@ -232,7 +237,10 @@ class Initializer {
}
function handleFailedInitialization($message) {
Menu::addErrorPage();
// Check if we are able to add pages at this point
if (function_exists('wp_get_current_user')) {
Menu::addErrorPage();
}
return WPNotice::displayError($message);
}
}