Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/HealthCheck/DoctrineConnectionHealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace OpenConext\MonitorBundle\HealthCheck;

use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use Exception;
use OpenConext\MonitorBundle\Value\HealthReport;
Expand Down Expand Up @@ -47,18 +48,12 @@ public function check(HealthReportInterface $report): HealthReportInterface
{
// Was the entityManager injected? When it is not the project does not use Doctrine ORM
if (!is_null($this->entityManager)) {
// @todo: get a custom query from the bundle configuration
$query = 'SELECT 1';
try {
// Get the schema manager and grab the first table to later query on
$sm = $this->entityManager->getConnection()->getSchemaManager();
$tables = $sm->listTables();
if (!empty($tables)) {
$table = reset($tables);
// Perform a light-weight query on the chosen table
$query = 'SELECT * FROM `%s` LIMIT 1';
$this->entityManager->getConnection()->executeQuery(sprintf($query, $table->getName()));
}
$this->entityManager->getConnection()->executeQuery($query);
} catch (Exception $e) {
return HealthReport::buildStatusDown('Unable to execute a query on the database.');
return HealthReport::buildStatusDown("Unable to execute query [$query] on the database.");
}
}
return $report;
Expand Down