Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

Commit 5d91ae9

Browse files
justinwraygsingh93
authored andcommitted
Maintain Team Protection on Database Reset (#520)
* Maintain Team Protection on Database Reset * Database resets, through Admin Control, will maintain protection on protected admin accounts. * Added Team::genSetProtected() to set protection status on a team. * Database reset now calls Team::genSetProtected() on previous protected accounts. * The Database reset process has been optimized to improve performance. * Fixed Permissions
1 parent eb4a5b5 commit 5d91ae9

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/models/Control.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,15 +572,15 @@ class Control extends Model {
572572
$logos = await self::genLoadDatabaseFile('../database/logos.sql');
573573
if ($schema && $countries && $logos) {
574574
foreach ($admins as $admin) {
575-
await Team::genCreate(
575+
$team_id = await Team::genCreate(
576576
$admin->getName(),
577577
$admin->getPasswordHash(),
578578
$admin->getLogo(),
579579
);
580-
}
581-
$teams = await MultiTeam::genAllTeamsCache();
582-
foreach ($teams as $team) {
583-
await Team::genSetAdmin($team->getId(), true);
580+
await Team::genSetAdmin($team_id, true);
581+
if ($admin->getProtected() === true) {
582+
await Team::genSetProtected($team_id, true);
583+
}
584584
}
585585
await self::genFlushMemcached();
586586
return true;

src/models/Team.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,20 @@ public static function regenerateHash(string $password_hash): bool {
438438
MultiTeam::invalidateMCRecords(); // Invalidate Memcached MultiTeam data.
439439
}
440440

441+
// Sets toggles team protection status.
442+
public static async function genSetProtected(
443+
int $team_id,
444+
bool $protect,
445+
): Awaitable<void> {
446+
$db = await self::genDb();
447+
await $db->queryf(
448+
'UPDATE teams SET protected = %d WHERE id = %d LIMIT 1',
449+
$protect ? 1 : 0,
450+
$team_id,
451+
);
452+
MultiTeam::invalidateMCRecords(); // Invalidate Memcached MultiTeam data.
453+
}
454+
441455
// Sets toggles team admin status.
442456
public static async function genSetAdmin(
443457
int $team_id,

0 commit comments

Comments
 (0)