- Raids: "Max. Spieler" only whole numbers up to groups x 5 (max. 10 groups / 50), gearscore only a number; fixed +1 Lumipunkt per participation, other values only with the new raids.points permission; pick an existing premade per group when creating a raid; unchanged legacy values no longer block editing - Raid page updates itself every 15 s while visible (raids_live.php, cards rendered by includes/raid_card.php), open editors and confirm dialogs are kept - Restore takes the new raid_id from the bot (archived messages are now deleted in Discord) and moves settings, attendance and awards; website signups send the server display name - Premades: dissolve by leadership needs a reason, lead gets DMs on join/assign/decline/remove (source/actor_id sent to the bot), transfer picker skips players who already lead a group, website accept keeps the one-group rule, no commas in names - Site-wide Lumina dialog (assets/js/confirm-dialog.js) replaces confirm/prompt/alert via data-confirm; error flashes are a dialog you confirm with OK - Calendar: audience per entry (all / leadership takes part / internal) with the new calendar.leadership permission; day cells list all entries and scroll - Gear planner: main-hand picker filtered by the set's class, mismatches marked, "keine Klasse" option, link to an external skill/Daevanion plan per set - Map: correct kisk icons (Elyos on Verteron/Abyss, Altgard fixed), per-map max zoom and bounded panning, German texts, data source note - Tactics: toolbar as a uniform grid, whole-tactic copy, automatic versions with restore and a 90-day trash, official tactics protected - Global thin gold scrollbars, readable hover colours, "Sedes Luminis" spelling, patch notes and README, schema version 34 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
259 lines
11 KiB
PHP
259 lines
11 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Daten zuruecksetzen (nur Entwickler, /admin/reset.php): Testdaten einzelner Bereiche auf einen
|
|
* Schlag loeschen. Konten, Gruppen, Rechte und Einstellungen bleiben immer erhalten - ebenso
|
|
* alles, was beim Bot liegt (Raids, Events, Premades).
|
|
*/
|
|
|
|
require_once __DIR__ . '/member_profile.php';
|
|
require_once __DIR__ . '/wiki.php';
|
|
require_once __DIR__ . '/bugs.php';
|
|
|
|
/**
|
|
* Bereiche: Schluessel => Beschriftung, Beschreibung, Zaehl-Abfrage und die Loeschbefehle
|
|
* (in dieser Reihenfolge, wegen der Fremdschluessel).
|
|
*/
|
|
const DATA_RESET_AREAS = [
|
|
'contributions' => [
|
|
'label' => 'Lumipunkte',
|
|
'description' => 'Alle Vergaben und Abzüge - jeder Punktestand steht danach auf 0.',
|
|
'count' => 'SELECT COUNT(*) FROM contribution_awards',
|
|
'unit' => ['Vergabe', 'Vergaben'],
|
|
'delete' => ['DELETE FROM contribution_entries', 'DELETE FROM contribution_awards'],
|
|
'reset_ids' => ['contribution_entries', 'contribution_awards'],
|
|
],
|
|
'shop_orders' => [
|
|
'label' => 'Lumishop: Anträge',
|
|
'description' => 'Alle Anträge der Mitglieder (offen, bewilligt, ausgegeben, abgelehnt). Punkte und Bestand werden dabei nicht zurückgebucht.',
|
|
'count' => 'SELECT COUNT(*) FROM shop_orders',
|
|
'unit' => ['Antrag', 'Anträge'],
|
|
'delete' => ['DELETE FROM shop_orders'],
|
|
'reset_ids' => ['shop_orders'],
|
|
],
|
|
'shop_items' => [
|
|
'label' => 'Lumishop: Angebot',
|
|
'description' => 'Alle Gegenstände und Kategorien im Shop. Alte Anträge behalten Name und Preis.',
|
|
'count' => 'SELECT COUNT(*) FROM shop_items',
|
|
'unit' => ['Gegenstand', 'Gegenstände'],
|
|
'delete' => ['DELETE FROM shop_items', 'DELETE FROM shop_categories'],
|
|
'reset_ids' => ['shop_items', 'shop_categories'],
|
|
],
|
|
'warehouse' => [
|
|
'label' => 'Lagerhaus',
|
|
'description' => 'Alle Einlagerungen und Entnahmen (Bestand danach überall 0) und selbst angelegte Gegenstände. Die Gegenstände aus dem Aion-Wiki bleiben.',
|
|
'count' => 'SELECT COUNT(*) FROM warehouse_movements',
|
|
'unit' => ['Buchung', 'Buchungen'],
|
|
'delete' => ['DELETE FROM warehouse_movements', "DELETE FROM warehouse_items WHERE source = 'custom'"],
|
|
'reset_ids' => ['warehouse_movements'],
|
|
],
|
|
'raid_attendance' => [
|
|
'label' => 'Raid-Anwesenheit',
|
|
'description' => 'Anwesenheitslisten und Punkte-Einstellungen der Raids. Die Raids selbst liegen beim Bot und bleiben.',
|
|
'count' => 'SELECT (SELECT COUNT(*) FROM raid_attendance) + (SELECT COUNT(*) FROM raid_settings)',
|
|
'unit' => ['Eintrag', 'Einträge'],
|
|
'delete' => ['DELETE FROM raid_attendance', 'DELETE FROM raid_settings'],
|
|
'reset_ids' => [],
|
|
],
|
|
'tactics' => [
|
|
'label' => 'Taktiken (Karte)',
|
|
'description' => 'Alle Taktiken mit ihren Schritten und Zeichnungen, dazu Verlauf und Papierkorb (gesicherte Stände, gelöschte Taktiken).',
|
|
'count' => 'SELECT COUNT(*) FROM tactics',
|
|
'unit' => ['Taktik', 'Taktiken'],
|
|
// tactic_revisions hat keinen Fremdschluessel auf tactics - muss eigens geleert werden
|
|
'delete' => ['DELETE FROM tactic_revisions', 'DELETE FROM tactics'],
|
|
'reset_ids' => ['tactic_shapes', 'tactic_steps', 'tactics', 'tactic_revisions'],
|
|
],
|
|
'calendar' => [
|
|
'label' => 'Kalender-Termine',
|
|
'description' => 'Von Mitgliedern eingetragene Termine samt Teilnehmern und Meldungen. Raids und Events aus dem Bot bleiben.',
|
|
'count' => 'SELECT COUNT(*) FROM calendar_entries',
|
|
'unit' => ['Termin', 'Termine'],
|
|
'delete' => ["DELETE FROM content_reports WHERE content_type = 'calendar'", 'DELETE FROM calendar_entries'],
|
|
'reset_ids' => ['calendar_entries'],
|
|
],
|
|
'gallery' => [
|
|
'label' => 'Profil-Galerien',
|
|
'description' => 'Alle Galeriebilder (auch die Dateien), Kommentare, Reaktionen und Meldungen dazu.',
|
|
'count' => 'SELECT COUNT(*) FROM member_gallery',
|
|
'unit' => ['Bild', 'Bilder'],
|
|
'delete' => [
|
|
"DELETE FROM content_reports WHERE content_type IN ('picture', 'comment')",
|
|
"DELETE FROM reactions WHERE content_type IN ('picture', 'comment')",
|
|
'DELETE FROM gallery_comments',
|
|
'DELETE FROM member_gallery',
|
|
// Profil-Hintergruende, die auf ein Galeriebild zeigen, gibt es danach nicht mehr
|
|
"UPDATE users SET profile_background = NULL WHERE profile_background LIKE 'gallery:%'",
|
|
],
|
|
'reset_ids' => ['gallery_comments', 'member_gallery', 'reactions'],
|
|
],
|
|
'characters' => [
|
|
'label' => 'Charaktere',
|
|
'description' => 'Alle Charaktere auf den Profilseiten mit Portraits und Bildern.',
|
|
'count' => 'SELECT COUNT(*) FROM member_characters',
|
|
'unit' => ['Charakter', 'Charaktere'],
|
|
'delete' => ['DELETE FROM member_characters'],
|
|
'reset_ids' => ['member_characters'],
|
|
],
|
|
'profiles' => [
|
|
'label' => 'Profiltexte & Hintergründe',
|
|
'description' => 'Beschreibungstexte, gewählte Hintergründe und eigene Hintergrundbilder aller Profilseiten. Konten, Profilbilder und Galerien bleiben.',
|
|
'count' => "SELECT COUNT(*) FROM users WHERE (profile_bio IS NOT NULL AND profile_bio <> '') OR profile_background IS NOT NULL",
|
|
'unit' => ['Profil', 'Profile'],
|
|
'delete' => [
|
|
"DELETE FROM content_reports WHERE content_type = 'picture' AND content_id IN (SELECT id FROM member_gallery WHERE is_background = 1)",
|
|
'DELETE FROM member_gallery WHERE is_background = 1',
|
|
'UPDATE users SET profile_bio = NULL, profile_background = NULL',
|
|
],
|
|
'reset_ids' => [],
|
|
],
|
|
'gear_sets' => [
|
|
'label' => 'Gear-Planer: Sets',
|
|
'description' => 'Alle Ausrüstungssets der Mitglieder. Der Katalog der Gegenstände bleibt.',
|
|
'count' => 'SELECT COUNT(*) FROM gear_sets',
|
|
'unit' => ['Set', 'Sets'],
|
|
'delete' => ['DELETE FROM gear_sets'],
|
|
'reset_ids' => ['gear_sets'],
|
|
],
|
|
'wiki' => [
|
|
'label' => 'Wiki',
|
|
'description' => 'Alle Seiten, Versionen, Bilder und Mitwirkenden. Der Einsteiger-Guide lässt sich danach im Wiki neu übernehmen.',
|
|
'count' => 'SELECT COUNT(*) FROM wiki_pages',
|
|
'unit' => ['Seite', 'Seiten'],
|
|
'delete' => ['DELETE FROM wiki_revisions', 'DELETE FROM wiki_contributors', 'UPDATE wiki_pages SET parent_id = NULL', 'DELETE FROM wiki_pages'],
|
|
'reset_ids' => ['wiki_revisions', 'wiki_pages'],
|
|
],
|
|
'bugs' => [
|
|
'label' => 'Fehlermeldungen',
|
|
'description' => 'Alle eingegangenen Fehlermeldungen samt angehängter Bilder.',
|
|
'count' => 'SELECT COUNT(*) FROM bug_reports',
|
|
'unit' => ['Meldung', 'Meldungen'],
|
|
'delete' => ['DELETE FROM bug_reports'],
|
|
'reset_ids' => ['bug_report_images', 'bug_reports'],
|
|
],
|
|
'tour' => [
|
|
'label' => 'Einführungstour',
|
|
'description' => 'Allen Mitgliedern die Dashboard-Einführung beim nächsten Besuch erneut zeigen.',
|
|
'count' => 'SELECT COUNT(*) FROM users WHERE tour_completed_at IS NOT NULL',
|
|
'unit' => ['Konto', 'Konten'],
|
|
'delete' => ['UPDATE users SET tour_completed_at = NULL'],
|
|
'reset_ids' => [],
|
|
],
|
|
'audit' => [
|
|
'label' => 'Audit-Log & Tempolimits',
|
|
'description' => 'Alle bisherigen Einträge im Audit-Log und die Zähler des Spam-Schutzes. Das Zurücksetzen selbst wird danach als erster Eintrag protokolliert.',
|
|
'count' => 'SELECT COUNT(*) FROM audit_log',
|
|
'unit' => ['Eintrag', 'Einträge'],
|
|
'delete' => ['DELETE FROM audit_log', 'DELETE FROM rate_limits'],
|
|
'reset_ids' => ['audit_log', 'rate_limits'],
|
|
],
|
|
];
|
|
|
|
/** Wort, das zur Bestaetigung eingetippt werden muss. */
|
|
const DATA_RESET_CONFIRM_WORD = 'ZURÜCKSETZEN';
|
|
|
|
/** @return array<string, int> Anzahl der Eintraege je Bereich */
|
|
function data_reset_counts(): array
|
|
{
|
|
$counts = [];
|
|
foreach (DATA_RESET_AREAS as $key => $area) {
|
|
try {
|
|
$counts[$key] = (int) db()->query($area['count'])->fetchColumn();
|
|
} catch (PDOException $e) {
|
|
$counts[$key] = 0;
|
|
}
|
|
}
|
|
return $counts;
|
|
}
|
|
|
|
/** "1 Bild" / "12 Bilder" */
|
|
function data_reset_amount(string $key, int $count): string
|
|
{
|
|
[$one, $many] = DATA_RESET_AREAS[$key]['unit'];
|
|
return number_format($count, 0, ',', '.') . ' ' . ($count === 1 ? $one : $many);
|
|
}
|
|
|
|
/**
|
|
* Setzt die gewaehlten Bereiche zurueck - alles in einer Transaktion, danach werden die
|
|
* zugehoerigen Dateien entfernt und die IDs wieder bei 1 begonnen.
|
|
*
|
|
* @param string[] $keys
|
|
* @return array<string, int> geloeschte Eintraege je Bereich (Stand vor dem Loeschen)
|
|
*/
|
|
function data_reset_run(array $keys): array
|
|
{
|
|
$keys = array_values(array_filter($keys, static fn ($key): bool => isset(DATA_RESET_AREAS[$key])));
|
|
$pdo = db();
|
|
$counts = data_reset_counts();
|
|
|
|
// Dateien merken, bevor die Zeilen weg sind
|
|
$files = [];
|
|
if (in_array('gallery', $keys, true)) {
|
|
$files = array_merge($files, $pdo->query('SELECT filename FROM member_gallery')->fetchAll(PDO::FETCH_COLUMN));
|
|
}
|
|
if (in_array('profiles', $keys, true) && !in_array('gallery', $keys, true)) {
|
|
$files = array_merge($files, $pdo->query('SELECT filename FROM member_gallery WHERE is_background = 1')->fetchAll(PDO::FETCH_COLUMN));
|
|
}
|
|
if (in_array('characters', $keys, true)) {
|
|
foreach ($pdo->query('SELECT portrait_filename, image_filename FROM member_characters')->fetchAll() as $row) {
|
|
$files[] = $row['portrait_filename'];
|
|
$files[] = $row['image_filename'];
|
|
}
|
|
}
|
|
|
|
$bugFiles = [];
|
|
if (in_array('bugs', $keys, true)) {
|
|
try {
|
|
$bugFiles = $pdo->query('SELECT filename FROM bug_report_images')->fetchAll(PDO::FETCH_COLUMN);
|
|
} catch (PDOException $e) {
|
|
$bugFiles = [];
|
|
}
|
|
}
|
|
|
|
$pdo->beginTransaction();
|
|
try {
|
|
foreach ($keys as $key) {
|
|
foreach (DATA_RESET_AREAS[$key]['delete'] as $sql) {
|
|
$pdo->exec($sql);
|
|
}
|
|
}
|
|
$pdo->commit();
|
|
} catch (Throwable $e) {
|
|
if ($pdo->inTransaction()) {
|
|
$pdo->rollBack();
|
|
}
|
|
throw $e;
|
|
}
|
|
|
|
foreach ($files as $filename) {
|
|
profile_delete_file($filename);
|
|
}
|
|
foreach ($bugFiles as $filename) {
|
|
if (strpos((string) $filename, '/') === false && is_file(BUG_UPLOAD_DIR . $filename)) {
|
|
@unlink(BUG_UPLOAD_DIR . $filename);
|
|
}
|
|
}
|
|
if (in_array('wiki', $keys, true) && is_dir(WIKI_UPLOAD_DIR)) {
|
|
foreach (scandir(WIKI_UPLOAD_DIR) ?: [] as $name) {
|
|
// .htaccess/index-Dateien des Ordners bleiben
|
|
if ($name[0] !== '.' && !str_starts_with($name, 'index.') && is_file(WIKI_UPLOAD_DIR . $name)) {
|
|
@unlink(WIKI_UPLOAD_DIR . $name);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Neue Eintraege beginnen wieder bei #1 (ALTER TABLE beendet Transaktionen, deshalb danach;
|
|
// MySQL nimmt automatisch die naechste freie Nummer, falls noch Zeilen uebrig sind).
|
|
foreach ($keys as $key) {
|
|
foreach (DATA_RESET_AREAS[$key]['reset_ids'] as $table) {
|
|
try {
|
|
$pdo->exec("ALTER TABLE `$table` AUTO_INCREMENT = 1");
|
|
} catch (PDOException $e) {
|
|
// nicht wichtig - dann laufen die Nummern eben weiter
|
|
}
|
|
}
|
|
}
|
|
|
|
return array_intersect_key($counts, array_flip($keys));
|
|
}
|