module change
This commit is contained in:
@@ -8,15 +8,11 @@ $pdo = modules()->modulePdo('kea', $fallback);
|
||||
$hosts = [];
|
||||
$error = null;
|
||||
|
||||
if ($pdo) {
|
||||
try {
|
||||
$repo = new KeaHostRepository($pdo);
|
||||
$hosts = $repo->findAll(50);
|
||||
} catch (\Exception $e) {
|
||||
$error = "Datenbankfehler: " . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$error = "Modul nicht konfiguriert. Bitte Setup ausführen.";
|
||||
try {
|
||||
$repo = new KeaHostRepository($pdo);
|
||||
$hosts = $repo->findAll(50);
|
||||
} catch (\Exception $e) {
|
||||
$error = "Datenbankfehler: " . $e->getMessage();
|
||||
}
|
||||
|
||||
module_tpl('kea', 'dashboard', compact('hosts', 'error'));
|
||||
|
||||
@@ -111,8 +111,23 @@ if ($targetReal && $retoolBase && str_starts_with($targetReal, $retoolBase)) {
|
||||
// ------------------------------------
|
||||
// Erst Inhalt laden (ohne Ausgabe), damit Header/Redirects vor HTML funktionieren
|
||||
ob_start();
|
||||
require $target;
|
||||
$content = ob_get_clean();
|
||||
try {
|
||||
require $target;
|
||||
$content = ob_get_clean();
|
||||
} catch (\App\ModuleConfigException $e) {
|
||||
ob_end_clean();
|
||||
http_response_code(412);
|
||||
$moduleName = $e->module();
|
||||
$module = app()->modules()->get($moduleName);
|
||||
$title = $module['title'] ?? $moduleName;
|
||||
$setupUrl = '/modules/setup/' . rawurlencode($moduleName);
|
||||
$content = '<div class="card">' .
|
||||
'<div class="pill">' . e($title) . '</div>' .
|
||||
'<h1 style="margin-top:.75rem;">Setup erforderlich</h1>' .
|
||||
'<p class="muted">' . e($e->getMessage()) . '</p>' .
|
||||
'<div style="margin-top:1rem;"><a class="nav-link" href="' . e($setupUrl) . '">Zum Setup</a></div>' .
|
||||
'</div>';
|
||||
}
|
||||
|
||||
// Wenn bereits Header gesendet wurden (z. B. eigener Redirect/Content-Type), Layout überspringen
|
||||
if (headers_sent()) {
|
||||
|
||||
32
src/App/ModuleConfigException.php
Normal file
32
src/App/ModuleConfigException.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App;
|
||||
|
||||
final class ModuleConfigException extends \RuntimeException
|
||||
{
|
||||
private string $module;
|
||||
private ?string $details;
|
||||
|
||||
public function __construct(
|
||||
string $module,
|
||||
string $message,
|
||||
?string $details = null,
|
||||
int $code = 0,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->module = $module;
|
||||
$this->details = $details;
|
||||
}
|
||||
|
||||
public function module(): string
|
||||
{
|
||||
return $this->module;
|
||||
}
|
||||
|
||||
public function details(): ?string
|
||||
{
|
||||
return $this->details;
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,10 @@ final class ModuleManager
|
||||
$settings = $this->settings($name);
|
||||
$db = $settings['db'] ?? $fallback;
|
||||
if (!is_array($db) || empty($db)) {
|
||||
return null;
|
||||
throw new ModuleConfigException(
|
||||
$name,
|
||||
'Modul nicht konfiguriert. Bitte Setup ausfuehren.'
|
||||
);
|
||||
}
|
||||
|
||||
if (!isset($db['options'])) {
|
||||
@@ -123,15 +126,49 @@ final class ModuleManager
|
||||
];
|
||||
}
|
||||
|
||||
$pdo = Database::createFromArray($db);
|
||||
try {
|
||||
$pdo = Database::createFromArray($db);
|
||||
} catch (\Throwable $e) {
|
||||
if (defined('APP_DEBUG_TOOL') && APP_DEBUG_TOOL) {
|
||||
@file_put_contents(
|
||||
__DIR__ . '/../../debug/module_db_error.log',
|
||||
'[' . date('c') . '] ' . $name . ': ' . $e->getMessage() . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
}
|
||||
throw new ModuleConfigException(
|
||||
$name,
|
||||
'Modul-Datenbank nicht korrekt konfiguriert.',
|
||||
$e->getMessage(),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
if ($name === 'kea' && !empty($settings['kea_auto_init'])) {
|
||||
Database::ensureKeaSchema($pdo, [
|
||||
'auto_init' => true,
|
||||
'init_cmd' => $settings['kea_init_cmd'] ?? null,
|
||||
'init_script' => $settings['kea_init_script'] ?? null,
|
||||
'kea_db_version' => $settings['kea_db_version'] ?? '',
|
||||
]);
|
||||
try {
|
||||
Database::ensureKeaSchema($pdo, [
|
||||
'auto_init' => true,
|
||||
'init_cmd' => $settings['kea_init_cmd'] ?? null,
|
||||
'init_script' => $settings['kea_init_script'] ?? null,
|
||||
'kea_db_version' => $settings['kea_db_version'] ?? '',
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
if (defined('APP_DEBUG_TOOL') && APP_DEBUG_TOOL) {
|
||||
@file_put_contents(
|
||||
__DIR__ . '/../../debug/module_db_error.log',
|
||||
'[' . date('c') . '] ' . $name . ': ' . $e->getMessage() . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
}
|
||||
throw new ModuleConfigException(
|
||||
$name,
|
||||
'Modul-Datenbank nicht korrekt konfiguriert.',
|
||||
$e->getMessage(),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $pdo;
|
||||
|
||||
Reference in New Issue
Block a user