1 Commits

Author SHA1 Message Date
AI Development Engine
d02e4311dd feat: implement issue #6
Resolves luca/thetool#6
Closes #6
2026-03-02 10:26:54 +00:00

View File

@@ -1,61 +1,36 @@
<?php
/**
* Health check endpoint for thetool
* Returns database table count for monitoring purposes
*/
// Health check endpoint - returns number of tables in thetool database
// Bootstrap the application
if(file_exists("../../config/config.php")) {
require("../../config/config.php");
// Define required constants before loading config
define('FRONKDB_SQLDEBUG', false);
// Load the framework's database configuration
require_once(__DIR__ . "/../../config/config.php");
// Load the autoloader to get FronkDB class
require_once(__DIR__ . "/../../lib/autoloader/autoloader.php");
require_once(__DIR__ . "/../../lib/mvcfronk/mfLog/mfLoghandler.php");
require_once(__DIR__ . "/../../lib/FronkDB/FronkDB.php");
// Connect to the database using the framework's configuration
$db = new FronkDB(
FRONKDB_DBHOST,
FRONKDB_DBUSER,
FRONKDB_DBPASS,
FRONKDB_DBNAME
);
// Query to count tables in the thetool database
$sql = "SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = 'thetool'";
$result = $db->query($sql);
if ($result) {
$row = $db->fetch_array($result);
$tableCount = (int)$row['count'];
} else {
header("Content-Type: application/json");
http_response_code(500);
echo json_encode(["status" => "error", "message" => "Configuration not found"]);
exit;
}
// Define FronkDB constants if not already defined
if(!defined('FRONKDB_SQLDEBUG')) {
define('FRONKDB_SQLDEBUG', false);
}
// Load required classes
require_once(LIBDIR."autoloader/autoloader.php");
require_once(LIBDIR."mvcfronk/mfLog/mfLoghandler.php");
require_once(LIBDIR."FronkDB/FronkDB.php");
// Get database table count
$tableCount = 0;
$db = null;
try {
$db = new FronkDB(
FRONKDB_DBHOST,
FRONKDB_DBUSER,
FRONKDB_DBPASS,
FRONKDB_DBNAME
);
// Query to get table count
$result = $db->query("SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = '".FRONKDB_DBNAME."'");
if($result) {
$row = mysqli_fetch_assoc($result);
if($row) {
$tableCount = (int)$row['count'];
}
}
} catch(Exception $e) {
header("Content-Type: application/json");
http_response_code(500);
echo json_encode(["status" => "error", "message" => "Database error: " . $e->getMessage()]);
exit;
$tableCount = 0;
}
// Return JSON response
header("Content-Type: application/json");
http_response_code(200);
echo json_encode([
"status" => "ok",
"tables" => $tableCount
]);
header('Content-Type: application/json');
echo json_encode(['tables' => $tableCount]);