Elyos Allianz: versehentlich angelegte eigene Legion entfernt der Abgleich wieder
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
20a68921aa
commit
03b8cef5ba
1 changed files with 12 additions and 2 deletions
|
|
@ -252,12 +252,12 @@ function consilium_role_legion_name(string $roleName): string
|
||||||
* steht in der Mitgliederliste der Elyos Allianz bei uns (users.consilium_home_by_role = 1).
|
* steht in der Mitgliederliste der Elyos Allianz bei uns (users.consilium_home_by_role = 1).
|
||||||
*
|
*
|
||||||
* @param array<int, array{role_id: string, name: string, members: array<int, string>}> $legions
|
* @param array<int, array{role_id: string, name: string, members: array<int, string>}> $legions
|
||||||
* @return array{legions: int, created: int, assigned: int, cleared: int, home: int}
|
* @return array{legions: int, created: int, assigned: int, cleared: int, home: int, removed: int}
|
||||||
*/
|
*/
|
||||||
function consilium_sync_legion_roles(array $legions): array
|
function consilium_sync_legion_roles(array $legions): array
|
||||||
{
|
{
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
$result = ['legions' => 0, 'created' => 0, 'assigned' => 0, 'cleared' => 0];
|
$result = ['legions' => 0, 'created' => 0, 'assigned' => 0, 'cleared' => 0, 'removed' => 0];
|
||||||
$existing = $pdo->query('SELECT id, name, discord_role_id FROM consilium_legions')->fetchAll();
|
$existing = $pdo->query('SELECT id, name, discord_role_id FROM consilium_legions')->fetchAll();
|
||||||
$byRole = [];
|
$byRole = [];
|
||||||
$byName = [];
|
$byName = [];
|
||||||
|
|
@ -298,6 +298,16 @@ function consilium_sync_legion_roles(array $legions): array
|
||||||
foreach ($known as $discordId) {
|
foreach ($known as $discordId) {
|
||||||
$homeMembers[$discordId] = true;
|
$homeMembers[$discordId] = true;
|
||||||
}
|
}
|
||||||
|
// Frueher (vor der Erkennung) versehentlich als verbuendete Legion angelegt: ohne Mitglieder wieder weg
|
||||||
|
$wrongId = $byRole[$roleId] ?? $byName[mb_strtolower($name)] ?? null;
|
||||||
|
if ($wrongId !== null) {
|
||||||
|
$used = $pdo->prepare('SELECT COUNT(*) FROM users WHERE consilium_legion_id = ?');
|
||||||
|
$used->execute([$wrongId]);
|
||||||
|
if ((int) $used->fetchColumn() === 0) {
|
||||||
|
$pdo->prepare('DELETE FROM consilium_legions WHERE id = ?')->execute([$wrongId]);
|
||||||
|
$result['removed']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$legionId = $byRole[$roleId] ?? $byName[mb_strtolower($name)] ?? null;
|
$legionId = $byRole[$roleId] ?? $byName[mb_strtolower($name)] ?? null;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue