mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
better error message in MissingConnectionException when driver is not enabled
This commit is contained in:
parent
55f3cbe1f6
commit
b913fe5303
5 changed files with 21 additions and 7 deletions
|
@ -337,6 +337,12 @@ class MissingConnectionException extends CakeException {
|
|||
|
||||
protected $_messageTemplate = 'Database connection "%s" is missing, or could not be created.';
|
||||
|
||||
public function __construct($message, $code = 500) {
|
||||
if (is_array($message)) {
|
||||
$message += array('enabled' => true);
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -439,7 +445,7 @@ class MissingPluginException extends CakeException {
|
|||
}
|
||||
|
||||
/**
|
||||
* Exception class for AclComponent and Interface implementations.
|
||||
* Exception class for AclComponent and Interface implementations.
|
||||
*
|
||||
* @package Cake.Error
|
||||
*/
|
||||
|
|
|
@ -237,7 +237,8 @@ class DboSource extends DataSource {
|
|||
$this->fullDebug = Configure::read('debug') > 1;
|
||||
if (!$this->enabled()) {
|
||||
throw new MissingConnectionException(array(
|
||||
'class' => get_class($this)
|
||||
'class' => get_class($this),
|
||||
'enabled' => false
|
||||
));
|
||||
}
|
||||
if ($autoConnect) {
|
||||
|
|
|
@ -3429,10 +3429,6 @@ class Model extends Object implements CakeEventListener {
|
|||
}
|
||||
|
||||
$this->schemaName = $db->getSchemaName();
|
||||
|
||||
if (empty($db) || !is_object($db)) {
|
||||
throw new MissingConnectionException(array('class' => $this->name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -559,6 +559,15 @@ class ExceptionRendererTest extends CakeTestCase {
|
|||
),
|
||||
500
|
||||
),
|
||||
array(
|
||||
new MissingConnectionException(array('class' => 'Mysql', 'enabled' => false)),
|
||||
array(
|
||||
'/<h2>Missing Database Connection<\/h2>/',
|
||||
'/Mysql requires a database connection/',
|
||||
'/Mysql driver is NOT enabled/'
|
||||
),
|
||||
500
|
||||
),
|
||||
array(
|
||||
new MissingDatasourceConfigException(array('config' => 'default')),
|
||||
array(
|
||||
|
|
|
@ -21,10 +21,12 @@
|
|||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', '%s requires a database connection', $class); ?>
|
||||
</p>
|
||||
<?php if (!$enabled) : ?>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Confirm you have created the file : %s.', APP_DIR . DS . 'Config' . DS . 'database.php'); ?>
|
||||
<?php echo __d('cake_dev', '%s driver is NOT enabled', $class); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s.', APP_DIR . DS . 'View' . DS . 'Errors' . DS . basename(__FILE__)); ?>
|
||||
|
|
Loading…
Reference in a new issue