Remove minecraft_access_keys table and all related code

This commit is contained in:
ErickSkrauch
2024-06-14 05:42:35 +02:00
parent 2111e1769f
commit 0c110213f4
21 changed files with 69 additions and 321 deletions

View File

@@ -1,10 +1,8 @@
<?php
namespace console\controllers;
use Carbon\Carbon;
use common\models\AccountSession;
use common\models\EmailActivation;
use common\models\MinecraftAccessKey;
use common\models\OauthClient;
use common\tasks\ClearOauthSessions;
use Yii;
@@ -31,18 +29,6 @@ class CleanupController extends Controller {
return ExitCode::OK;
}
public function actionMinecraftSessions(): int {
$expiredMinecraftSessionsQuery = MinecraftAccessKey::find()
->andWhere(['<', 'updated_at', Carbon::now()->subMonths(3)->getTimestamp()]);
foreach ($expiredMinecraftSessionsQuery->each(100, Yii::$app->unbufferedDb) as $minecraftSession) {
/** @var MinecraftAccessKey $minecraftSession */
$minecraftSession->delete();
}
return ExitCode::OK;
}
/**
* Sessions that have not been refreshed for 90 days and those
* that have not been refreshed since they were issued more than 2 weeks ago

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use console\db\Migration;
class m240614_024554_drop_minecraft_access_keys_table extends Migration {
public function safeUp() {
$this->dropTable('minecraft_access_keys');
}
public function safeDown() {
$this->createTable('minecraft_access_keys', [
'access_token' => $this->string(36)->notNull(),
'client_token' => $this->string()->notNull(),
'account_id' => $this->db->getTableSchema('accounts')->getColumn('id')->dbType . ' NOT NULL',
'created_at' => $this->integer()->unsigned()->notNull(),
'updated_at' => $this->integer()->unsigned()->notNull(),
$this->primary('access_token'),
]);
$this->addForeignKey('FK_minecraft_access_token_to_account', 'minecraft_access_keys', 'account_id', 'accounts', 'id', 'CASCADE', 'CASCADE');
}
}

View File

@@ -5,7 +5,6 @@ namespace console\tests\unit\controllers;
use common\models\AccountSession;
use common\models\EmailActivation;
use common\models\MinecraftAccessKey;
use common\models\OauthClient;
use common\tasks\ClearOauthSessions;
use common\tests\fixtures;
@@ -18,7 +17,6 @@ class CleanupControllerTest extends TestCase {
public function _fixtures(): array {
return [
'emailActivations' => fixtures\EmailActivationFixture::class,
'minecraftSessions' => fixtures\MinecraftAccessKeyFixture::class,
'accountsSessions' => fixtures\AccountSessionFixture::class,
'oauthClients' => fixtures\OauthClientFixture::class,
'oauthSessions' => fixtures\OauthSessionFixture::class,
@@ -35,16 +33,6 @@ class CleanupControllerTest extends TestCase {
$this->tester->cantSeeRecord(EmailActivation::class, ['key' => $expiredConfirmation->key]);
}
public function testActionMinecraftSessions() {
/** @var MinecraftAccessKey $expiredSession */
$expiredSession = $this->tester->grabFixture('minecraftSessions', 'expired-token');
$controller = new CleanupController('cleanup', Yii::$app);
$this->assertSame(0, $controller->actionMinecraftSessions());
$this->tester->cantSeeRecord(MinecraftAccessKey::class, ['access_token' => $expiredSession->access_token]);
}
public function testActionWebSessions() {
/** @var AccountSession $expiredSession */
$expiredSession = $this->tester->grabFixture('accountsSessions', 'very-expired-session');