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

Maintain Team Protection on Database Reset #520

Merged
merged 2 commits into from Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/models/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,15 @@ class Control extends Model {
$logos = await self::genLoadDatabaseFile('../database/logos.sql');
if ($schema && $countries && $logos) {
foreach ($admins as $admin) {
await Team::genCreate(
$team_id = await Team::genCreate(
$admin->getName(),
$admin->getPasswordHash(),
$admin->getLogo(),
);
}
$teams = await MultiTeam::genAllTeamsCache();
foreach ($teams as $team) {
await Team::genSetAdmin($team->getId(), true);
await Team::genSetAdmin($team_id, true);
if ($admin->getProtected() === true) {
await Team::genSetProtected($team_id, true);
}
}
await self::genFlushMemcached();
return true;
Expand Down
14 changes: 14 additions & 0 deletions src/models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,20 @@ public static function regenerateHash(string $password_hash): bool {
MultiTeam::invalidateMCRecords(); // Invalidate Memcached MultiTeam data.
}

// Sets toggles team protection status.
public static async function genSetProtected(
int $team_id,
bool $protect,
): Awaitable<void> {
$db = await self::genDb();
await $db->queryf(
'UPDATE teams SET protected = %d WHERE id = %d LIMIT 1',
$protect ? 1 : 0,
$team_id,
);
MultiTeam::invalidateMCRecords(); // Invalidate Memcached MultiTeam data.
}

// Sets toggles team admin status.
public static async function genSetAdmin(
int $team_id,
Expand Down