Skip to content

Commit

Permalink
Add debugkit connection status to welcome page
Browse files Browse the repository at this point in the history
Separate the 'installed' from 'works' states to make
setup issues easier to understand.
  • Loading branch information
markstory committed May 8, 2021
1 parent 69716b3 commit 699df38
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions templates/Pages/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@

$this->disableAutoLayout();

$checkConnection = function (string $name) {
$error = null;
$connected = false;
try {
$connection = ConnectionManager::get($name);
$connected = $connection->connect();
} catch (Exception $connectionError) {
$error = $connectionError->getMessage();
if (method_exists($connectionError, 'getAttributes')) {
$attributes = $connectionError->getAttributes();
if (isset($attributes['message'])) {
$error .= '<br />' . $attributes['message'];
}
}
}

return compact('connected', 'error');
};

if (!Configure::read('debug')) :
throw new NotFoundException(
'Please replace templates/Pages/home.php with your own version or re-enable debug mode.'
Expand Down Expand Up @@ -56,7 +75,7 @@
<img alt="CakePHP" src="https://cakephp.org/v2/img/logos/CakePHP_Logo.svg" width="350" />
</a>
<h1>
Welcome to CakePHP <?php echo Configure::version() ?> Strawberry (🍓)
Welcome to CakePHP <?= Configure::version() ?> Strawberry (🍓)
</h1>
</div>
</header>
Expand Down Expand Up @@ -85,9 +104,9 @@
<h4>Environment</h4>
<ul>
<?php if (version_compare(PHP_VERSION, '7.2.0', '>=')) : ?>
<li class="bullet success">Your version of PHP is 7.2.0 or higher (detected <?php echo PHP_VERSION ?>).</li>
<li class="bullet success">Your version of PHP is 7.2.0 or higher (detected <?= PHP_VERSION ?>).</li>
<?php else : ?>
<li class="bullet problem">Your version of PHP is too low. You need PHP 7.2.0 or higher to use CakePHP (detected <?php echo PHP_VERSION ?>).</li>
<li class="bullet problem">Your version of PHP is too low. You need PHP 7.2.0 or higher to use CakePHP (detected <?= PHP_VERSION ?>).</li>
<?php endif; ?>

<?php if (extension_loaded('mbstring')) : ?>
Expand Down Expand Up @@ -128,7 +147,7 @@

<?php $settings = Cache::getConfig('_cake_core_'); ?>
<?php if (!empty($settings)) : ?>
<li class="bullet success">The <em><?php echo $settings['className'] ?>Engine</em> is being used for core caching. To change the config edit config/app.php</li>
<li class="bullet success">The <em><?= $settings['className'] ?>Engine</em> is being used for core caching. To change the config edit config/app.php</li>
<?php else : ?>
<li class="bullet problem">Your cache is NOT working. Please check the settings in config/app.php</li>
<?php endif; ?>
Expand All @@ -140,25 +159,13 @@
<div class="column">
<h4>Database</h4>
<?php
try {
$connection = ConnectionManager::get('default');
$connected = $connection->connect();
} catch (Exception $connectionError) {
$connected = false;
$errorMsg = $connectionError->getMessage();
if (method_exists($connectionError, 'getAttributes')) :
$attributes = $connectionError->getAttributes();
if (isset($attributes['message'])) :
$errorMsg .= '<br />' . $attributes['message'];
endif;
endif;
}
$result = $checkConnection('default');
?>
<ul>
<?php if ($connected) : ?>
<?php if ($result['connected']) : ?>
<li class="bullet success">CakePHP is able to connect to the database.</li>
<?php else : ?>
<li class="bullet problem">CakePHP is NOT able to connect to the database.<br /><?php echo $errorMsg ?></li>
<li class="bullet problem">CakePHP is NOT able to connect to the database.<br /><?= $result['error'] ?></li>
<?php endif; ?>
</ul>
</div>
Expand All @@ -168,7 +175,15 @@
<?php if (Plugin::isLoaded('DebugKit')) : ?>
<li class="bullet success">DebugKit is loaded.</li>
<?php else : ?>
<li class="bullet problem">DebugKit is NOT loaded. You need to either install pdo_sqlite, or define the "debug_kit" connection name.</li>
<li class="bullet problem">DebugKit is <strong>not</strong> loaded.</li>
<?php endif; ?>
<?php
$result = $checkConnection('debug_kit');
?>
<?php if ($result['connected']) : ?>
<li class="bullet success">DebugKit can connect to the database.</li>
<?php else : ?>
<li class="bullet problem">DebugKit is <strong>not</strong> able to connect to the database.<br /><?= $result['error'] ?></li>
<?php endif; ?>
</ul>
</div>
Expand Down

0 comments on commit 699df38

Please sign in to comment.