Asked for: the legion collects dues in Kina; a separate, purely administrative page to set a cycle and an amount, tick off who has paid, exempt members for one or more cycles and suspend a cycle for everyone. On the site it is called "Legionsbeiträge" and the currency "Kina", like everywhere else. - includes/dues.php: settings dues_amount/_unit/_every/_start/_anchor (every 1-12 weeks or months). The cycles (dues_cycles) form a series from the anchor (months on the same day, in shorter months the last one) and exist up to the running one plus the next. Until something is ticked or suspended, a new setting rebuilds all cycles; afterwards a new amount applies to the coming cycles (optionally the running one) and a new rhythm starts after the last cycle that has begun or has data. The amount also takes 500k, 1,5kk or 2 Mio. - Who owes: every active account that was a member when the cycle started (Discord join, else account creation), unless exempt or the cycle is suspended; a ticked payment always counts. Former members only show up with payments in the visible cycles. - admin/dues.php: key figures (running cycle, paid, collected of expected, arrears), a table of members x the last six cycles with paging, a click toggles a payment (dues_entries with who and when; without reload via assets/js/dues.js, the button sends the state it sets), search and filters (open, paid, exempt, arrears), suspend/resume per cycle with an optional reason, exemptions (dues_exemptions: members, from which cycle, 1-12 cycles or until further notice, reason; end or delete) and the settings. On phones the table opens at the running cycle, the exemption list stacks. - admin/dues_action.php: settings, toggle (JSON with the redrawn cell, column figures, arrears and key figures), cycle, exempt_add/_end/_delete. Settings, suspensions and exemptions go to the audit log and the Discord log channel, ticks only to the audit log (area "Legionsbeiträge"); ticking is exempt from the general form rate limit. - New right dues.manage (Administrator and the groups with roles.manage), menu item in the admin section with a coins icon, schema version 61 (tables also in sql/schema.sql). - Privacy: privacy policy (what is stored, only the leadership sees it, account deletion), data export section legionsbeitraege, account deletion removes exemptions and keeps payments without the name, data reset area. - Patch notes (leadership) and README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
272 lines
12 KiB
PHP
272 lines
12 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'],
|
|
],
|
|
'dues' => [
|
|
'label' => 'Legionsbeiträge',
|
|
'description' => 'Alle Zyklen mit den abgehakten Zahlungen, ausgesetzte Zyklen und alle Befreiungen. Betrag und Rhythmus bleiben eingestellt - die Zyklen entstehen ab dem eingestellten Beginn neu.',
|
|
'count' => 'SELECT (SELECT COUNT(*) FROM dues_entries) + (SELECT COUNT(*) FROM dues_exemptions)',
|
|
'unit' => ['Eintrag', 'Einträge'],
|
|
'delete' => [
|
|
'DELETE FROM dues_exemptions', 'DELETE FROM dues_entries', 'DELETE FROM dues_cycles',
|
|
// Die Reihe beginnt wieder beim eingestellten Beginn (nach einem geaenderten Rhythmus lag ihr Anker spaeter)
|
|
"UPDATE settings a JOIN settings s ON s.`key` = 'dues_start' SET a.value = s.value WHERE a.`key` = 'dues_anchor'",
|
|
],
|
|
'reset_ids' => ['dues_exemptions', 'dues_cycles'],
|
|
],
|
|
'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 und Premade-Banner, die auf ein Galeriebild zeigen, gibt es danach nicht mehr
|
|
"UPDATE users SET profile_background = NULL WHERE profile_background LIKE 'gallery:%'",
|
|
"DELETE FROM premade_banners WHERE banner 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 AND premade_id IS NULL)",
|
|
'DELETE FROM member_gallery WHERE is_background = 1 AND premade_id IS NULL',
|
|
'UPDATE users SET profile_bio = NULL, profile_background = NULL',
|
|
],
|
|
'reset_ids' => [],
|
|
],
|
|
'gear_sets' => [
|
|
'label' => 'Gear-Planer: Sets',
|
|
'description' => 'Alle Ausrüstungssets der Mitglieder samt geplanter Skills. Der Katalog der Gegenstände und Skills 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 AND premade_id IS NULL')->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));
|
|
}
|