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;
|
$driver_options[] = $character_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
$current_options = ORM::for_table("")
|
/**
|
||||||
->raw_query('SELECT @@session.wait_timeout as wait_timeout')
|
* Rethrow PDOExceptions to prevent exposing sensitive data in stack traces
|
||||||
->findOne();
|
*/
|
||||||
|
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) {
|
if($current_options && (int)$current_options->wait_timeout < $this->driver_option_wait_timeout) {
|
||||||
$driver_options[] = 'SESSION wait_timeout = ' . $this->driver_option_wait_timeout;
|
$driver_options[] = 'SESSION wait_timeout = ' . $this->driver_option_wait_timeout;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,12 @@ class Initializer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setupDB();
|
try {
|
||||||
|
$this->setupDB();
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
$this->handleFailedInitialization($e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// activation function
|
// activation function
|
||||||
register_activation_hook(
|
register_activation_hook(
|
||||||
@ -232,7 +237,10 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleFailedInitialization($message) {
|
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);
|
return WPNotice::displayError($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user