130 lines
4.9 KiB
PHP
130 lines
4.9 KiB
PHP
<?php
|
|
require_admin();
|
|
|
|
$GLOBALS['layout_header_base_title'] = 'Modulverwaltung';
|
|
$GLOBALS['layout_header_title'] = 'Modulverwaltung';
|
|
$GLOBALS['layout_header_context'] = 'SQL-Import';
|
|
$GLOBALS['layout_header_text'] = '';
|
|
$GLOBALS['layout_header_actions'] = [];
|
|
|
|
$service = new \App\ModuleSqlImportService(modules());
|
|
$availableModules = $service->importableModules();
|
|
$selectedModule = (string) ($_POST['module'] ?? ($_GET['module'] ?? ''));
|
|
$error = null;
|
|
$notice = null;
|
|
$result = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
try {
|
|
if (!isset($_FILES['sql_file']) || !is_array($_FILES['sql_file'])) {
|
|
throw new RuntimeException('Bitte eine SQL-Datei auswählen.');
|
|
}
|
|
|
|
$result = $service->importUploadedFile($selectedModule, $_FILES['sql_file']);
|
|
$notice = sprintf(
|
|
'%s %d Statements aus %s wurden nach %s importiert.',
|
|
(string) ($result['message'] ?? 'Import erfolgreich.'),
|
|
(int) ($result['statement_count'] ?? 0),
|
|
(string) ($result['file'] ?? 'der Datei'),
|
|
(string) ($result['target_label'] ?? 'der Ziel-Datenbank')
|
|
);
|
|
} catch (Throwable $exception) {
|
|
$error = $exception->getMessage();
|
|
}
|
|
}
|
|
?>
|
|
<div class="module-flow">
|
|
<?php if ($error): ?>
|
|
<div class="module-box-soft bg-red-900 border-l-4 border-red-500 text-red-100" role="alert">
|
|
<?= e($error) ?>
|
|
</div>
|
|
<?php elseif ($notice): ?>
|
|
<div class="module-box-soft" style="border-color:var(--accent-2);">
|
|
<?= e($notice) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="submenu-box">
|
|
<div class="module-hero-top module-hero-top--compact">
|
|
<nav class="module-tabs" aria-label="Modulverwaltung">
|
|
<a class="module-button module-button--tab" href="/modules">Aktive Module</a>
|
|
<a class="module-button module-button--tab" href="/modules/install">Module installieren/aktivieren</a>
|
|
<a class="module-button module-button--tab-active" href="/modules/sql-import">Zentralen SQL-Import</a>
|
|
</nav>
|
|
<div class="module-submenu-actions">
|
|
<a class="module-button module-button--secondary module-button--small" href="/">Nexus Übersicht</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<section class="section-box">
|
|
<div class="module-box-head">
|
|
<div>
|
|
<h2 class="module-box-title">Zentraler SQL-Import</h2>
|
|
<p>Gemeinsame Standard-Lösung für Module mit SQL-Upload in die konfigurierte Ziel-Datenbank.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($availableModules === []): ?>
|
|
<div class="card-box">
|
|
Aktuell ist kein Modul für den generischen SQL-Import vorbereitet.
|
|
</div>
|
|
<?php else: ?>
|
|
<form method="post" enctype="multipart/form-data" class="section-box" style="padding:0; border:0; box-shadow:none; background:transparent;">
|
|
<div style="display:grid; gap:1rem;">
|
|
<label style="display:grid; gap:.35rem;">
|
|
<span>Modul</span>
|
|
<select name="module" required>
|
|
<option value="">Bitte wählen</option>
|
|
<?php foreach ($availableModules as $module): ?>
|
|
<option value="<?= e($module['name']) ?>" <?= $selectedModule === $module['name'] ? 'selected' : '' ?>>
|
|
<?= e($module['title']) ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</label>
|
|
|
|
<label style="display:grid; gap:.35rem;">
|
|
<span>SQL-Datei</span>
|
|
<input type="file" name="sql_file" accept=".sql,text/sql,application/sql" required>
|
|
</label>
|
|
|
|
<div class="muted" style="font-size:.95rem;">
|
|
Der generische Import nutzt die Standard-Datenbankverbindung des Moduls oder einen optionalen Modul-Callback für Spezialfälle.
|
|
</div>
|
|
|
|
<div style="display:flex; gap:10px; flex-wrap:wrap;">
|
|
<button class="cta-button" type="submit">SQL importieren</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
<?php endif; ?>
|
|
</section>
|
|
|
|
<?php if ($availableModules !== []): ?>
|
|
<section class="section-box">
|
|
<div class="module-box-head">
|
|
<div>
|
|
<h2 class="module-box-title">Importierbare Module</h2>
|
|
<p>Schnelleinstieg für den Import mit bereits vorausgewähltem Modul.</p>
|
|
</div>
|
|
</div>
|
|
<div class="module-admin-grid module-admin-grid--compact">
|
|
<?php foreach ($availableModules as $module): ?>
|
|
<article class="card-box module-admin-card">
|
|
<div class="module-admin-card__head">
|
|
<div class="module-admin-card__title">
|
|
<h2><?= e($module['title']) ?></h2>
|
|
<p><?= e($module['description']) ?></p>
|
|
</div>
|
|
</div>
|
|
<div class="module-admin-actions">
|
|
<a class="nav-link" href="/modules/sql-import?module=<?= e($module['name']) ?>">Für dieses Modul importieren</a>
|
|
</div>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
</div>
|