- Discord sync (login and live check) stores every class role of a member in users.classes (role names match the classes, German and English names are recognised); users.class_name is the main class: the one chosen in the profile (users.main_class) while the member still has it, otherwise the highest class role; no class role means no class - The guild role list is fetched once per request and kept when the bot is briefly unreachable (it used to be emptied); nothing is changed while the role list is unknown - Profile: the manual class select is gone; new "Klassen" card with the detected classes, main class choice for members with several classes and a "Jetzt mit Discord abgleichen" button (at most every 30 s and 10 per hour, new security bucket discord_sync with a log entry) - Main class first on the profile page, in the member list (the class filter also finds secondary classes), in the raid signup and premade class pickers (own classes first, main preselected for new raid signups) - Berechtigungsgruppen shows which Discord roles count as classes - Schema version 36 (users.classes filled from class_name until the first sync, users.main_class), patch notes, README Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
856 lines
42 KiB
PHP
856 lines
42 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Bringt eine bestehende Datenbank auf den Stand, den der Code erwartet. Frueher standen
|
|
* dafuer ALTER-Befehle in der README, die von Hand in phpMyAdmin auszufuehren waren - fuer
|
|
* den Discord-Login geht das nicht mehr, weil schon die Login-Seite die neuen Spalten
|
|
* braucht (ohne sie koennte sich niemand mehr anmelden, auch kein Administrator).
|
|
*
|
|
* Geprueft wird einmal pro Sitzung; ist alles da, kostet das eine einzige Abfrage.
|
|
*/
|
|
|
|
// Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu.
|
|
const SCHEMA_VERSION = 36;
|
|
|
|
/**
|
|
* Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql).
|
|
*/
|
|
function schema_table_upgrades(): array
|
|
{
|
|
return [
|
|
// Verlauf und Papierkorb der Taktiken (includes/tactics.php) - ohne Fremdschluessel auf
|
|
// tactics, damit die Sicherung das Loeschen der Taktik ueberlebt.
|
|
'tactic_revisions' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS tactic_revisions (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
tactic_id INT UNSIGNED NOT NULL,
|
|
map_slug VARCHAR(60) NOT NULL,
|
|
name VARCHAR(120) NOT NULL,
|
|
-- So war die Taktik beim Sichern - danach richten sich die Rechte, auch nach dem Loeschen
|
|
visibility ENUM('private', 'public') NOT NULL,
|
|
highlight ENUM('none', 'recommended', 'official') NOT NULL DEFAULT 'none',
|
|
owner_id INT UNSIGNED NULL,
|
|
-- edit = vor einer Aenderung, delete = vor dem Loeschen, restore = vor dem Wiederherstellen
|
|
reason ENUM('edit', 'delete', 'restore') NOT NULL DEFAULT 'edit',
|
|
step_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
shape_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
-- JSON: Felder der Taktik und die Schritte in Reihenfolge samt Zeichnungen (tactic_export)
|
|
snapshot MEDIUMTEXT NOT NULL,
|
|
created_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_tactic_revisions_tactic (tactic_id, created_at),
|
|
INDEX idx_tactic_revisions_map (map_slug, reason)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
// Lumipunkte fuer "Ich bin da" beim Aktivitaetscheck (includes/activity_points.php)
|
|
'activity_settings' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS activity_settings (
|
|
-- ID des Aktivitaetschecks beim Bot
|
|
check_id INT UNSIGNED NOT NULL PRIMARY KEY,
|
|
-- Lumipunkte fuer "Ich bin da", vergeben nach dem Abschluss (includes/activity_points.php)
|
|
points_present INT UNSIGNED NOT NULL DEFAULT 0,
|
|
-- Ende der Frist: ab dann wird beim Bot nachgesehen, ob der Check abgeschlossen ist
|
|
deadline_at DATETIME NOT NULL,
|
|
processed_at DATETIME NULL,
|
|
result VARCHAR(255) NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
SQL,
|
|
// Bilder an Fehlermeldungen (includes/bugs.php)
|
|
'bug_report_images' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS bug_report_images (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
bug_id INT UNSIGNED NOT NULL,
|
|
-- Datei unter assets/uploads/bugs/ (nur ueber /bug_image.php abrufbar)
|
|
filename VARCHAR(120) NOT NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (bug_id) REFERENCES bug_reports(id) ON DELETE CASCADE,
|
|
INDEX idx_bug_report_images_bug (bug_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
SQL,
|
|
// Gear-Planer (includes/gear.php)
|
|
'gear_items' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS gear_items (
|
|
-- Gegenstands-ID aus dem Spiel (wie bei aion2hub.com/database/items/<ID>)
|
|
id INT UNSIGNED NOT NULL PRIMARY KEY,
|
|
name VARCHAR(150) NOT NULL,
|
|
-- Weapons, Armor, Accessories
|
|
category VARCHAR(20) NOT NULL,
|
|
-- Slot laut Spiel (MainHand, SubHand, Helmet, Torso, Ring, ...) und Art (Greatsword, ...)
|
|
slot VARCHAR(20) NOT NULL,
|
|
item_type VARCHAR(40) NOT NULL DEFAULT '',
|
|
grade VARCHAR(20) NOT NULL DEFAULT '',
|
|
item_level SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
|
required_level SMALLINT UNSIGNED NULL,
|
|
-- Werte als JSON: stats, soul_imprint, Sockel, Aufwertung/Durchbruch (GEAR_DATA_FIELDS in includes/gear.php)
|
|
data MEDIUMTEXT NOT NULL,
|
|
-- Dateiname unter assets/uploads/gear/
|
|
icon VARCHAR(40) NULL,
|
|
-- Stand der Quelle, z.B. "Global data (Launch Scale Test client, 2026-09-19)"
|
|
source_version VARCHAR(120) NOT NULL DEFAULT '',
|
|
-- Zuletzt mit der Quelle abgeglichen (von wem) und zuletzt tatsaechlich geaendert
|
|
checked_at DATETIME NULL,
|
|
checked_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME NULL,
|
|
FOREIGN KEY (checked_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_gear_items_slot (slot, item_level),
|
|
INDEX idx_gear_items_name (name)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
SQL,
|
|
'gear_sets' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS gear_sets (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT UNSIGNED NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
class_name VARCHAR(30) NULL,
|
|
note VARCHAR(255) NULL,
|
|
-- Link zum eigenen Skill-/Daevanion-Plan auf einer Planer-Seite (GEAR_BUILD_HOSTS)
|
|
build_url VARCHAR(300) NULL,
|
|
-- 1 = auf der eigenen Profilseite zeigen (dann koennen alle Mitglieder es ansehen und vergleichen)
|
|
show_on_profile TINYINT(1) NOT NULL DEFAULT 0,
|
|
sort_order INT NOT NULL DEFAULT 0,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME NULL,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
INDEX idx_gear_sets_user (user_id, sort_order)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
SQL,
|
|
'gear_set_slots' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS gear_set_slots (
|
|
set_id INT UNSIGNED NOT NULL,
|
|
-- Schluessel aus GEAR_SLOTS (main_hand, head, ring_1, ...)
|
|
slot VARCHAR(20) NOT NULL,
|
|
item_id INT UNSIGNED NULL,
|
|
enchant TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
|
exceed TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
|
-- JSON [[Wert, Zahl], ...] - so eingetragen, wie im Spiel gewuerfelt
|
|
soul_imprint TEXT NULL,
|
|
manastones TEXT NULL,
|
|
godstone VARCHAR(100) NULL,
|
|
PRIMARY KEY (set_id, slot),
|
|
FOREIGN KEY (set_id) REFERENCES gear_sets(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (item_id) REFERENCES gear_items(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
SQL,
|
|
// Skillplaner im Gear-Planer (includes/gear_skills.php)
|
|
'gear_skills' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS gear_skills (
|
|
-- Skill-ID aus dem Spiel (wie bei aion2hub.com/api/skill-icon/<ID>)
|
|
id INT UNSIGNED NOT NULL PRIMARY KEY,
|
|
-- Klasse wie in AION_CLASSES (Templer, Kantor, ...)
|
|
class_name VARCHAR(30) NOT NULL,
|
|
name VARCHAR(100) NOT NULL,
|
|
-- active = normaler aktiver Skill, stigma = Stigma-Skill, passive = passiver Skill
|
|
kind ENUM('active', 'stigma', 'passive') NOT NULL DEFAULT 'active',
|
|
-- Art laut aion2hub (Attack, Buff, Heal, ...) - bei manchen Skills leer
|
|
category VARCHAR(30) NOT NULL DEFAULT '',
|
|
-- Reihenfolge wie auf der Klassenseite
|
|
sort_order SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
|
-- Dateiname unter assets/uploads/skills/
|
|
icon VARCHAR(40) NULL,
|
|
source_version VARCHAR(120) NOT NULL DEFAULT '',
|
|
-- 0 = stand beim letzten Abgleich nicht mehr in der Liste (bleibt fuer bestehende Plaene)
|
|
is_listed TINYINT(1) NOT NULL DEFAULT 1,
|
|
checked_at DATETIME NULL,
|
|
checked_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (checked_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_gear_skills_class (class_name, kind, sort_order)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
SQL,
|
|
'gear_set_skills' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS gear_set_skills (
|
|
set_id INT UNSIGNED NOT NULL,
|
|
skill_id INT UNSIGNED NOT NULL,
|
|
-- Geplante Stufe 1-20 (GEAR_SKILL_LEVEL_MAX / GEAR_STIGMA_LEVEL_MAX in includes/gear_skills.php)
|
|
level TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
|
PRIMARY KEY (set_id, skill_id),
|
|
FOREIGN KEY (set_id) REFERENCES gear_sets(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (skill_id) REFERENCES gear_skills(id) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
SQL,
|
|
// "Angemeldet bleiben" (includes/auth.php)
|
|
'auth_tokens' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS auth_tokens (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT UNSIGNED NOT NULL,
|
|
-- Cookie "selector:validator": selector zum Nachschlagen, vom validator nur der SHA-256-Hash
|
|
selector CHAR(24) NOT NULL UNIQUE,
|
|
validator_hash CHAR(64) NOT NULL,
|
|
-- password | discord (wie $_SESSION['login_method'])
|
|
login_method VARCHAR(10) NOT NULL DEFAULT 'password',
|
|
-- Stand von users.session_epoch beim Anmelden - passt er nicht mehr, ist das Token ungueltig
|
|
session_epoch INT UNSIGNED NOT NULL DEFAULT 0,
|
|
user_agent VARCHAR(255) NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
last_used_at DATETIME NULL,
|
|
expires_at DATETIME NOT NULL,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
INDEX idx_auth_tokens_user (user_id),
|
|
INDEX idx_auth_tokens_expires (expires_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
SQL,
|
|
'warehouse_items' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS warehouse_items (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(150) NOT NULL,
|
|
-- Schluessel aus WAREHOUSE_CATEGORIES in includes/warehouse.php (sword, boots, ...)
|
|
category VARCHAR(30) NOT NULL,
|
|
-- Dateiname des Bildes unter assets/images/warehouse/ (NULL = Platzhalter)
|
|
icon VARCHAR(120) NULL,
|
|
-- wiki = aus includes/data/warehouse_items.json, custom = in der Oberflaeche angelegt
|
|
source ENUM('wiki', 'custom') NOT NULL DEFAULT 'wiki',
|
|
created_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
UNIQUE KEY uq_warehouse_items_name (name),
|
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'warehouse_movements' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS warehouse_movements (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
item_id INT UNSIGNED NOT NULL,
|
|
-- in = eingelagert, out = entnommen
|
|
direction ENUM('in', 'out') NOT NULL,
|
|
-- BIGINT wegen Kina (Betraege weit ueber 4 Milliarden moeglich)
|
|
quantity BIGINT UNSIGNED NOT NULL,
|
|
-- Wann uebergeben/entnommen (wie eingegeben, deutsche Zeit)
|
|
occurred_at DATETIME NOT NULL,
|
|
-- Von wem (in) bzw. an wen (out): ein Konto der Website oder ein frei eingetragener Name
|
|
counterpart_user_id INT UNSIGNED NULL,
|
|
counterpart_name VARCHAR(100) NULL,
|
|
note VARCHAR(255) NULL,
|
|
created_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (item_id) REFERENCES warehouse_items(id) ON DELETE RESTRICT,
|
|
FOREIGN KEY (counterpart_user_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_warehouse_movements_item (item_id),
|
|
INDEX idx_warehouse_movements_time (occurred_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'contribution_awards' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS contribution_awards (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
-- raid, event, other (CONTRIBUTION_CATEGORIES in includes/contributions.php)
|
|
category VARCHAR(20) NOT NULL,
|
|
title VARCHAR(150) NOT NULL,
|
|
note VARCHAR(255) NULL,
|
|
-- Raid aus der Raid-API, wenn die Punkte fuer einen Raid vergeben wurden
|
|
raid_id BIGINT UNSIGNED NULL,
|
|
awarded_at DATETIME NOT NULL,
|
|
created_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_contribution_awards_time (awarded_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'contribution_entries' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS contribution_entries (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
award_id INT UNSIGNED NOT NULL,
|
|
user_id INT UNSIGNED NOT NULL,
|
|
-- Negativ = Abzug
|
|
points INT NOT NULL,
|
|
UNIQUE KEY uq_contribution_entry (award_id, user_id),
|
|
FOREIGN KEY (award_id) REFERENCES contribution_awards(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
INDEX idx_contribution_entries_user (user_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'shop_categories' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS shop_categories (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(80) NOT NULL,
|
|
sort_order INT NOT NULL DEFAULT 0,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'shop_items' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS shop_items (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
category_id INT UNSIGNED NULL,
|
|
name VARCHAR(150) NOT NULL,
|
|
description VARCHAR(500) NULL,
|
|
-- Preis in Lumipunkten pro Stueck
|
|
price INT UNSIGNED NOT NULL,
|
|
-- manual = eigener Bestand (stock), warehouse = Bestand des Lagerhaus-Gegenstands, unlimited
|
|
stock_mode ENUM('manual', 'warehouse', 'unlimited') NOT NULL DEFAULT 'manual',
|
|
stock INT UNSIGNED NOT NULL DEFAULT 0,
|
|
-- Verknuepfter Lagerhaus-Gegenstand: liefert das Bild und bei stock_mode = warehouse den Bestand
|
|
warehouse_item_id INT UNSIGNED NULL,
|
|
active TINYINT(1) NOT NULL DEFAULT 1,
|
|
created_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME NULL,
|
|
FOREIGN KEY (category_id) REFERENCES shop_categories(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (warehouse_item_id) REFERENCES warehouse_items(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'shop_orders' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS shop_orders (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT UNSIGNED NOT NULL,
|
|
item_id INT UNSIGNED NULL,
|
|
-- Name und Preis zum Zeitpunkt der Bestellung (bleiben, auch wenn der Gegenstand spaeter
|
|
-- geaendert oder geloescht wird)
|
|
item_name VARCHAR(150) NOT NULL,
|
|
-- Anzahl (nach einer Teilbewilligung die bewilligte) und die urspruenglich beantragte
|
|
quantity INT UNSIGNED NOT NULL,
|
|
requested_quantity INT UNSIGNED NOT NULL,
|
|
unit_price INT UNSIGNED NOT NULL,
|
|
total_price INT UNSIGNED NOT NULL,
|
|
-- Bemerkung des Mitglieds (z.B. Charaktername)
|
|
note VARCHAR(255) NULL,
|
|
-- pending, approved, delivered, rejected, cancelled (SHOP_STATUSES in includes/shop.php)
|
|
status ENUM('pending', 'approved', 'delivered', 'rejected', 'cancelled') NOT NULL DEFAULT 'pending',
|
|
decision_note VARCHAR(255) NULL,
|
|
decided_by INT UNSIGNED NULL,
|
|
decided_at DATETIME NULL,
|
|
delivered_by INT UNSIGNED NULL,
|
|
delivered_at DATETIME NULL,
|
|
-- Die Vergabe mit dem Punkteabzug und die Entnahme im Lagerhaus (fuer eine Stornierung)
|
|
award_id INT UNSIGNED NULL,
|
|
warehouse_movement_id INT UNSIGNED NULL,
|
|
-- 1 = bei der Bewilligung wurde der eigene Bestand im Shop verringert
|
|
stock_taken TINYINT(1) NOT NULL DEFAULT 0,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (item_id) REFERENCES shop_items(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (decided_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (delivered_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (award_id) REFERENCES contribution_awards(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (warehouse_movement_id) REFERENCES warehouse_movements(id) ON DELETE SET NULL,
|
|
INDEX idx_shop_orders_status (status),
|
|
INDEX idx_shop_orders_user (user_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'raid_settings' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS raid_settings (
|
|
-- Discord-Nachrichten-ID des Raids (wie in der Raid-API), 19-stellig
|
|
raid_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
-- Automatische Lumipunkte beim Archivieren: fuer Anwesende bzw. Abzug fuer Abwesende
|
|
points_present INT NOT NULL DEFAULT 0,
|
|
points_absent INT NOT NULL DEFAULT 0,
|
|
-- Wann die Automatik gelaufen ist (oder uebersprungen wurde, weil schon Punkte vergeben waren)
|
|
auto_processed_at DATETIME NULL,
|
|
auto_result VARCHAR(255) NULL,
|
|
-- Anwesenheitsliste als kontrolliert bestaetigt
|
|
attendance_checked_at DATETIME NULL,
|
|
attendance_checked_by INT UNSIGNED NULL,
|
|
FOREIGN KEY (attendance_checked_by) REFERENCES users(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'raid_attendance' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS raid_attendance (
|
|
raid_id BIGINT UNSIGNED NOT NULL,
|
|
-- Discord-ID wie in den Raid-Anmeldungen; zugeordnet zu Website-Konten ueber users.discord_id
|
|
discord_id BIGINT UNSIGNED NOT NULL,
|
|
name VARCHAR(100) NOT NULL DEFAULT '',
|
|
status ENUM('present', 'absent', 'excused') NOT NULL,
|
|
updated_by INT UNSIGNED NULL,
|
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (raid_id, discord_id),
|
|
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'settings' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS settings (
|
|
`key` VARCHAR(100) NOT NULL PRIMARY KEY,
|
|
value TEXT NOT NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'member_characters' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS member_characters (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT UNSIGNED NOT NULL,
|
|
name VARCHAR(60) NOT NULL,
|
|
-- AION_CLASSES in includes/functions.php
|
|
class_name VARCHAR(30) NULL,
|
|
level SMALLINT UNSIGNED NULL,
|
|
note VARCHAR(255) NULL,
|
|
-- Dateien unter assets/uploads/profiles/
|
|
portrait_filename VARCHAR(120) NULL,
|
|
image_filename VARCHAR(120) NULL,
|
|
is_main TINYINT(1) NOT NULL DEFAULT 0,
|
|
sort_order INT NOT NULL DEFAULT 0,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
INDEX idx_member_characters_user (user_id, sort_order)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'member_gallery' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS member_gallery (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT UNSIGNED NOT NULL,
|
|
filename VARCHAR(120) NOT NULL,
|
|
caption VARCHAR(150) NULL,
|
|
-- visible = fuer alle sichtbar, pending = wartet auf Freigabe
|
|
status VARCHAR(10) NOT NULL DEFAULT 'visible',
|
|
moderation_note VARCHAR(255) NULL,
|
|
sort_order INT NOT NULL DEFAULT 0,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
INDEX idx_member_gallery_user (user_id, sort_order)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'wiki_pages' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS wiki_pages (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
-- NULL = Kapitel, sonst Unterseite dieses Kapitels
|
|
parent_id INT UNSIGNED NULL,
|
|
title VARCHAR(150) NOT NULL,
|
|
slug VARCHAR(170) NOT NULL UNIQUE,
|
|
content MEDIUMTEXT NOT NULL,
|
|
-- 1 = noch in Arbeit (wird im Inhaltsverzeichnis markiert)
|
|
is_wip TINYINT(1) NOT NULL DEFAULT 0,
|
|
sort_order INT NOT NULL DEFAULT 0,
|
|
created_by INT UNSIGNED NULL,
|
|
updated_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (parent_id) REFERENCES wiki_pages(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_wiki_pages_parent (parent_id, sort_order)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'wiki_revisions' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS wiki_revisions (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
page_id INT UNSIGNED NOT NULL,
|
|
title VARCHAR(150) NOT NULL,
|
|
content MEDIUMTEXT NOT NULL,
|
|
is_wip TINYINT(1) NOT NULL DEFAULT 0,
|
|
-- kurze Beschreibung der Aenderung ("Tabelle ergaenzt")
|
|
summary VARCHAR(255) NULL,
|
|
edited_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (page_id) REFERENCES wiki_pages(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (edited_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_wiki_revisions_page (page_id, created_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'wiki_contributors' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS wiki_contributors (
|
|
-- Mitglieder, die die Leitung im Wiki als Mitwirkende hinzugefuegt hat (duerfen schreiben)
|
|
user_id INT UNSIGNED NOT NULL PRIMARY KEY,
|
|
added_by INT UNSIGNED NULL,
|
|
added_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (added_by) REFERENCES users(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'bug_reports' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS bug_reports (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT UNSIGNED NULL,
|
|
title VARCHAR(150) NOT NULL,
|
|
-- Schluessel aus BUG_AREAS in includes/bugs.php (raids, shop, ...)
|
|
area VARCHAR(30) NOT NULL,
|
|
description TEXT NOT NULL,
|
|
-- optional: Link zu einem Screenshot o.ae.
|
|
screenshot_url VARCHAR(500) NULL,
|
|
-- Browser/Geraet des Melders, hilft beim Nachstellen
|
|
user_agent VARCHAR(255) NULL,
|
|
status ENUM('open', 'in_progress', 'done', 'rejected') NOT NULL DEFAULT 'open',
|
|
-- Antwort der Leitung, sieht der Melder im Dashboard
|
|
admin_note TEXT NULL,
|
|
handled_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME NULL,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
FOREIGN KEY (handled_by) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_bug_reports_status (status),
|
|
INDEX idx_bug_reports_user (user_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'audit_log' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS audit_log (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
-- Wer (NULL = unbekannt/abgemeldet, z.B. fehlgeschlagener Login); Name bleibt auch nach dem Loeschen des Kontos
|
|
user_id INT UNSIGNED NULL,
|
|
actor_name VARCHAR(100) NOT NULL DEFAULT '',
|
|
-- Bereich (siehe AUDIT_AREAS in includes/security.php), Titel und Details (JSON: Name => Wert)
|
|
area VARCHAR(30) NOT NULL,
|
|
title VARCHAR(256) NOT NULL,
|
|
details TEXT NULL,
|
|
tone VARCHAR(10) NOT NULL DEFAULT 'info',
|
|
-- gekuerzte IP (letzter Block genullt) - reicht zum Wiedererkennen, ohne sie ganz zu speichern
|
|
ip VARCHAR(45) NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
INDEX idx_audit_log_time (created_at),
|
|
INDEX idx_audit_log_user (user_id, created_at),
|
|
INDEX idx_audit_log_area (area, created_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'rate_limits' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS rate_limits (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
-- Art der Aktion (z.B. post, upload, login) und wer (Konto-ID, IP oder Benutzername)
|
|
bucket VARCHAR(40) NOT NULL,
|
|
subject VARCHAR(120) NOT NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
INDEX idx_rate_limits_lookup (bucket, subject, created_at),
|
|
INDEX idx_rate_limits_time (created_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'gallery_comments' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS gallery_comments (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
-- Kommentar unter einem Bild der Profil-Galerie
|
|
gallery_id INT UNSIGNED NOT NULL,
|
|
author_id INT UNSIGNED NULL,
|
|
body TEXT NOT NULL,
|
|
-- visible = fuer alle sichtbar, pending = wartet auf Freigabe (Vertrauensstufe, Link, KI-Pruefung, Meldungen)
|
|
status VARCHAR(10) NOT NULL DEFAULT 'visible',
|
|
moderation_note VARCHAR(255) NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (gallery_id) REFERENCES member_gallery(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
INDEX idx_gallery_comments_picture (gallery_id, created_at),
|
|
INDEX idx_gallery_comments_author (author_id, created_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'moderation_words' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS moderation_words (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
-- Wort (klein geschrieben); * am Anfang/Ende = auch als Wortteil (z.B. fick*)
|
|
word VARCHAR(60) NOT NULL,
|
|
-- flag = nur markieren, hold = erst nach Freigabe sichtbar, block = wird nicht gespeichert
|
|
action VARCHAR(10) NOT NULL DEFAULT 'flag',
|
|
created_by INT UNSIGNED NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
UNIQUE KEY uq_moderation_words (word),
|
|
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'reactions' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS reactions (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
-- Reaktion auf: picture = member_gallery.id, comment = gallery_comments.id
|
|
content_type VARCHAR(20) NOT NULL,
|
|
content_id INT UNSIGNED NOT NULL,
|
|
user_id INT UNSIGNED NOT NULL,
|
|
-- ein Emoji aus REACTION_EMOJIS (includes/reactions.php)
|
|
emoji VARCHAR(16) NOT NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
UNIQUE KEY uq_reactions (content_type, content_id, user_id, emoji),
|
|
INDEX idx_reactions_content (content_type, content_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'calendar_entries' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS calendar_entries (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
-- Von Mitgliedern eingetragene Termine (Raids und Events kommen aus der Bot-API)
|
|
user_id INT UNSIGNED NOT NULL,
|
|
title VARCHAR(100) NOT NULL,
|
|
description TEXT NULL,
|
|
starts_at DATETIME NOT NULL,
|
|
ends_at DATETIME NULL,
|
|
-- Treffpunkt auf der Karte (Link /map.php?karte=...&x=...&y=...)
|
|
location_path VARCHAR(300) NULL,
|
|
-- Fuer wen: all (alle), leadership (alle sehen ihn, teilnehmen nur die Leitung), internal (nur die Leitung sieht ihn)
|
|
audience ENUM('all', 'leadership', 'internal') NOT NULL DEFAULT 'all',
|
|
-- visible / pending (Moderation wie bei Kommentaren)
|
|
status VARCHAR(10) NOT NULL DEFAULT 'visible',
|
|
moderation_note VARCHAR(255) NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME NULL,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
INDEX idx_calendar_entries_start (starts_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'calendar_participants' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS calendar_participants (
|
|
entry_id INT UNSIGNED NOT NULL,
|
|
user_id INT UNSIGNED NOT NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (entry_id, user_id),
|
|
FOREIGN KEY (entry_id) REFERENCES calendar_entries(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
'content_reports' => <<<'SQL'
|
|
CREATE TABLE IF NOT EXISTS content_reports (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
-- Gemeldeter Inhalt: picture = member_gallery.id, comment = gallery_comments.id
|
|
content_type VARCHAR(20) NOT NULL,
|
|
content_id INT UNSIGNED NOT NULL,
|
|
reporter_id INT UNSIGNED NOT NULL,
|
|
reason VARCHAR(255) NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (reporter_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
UNIQUE KEY uq_content_reports (content_type, content_id, reporter_id),
|
|
INDEX idx_content_reports_content (content_type, content_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
|
SQL,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Spalten, die nachtraeglich dazugekommen sind: Tabelle => [Spalte => ALTER-Befehl].
|
|
* Die Befehle muessen zu sql/schema.sql passen (dort stehen sie fuer Neuinstallationen).
|
|
*/
|
|
function schema_column_upgrades(): array
|
|
{
|
|
return [
|
|
// Persoenliche Taktiken und Hervorhebung (tactics_api.php) - bisherige Taktiken bleiben
|
|
// oeffentlich, sie stammen alle von der Leitung.
|
|
'tactics' => [
|
|
'visibility' => "ALTER TABLE tactics ADD COLUMN visibility ENUM('private', 'public') NOT NULL DEFAULT 'public' AFTER description",
|
|
'highlight' => "ALTER TABLE tactics ADD COLUMN highlight ENUM('none', 'recommended', 'official') NOT NULL DEFAULT 'none' AFTER visibility",
|
|
'highlighted_by' => [
|
|
"ALTER TABLE tactics ADD COLUMN highlighted_by INT UNSIGNED NULL AFTER highlight",
|
|
"ALTER TABLE tactics ADD CONSTRAINT fk_tactics_highlighted_by FOREIGN KEY (highlighted_by) REFERENCES users(id) ON DELETE SET NULL",
|
|
],
|
|
'highlighted_at' => "ALTER TABLE tactics ADD COLUMN highlighted_at DATETIME NULL AFTER highlighted_by",
|
|
],
|
|
'users' => [
|
|
// Zuletzt gelesene Patchnote (includes/patchnotes.php) - leer: "Neu" in der Seitenleiste
|
|
'patchnotes_seen' => "ALTER TABLE users ADD COLUMN patchnotes_seen VARCHAR(20) NULL AFTER sidebar_order",
|
|
// Weggeklickte Ankuendigung (includes/site_notice.php)
|
|
'announcement_dismissed' => "ALTER TABLE users ADD COLUMN announcement_dismissed VARCHAR(20) NULL AFTER patchnotes_seen",
|
|
// Eigene Reihenfolge der Menuepunkte (JSON, siehe SIDEBAR_NAV_MAIN)
|
|
'sidebar_order' => "ALTER TABLE users ADD COLUMN sidebar_order TEXT NULL AFTER tour_completed_at",
|
|
'password_login' => "ALTER TABLE users ADD COLUMN password_login TINYINT(1) NOT NULL DEFAULT 1 AFTER must_change_password",
|
|
'is_admin' => "ALTER TABLE users ADD COLUMN is_admin TINYINT(1) NOT NULL DEFAULT 0 AFTER password_login",
|
|
// Profilbild von Discord uebernehmen - wer schon ein eigenes hochgeladen hat, behaelt es.
|
|
'avatar_sync' => [
|
|
"ALTER TABLE users ADD COLUMN avatar_sync TINYINT(1) NOT NULL DEFAULT 1 AFTER avatar_filename",
|
|
"UPDATE users SET avatar_sync = 0 WHERE avatar_filename IS NOT NULL",
|
|
],
|
|
'discord_avatar' => "ALTER TABLE users ADD COLUMN discord_avatar VARCHAR(120) NULL AFTER avatar_sync",
|
|
'class_name' => "ALTER TABLE users ADD COLUMN class_name VARCHAR(30) NULL AFTER display_name",
|
|
// Alle Klassen laut Discord-Klassenrollen ("Kantor,Kleriker") - bis zum ersten Abgleich die bisherige
|
|
'classes' => [
|
|
"ALTER TABLE users ADD COLUMN classes VARCHAR(255) NULL AFTER class_name",
|
|
"UPDATE users SET classes = class_name WHERE class_name IS NOT NULL",
|
|
],
|
|
// Selbst gewaehlte Main-Klasse (leer = die hoechste Klassenrolle auf Discord)
|
|
'main_class' => "ALTER TABLE users ADD COLUMN main_class VARCHAR(30) NULL AFTER classes",
|
|
// Profilseite: frei geschriebener Text (Wiki-Format)
|
|
'profile_bio' => "ALTER TABLE users ADD COLUMN profile_bio TEXT NULL AFTER class_name",
|
|
// Beitritt zum Discord-Server (wird beim Discord-Abgleich gesetzt)
|
|
'discord_joined_at' => "ALTER TABLE users ADD COLUMN discord_joined_at DATETIME NULL AFTER discord_synced_at",
|
|
'discord_access_token' => "ALTER TABLE users ADD COLUMN discord_access_token VARCHAR(255) NULL AFTER discord_username",
|
|
'discord_refresh_token' => "ALTER TABLE users ADD COLUMN discord_refresh_token VARCHAR(255) NULL AFTER discord_access_token",
|
|
'discord_token_expires' => "ALTER TABLE users ADD COLUMN discord_token_expires DATETIME NULL AFTER discord_refresh_token",
|
|
'discord_synced_at' => "ALTER TABLE users ADD COLUMN discord_synced_at DATETIME NULL AFTER discord_token_expires",
|
|
// Einfuehrung im Dashboard: bestehende Konten gelten als "schon gesehen", nur neue
|
|
// Mitglieder bekommen die Tour automatisch.
|
|
'tour_completed_at' => [
|
|
"ALTER TABLE users ADD COLUMN tour_completed_at DATETIME NULL AFTER discord_synced_at",
|
|
"UPDATE users SET tour_completed_at = NOW()",
|
|
],
|
|
// Wird hochgezaehlt, um alle Sitzungen eines Kontos sofort zu beenden (Sperren/Abmelden).
|
|
// Zuletzt aktiv (Mitgliederliste) - bis zum ersten Besuch gilt der letzte Login
|
|
'last_seen_at' => [
|
|
"ALTER TABLE users ADD COLUMN last_seen_at DATETIME NULL AFTER last_login",
|
|
"UPDATE users SET last_seen_at = last_login",
|
|
],
|
|
'session_epoch' => "ALTER TABLE users ADD COLUMN session_epoch INT UNSIGNED NOT NULL DEFAULT 0 AFTER is_admin",
|
|
// Hintergrund der eigenen Profilseite: "preset:landscape5" oder "gallery:<Bild-ID>"
|
|
'profile_background' => "ALTER TABLE users ADD COLUMN profile_background VARCHAR(40) NULL AFTER profile_bio",
|
|
// Kommentare unter den eigenen Galeriebildern (0 = vom Mitglied abgeschaltet)
|
|
'gallery_comments_enabled' => "ALTER TABLE users ADD COLUMN gallery_comments_enabled TINYINT(1) NOT NULL DEFAULT 1 AFTER profile_bio",
|
|
],
|
|
'roles' => [
|
|
'discord_role_id' => "ALTER TABLE roles ADD COLUMN discord_role_id BIGINT UNSIGNED NULL AFTER roster_order",
|
|
],
|
|
// Freigabe von Galeriebildern (Moderation) - vorhandene Bilder bleiben sichtbar
|
|
'member_gallery' => [
|
|
'status' => "ALTER TABLE member_gallery ADD COLUMN status VARCHAR(10) NOT NULL DEFAULT 'visible' AFTER caption",
|
|
'moderation_note' => "ALTER TABLE member_gallery ADD COLUMN moderation_note VARCHAR(255) NULL AFTER status",
|
|
// 1 = nur als Hintergrund der Profilseite hochgeladen, nicht Teil der Galerie
|
|
'is_background' => "ALTER TABLE member_gallery ADD COLUMN is_background TINYINT(1) NOT NULL DEFAULT 0 AFTER moderation_note",
|
|
],
|
|
// Treffpunkt auf der Karte (Link /map.php?karte=...&x=...&y=...)
|
|
'calendar_entries' => [
|
|
'location_path' => "ALTER TABLE calendar_entries ADD COLUMN location_path VARCHAR(300) NULL AFTER ends_at",
|
|
// Termine nur fuer die Leitung (calendar.leadership) - bestehende gelten fuer alle
|
|
'audience' => "ALTER TABLE calendar_entries ADD COLUMN audience ENUM('all', 'leadership', 'internal') NOT NULL DEFAULT 'all' AFTER location_path",
|
|
],
|
|
// Link zum Skill-/Daevanion-Plan eines Gear-Sets (gear.php, "Set bearbeiten")
|
|
'gear_sets' => [
|
|
'build_url' => "ALTER TABLE gear_sets ADD COLUMN build_url VARCHAR(300) NULL AFTER note",
|
|
],
|
|
'shop_orders' => [
|
|
'requested_quantity' => "ALTER TABLE shop_orders ADD COLUMN requested_quantity INT UNSIGNED NOT NULL DEFAULT 0 AFTER quantity",
|
|
],
|
|
];
|
|
}
|
|
|
|
function ensure_schema(): void
|
|
{
|
|
if (($_SESSION['schema_version'] ?? 0) === SCHEMA_VERSION) {
|
|
return;
|
|
}
|
|
|
|
$pdo = db();
|
|
$upgrades = schema_column_upgrades();
|
|
|
|
$stmt = $pdo->query(
|
|
"SELECT LOWER(table_name) AS t, LOWER(column_name) AS c FROM information_schema.columns
|
|
WHERE table_schema = DATABASE() AND table_name IN ('" . implode("', '", array_keys($upgrades)) . "')"
|
|
);
|
|
$existing = [];
|
|
foreach ($stmt->fetchAll() as $row) {
|
|
$existing[$row['t']][$row['c']] = true;
|
|
}
|
|
|
|
// Noch gar keine Tabellen: frische Installation, schema.sql ist noch nicht importiert.
|
|
if (empty($existing['users'])) {
|
|
return;
|
|
}
|
|
|
|
$statements = [];
|
|
|
|
$tables = $pdo->query(
|
|
"SELECT LOWER(table_name) FROM information_schema.tables WHERE table_schema = DATABASE()"
|
|
)->fetchAll(PDO::FETCH_COLUMN);
|
|
foreach (schema_table_upgrades() as $table => $sql) {
|
|
if (!in_array($table, $tables, true)) {
|
|
$statements[] = $sql;
|
|
}
|
|
}
|
|
|
|
foreach ($upgrades as $table => $columns) {
|
|
// Tabellen, die es noch nicht gibt, entstehen oben schon mit allen Spalten.
|
|
if (!in_array($table, $tables, true)) {
|
|
continue;
|
|
}
|
|
foreach ($columns as $column => $sql) {
|
|
if (empty($existing[$table][$column])) {
|
|
// Ein Eintrag kann auch mehrere Befehle sein (z.B. Spalte anlegen + befuellen).
|
|
foreach ((array) $sql as $single) {
|
|
$statements[] = $single;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Der Status "pending" (Freischaltung ausstehend) kam mit dem Discord-Login dazu.
|
|
$enum = $pdo->query(
|
|
"SELECT column_type FROM information_schema.columns
|
|
WHERE table_schema = DATABASE() AND table_name = 'users' AND column_name = 'status'"
|
|
)->fetchColumn();
|
|
if (is_string($enum) && strpos($enum, "'pending'") === false) {
|
|
$statements[] = "ALTER TABLE users MODIFY status ENUM('active', 'disabled', 'pending') NOT NULL DEFAULT 'active'";
|
|
}
|
|
|
|
// Spalten, deren Typ nachtraeglich korrigiert wurde: [Tabelle, Spalte, erwarteter Typ-Anfang, Befehl].
|
|
// raid_id sind Discord-Nachrichten-IDs (19-stellig) - ein INT war dafuer zu klein.
|
|
$typeFixes = [
|
|
['contribution_awards', 'raid_id', 'bigint', 'ALTER TABLE contribution_awards MODIFY raid_id BIGINT UNSIGNED NULL'],
|
|
['warehouse_movements', 'quantity', 'bigint', 'ALTER TABLE warehouse_movements MODIFY quantity BIGINT UNSIGNED NOT NULL'],
|
|
];
|
|
foreach ($typeFixes as [$table, $column, $expected, $sql]) {
|
|
if (!in_array($table, $tables, true)) {
|
|
continue; // Tabelle wird oben frisch (schon richtig) angelegt
|
|
}
|
|
$typeStmt = $pdo->prepare(
|
|
'SELECT LOWER(column_type) FROM information_schema.columns
|
|
WHERE table_schema = DATABASE() AND table_name = ? AND column_name = ?'
|
|
);
|
|
$typeStmt->execute([$table, $column]);
|
|
$type = (string) $typeStmt->fetchColumn();
|
|
if ($type !== '' && strpos($type, $expected) !== 0) {
|
|
$statements[] = $sql;
|
|
}
|
|
}
|
|
|
|
try {
|
|
foreach ($statements as $sql) {
|
|
$pdo->exec($sql);
|
|
}
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
header('Content-Type: text/plain; charset=UTF-8');
|
|
echo "Die Datenbank konnte nicht automatisch aktualisiert werden:\n" . $e->getMessage()
|
|
. "\n\nBitte diese Befehle einmal in phpMyAdmin ausfuehren und die Seite neu laden:\n\n"
|
|
. implode(";\n", $statements) . ";\n";
|
|
exit;
|
|
}
|
|
|
|
schema_sync_core_permissions();
|
|
|
|
$_SESSION['schema_version'] = SCHEMA_VERSION;
|
|
}
|
|
|
|
/**
|
|
* Traegt neu hinzugekommene Kern-Berechtigungen (CORE_PERMISSIONS) in die Datenbank ein und
|
|
* aktualisiert die Beschreibungen der vorhandenen -
|
|
* bisher musste man sie nach einem Update von Hand anlegen. Neue Rechte bekommt die
|
|
* Administrator-Gruppe gleich mit, weil sie laut Installation alle Rechte hat.
|
|
*/
|
|
function schema_sync_core_permissions(): void
|
|
{
|
|
$pdo = db();
|
|
$existing = $pdo->query('SELECT `key`, description FROM permissions')->fetchAll(PDO::FETCH_KEY_PAIR);
|
|
$adminRoleId = (int) $pdo->query("SELECT id FROM roles WHERE name = 'Administrator'")->fetchColumn();
|
|
|
|
foreach (CORE_PERMISSIONS as $permission) {
|
|
if (array_key_exists($permission['key'], $existing)) {
|
|
// Beschreibung nachziehen, falls sie im Code geaendert wurde (z.B. Umbenennungen).
|
|
if ($existing[$permission['key']] !== $permission['description']) {
|
|
$pdo->prepare('UPDATE permissions SET description = ? WHERE `key` = ?')
|
|
->execute([$permission['description'], $permission['key']]);
|
|
}
|
|
continue;
|
|
}
|
|
$pdo->prepare('INSERT INTO permissions (`key`, description) VALUES (?, ?)')
|
|
->execute([$permission['key'], $permission['description']]);
|
|
$newPermissionId = (int) $pdo->lastInsertId();
|
|
if ($adminRoleId > 0) {
|
|
$pdo->prepare('INSERT IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)')
|
|
->execute([$adminRoleId, $newPermissionId]);
|
|
}
|
|
// Das Wiki und den Gear-Planer sollen alle nutzen duerfen, die ins Dashboard kommen.
|
|
if (in_array($permission['key'], ['wiki.view', 'gear.view'], true)) {
|
|
$pdo->prepare(
|
|
"INSERT IGNORE INTO role_permissions (role_id, permission_id)
|
|
SELECT rp.role_id, ? FROM role_permissions rp
|
|
JOIN permissions p ON p.id = rp.permission_id
|
|
WHERE p.`key` = 'dashboard.view'"
|
|
)->execute([$newPermissionId]);
|
|
}
|
|
// Wer bisher Taktiken verwalten durfte, kann sie auch weiterhin hervorheben.
|
|
if ($permission['key'] === 'map.tactics.highlight') {
|
|
$pdo->prepare(
|
|
"INSERT IGNORE INTO role_permissions (role_id, permission_id)
|
|
SELECT rp.role_id, ? FROM role_permissions rp
|
|
JOIN permissions p ON p.id = rp.permission_id
|
|
WHERE p.`key` = 'map.tactics'"
|
|
)->execute([$newPermissionId]);
|
|
}
|
|
// Wer Lumipunkte schon von Hand vergeben darf, legt auch die Punkte fuer Raids fest.
|
|
if ($permission['key'] === 'raids.points') {
|
|
$pdo->prepare(
|
|
"INSERT IGNORE INTO role_permissions (role_id, permission_id)
|
|
SELECT rp.role_id, ? FROM role_permissions rp
|
|
JOIN permissions p ON p.id = rp.permission_id
|
|
WHERE p.`key` = 'contributions.manage'"
|
|
)->execute([$newPermissionId]);
|
|
}
|
|
// Bisher durfte jeder mit users.edit alle Gruppen vergeben - damit das nach dem
|
|
// Update nicht ploetzlich wegfaellt, bekommen diese Gruppen roles.assign einmalig mit.
|
|
if ($permission['key'] === 'roles.assign') {
|
|
$pdo->prepare(
|
|
"INSERT IGNORE INTO role_permissions (role_id, permission_id)
|
|
SELECT rp.role_id, ? FROM role_permissions rp
|
|
JOIN permissions p ON p.id = rp.permission_id
|
|
WHERE p.`key` = 'users.edit'"
|
|
)->execute([$newPermissionId]);
|
|
}
|
|
}
|
|
|
|
sync_role_assign_permissions();
|
|
}
|