Catch a DB connection exception earlier [MAILPOET-966]
This commit is contained in:
committed by
pavel-mailpoet
parent
d3db755489
commit
fb1a3a80ff
@ -42,9 +42,17 @@ class Database {
|
||||
$driver_options[] = $character_set;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
@ -31,7 +31,12 @@ class Initializer {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->setupDB();
|
||||
} catch(\Exception $e) {
|
||||
$this->handleFailedInitialization($e);
|
||||
return;
|
||||
}
|
||||
|
||||
// activation function
|
||||
register_activation_hook(
|
||||
@ -232,7 +237,10 @@ class Initializer {
|
||||
}
|
||||
|
||||
function handleFailedInitialization($message) {
|
||||
// Check if we are able to add pages at this point
|
||||
if (function_exists('wp_get_current_user')) {
|
||||
Menu::addErrorPage();
|
||||
}
|
||||
return WPNotice::displayError($message);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user