module change
This commit is contained in:
@@ -8,15 +8,11 @@ $pdo = modules()->modulePdo('kea', $fallback);
|
|||||||
$hosts = [];
|
$hosts = [];
|
||||||
$error = null;
|
$error = null;
|
||||||
|
|
||||||
if ($pdo) {
|
try {
|
||||||
try {
|
$repo = new KeaHostRepository($pdo);
|
||||||
$repo = new KeaHostRepository($pdo);
|
$hosts = $repo->findAll(50);
|
||||||
$hosts = $repo->findAll(50);
|
} catch (\Exception $e) {
|
||||||
} catch (\Exception $e) {
|
$error = "Datenbankfehler: " . $e->getMessage();
|
||||||
$error = "Datenbankfehler: " . $e->getMessage();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$error = "Modul nicht konfiguriert. Bitte Setup ausführen.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module_tpl('kea', 'dashboard', compact('hosts', 'error'));
|
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
|
// Erst Inhalt laden (ohne Ausgabe), damit Header/Redirects vor HTML funktionieren
|
||||||
ob_start();
|
ob_start();
|
||||||
require $target;
|
try {
|
||||||
$content = ob_get_clean();
|
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
|
// Wenn bereits Header gesendet wurden (z. B. eigener Redirect/Content-Type), Layout überspringen
|
||||||
if (headers_sent()) {
|
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);
|
$settings = $this->settings($name);
|
||||||
$db = $settings['db'] ?? $fallback;
|
$db = $settings['db'] ?? $fallback;
|
||||||
if (!is_array($db) || empty($db)) {
|
if (!is_array($db) || empty($db)) {
|
||||||
return null;
|
throw new ModuleConfigException(
|
||||||
|
$name,
|
||||||
|
'Modul nicht konfiguriert. Bitte Setup ausfuehren.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($db['options'])) {
|
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'])) {
|
if ($name === 'kea' && !empty($settings['kea_auto_init'])) {
|
||||||
Database::ensureKeaSchema($pdo, [
|
try {
|
||||||
'auto_init' => true,
|
Database::ensureKeaSchema($pdo, [
|
||||||
'init_cmd' => $settings['kea_init_cmd'] ?? null,
|
'auto_init' => true,
|
||||||
'init_script' => $settings['kea_init_script'] ?? null,
|
'init_cmd' => $settings['kea_init_cmd'] ?? null,
|
||||||
'kea_db_version' => $settings['kea_db_version'] ?? '',
|
'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;
|
return $pdo;
|
||||||
|
|||||||
Reference in New Issue
Block a user