mirror of
https://github.com/elyby/accounts.git
synced 2024-11-30 02:32:26 +05:30
#272: удалены все следы использование таблицы oauth_access_tokens
This commit is contained in:
parent
dde85c1d50
commit
c029db82a1
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
namespace common\models;
|
||||
|
||||
use common\components\Redis\Set;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
/**
|
||||
* Поля:
|
||||
* @property string $access_token
|
||||
* @property string $session_id
|
||||
* @property integer $expire_time
|
||||
*
|
||||
* Геттеры:
|
||||
* @property Set $scopes
|
||||
*
|
||||
* Отношения:
|
||||
* @property OauthSession $session
|
||||
* @deprecated
|
||||
*/
|
||||
class OauthAccessToken extends ActiveRecord {
|
||||
|
||||
public static function tableName() {
|
||||
return '{{%oauth_access_tokens}}';
|
||||
}
|
||||
|
||||
public function getSession() {
|
||||
return $this->hasOne(OauthSession::class, ['id' => 'session_id']);
|
||||
}
|
||||
|
||||
public function getScopes() {
|
||||
return new Set(static::getDb()->getSchema()->getRawTableName(static::tableName()), $this->access_token, 'scopes');
|
||||
}
|
||||
|
||||
public function beforeDelete() {
|
||||
if (!$result = parent::beforeDelete()) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$this->getScopes()->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isExpired() : bool {
|
||||
return time() > $this->expire_time;
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +1,8 @@
|
||||
<?php
|
||||
namespace console\controllers;
|
||||
|
||||
use common\models\OauthAccessToken;
|
||||
use yii\console\Controller;
|
||||
|
||||
class CleanupController extends Controller {
|
||||
|
||||
public function actionAccessTokens() {
|
||||
$accessTokens = OauthAccessToken::find()
|
||||
->andWhere(['<', 'expire_time', time()])
|
||||
->each(1000);
|
||||
|
||||
foreach($accessTokens as $token) {
|
||||
/** @var OauthAccessToken $token */
|
||||
$token->delete();
|
||||
}
|
||||
|
||||
return self::EXIT_CODE_NORMAL;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use console\db\Migration;
|
||||
|
||||
class m161222_222520_remove_oauth_access_tokens extends Migration {
|
||||
|
||||
public function safeUp() {
|
||||
$this->dropForeignKey('FK_oauth_access_toke_to_oauth_session', '{{%oauth_access_tokens}}');
|
||||
$this->dropTable('{{%oauth_access_tokens}}');
|
||||
}
|
||||
|
||||
public function safeDown() {
|
||||
$this->createTable('{{%oauth_access_tokens}}', [
|
||||
'access_token' => $this->string(64),
|
||||
'session_id' => $this->getDb()->getTableSchema('{{%oauth_sessions}}')->getColumn('id')->dbType,
|
||||
'expire_time' => $this->integer()->notNull(),
|
||||
$this->primary('access_token'),
|
||||
], $this->tableOptions);
|
||||
|
||||
$this->addForeignKey(
|
||||
'FK_oauth_access_toke_to_oauth_session',
|
||||
'{{%oauth_access_tokens}}',
|
||||
'session_id',
|
||||
'{{%oauth_sessions}}',
|
||||
'id',
|
||||
'CASCADE',
|
||||
'SET NULL'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
namespace tests\codeception\common\fixtures;
|
||||
|
||||
use common\models\OauthAccessToken;
|
||||
use yii\test\ActiveFixture;
|
||||
|
||||
class OauthAccessTokenFixture extends ActiveFixture {
|
||||
|
||||
public $modelClass = OauthAccessToken::class;
|
||||
|
||||
public $dataFile = '@tests/codeception/common/fixtures/data/oauth-access-tokens.php';
|
||||
|
||||
public $depends = [
|
||||
OauthSessionFixture::class,
|
||||
];
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
return [
|
||||
'admin-test1' => [
|
||||
'access_token' => '07541285-831e-1e47-e314-b950309a6fca',
|
||||
'session_id' => 1,
|
||||
'expire_time' => time() + 3600,
|
||||
],
|
||||
'admin-test1-expired' => [
|
||||
'access_token' => '2977ec21-3022-96f8-544db-2e1df936908',
|
||||
'session_id' => 1,
|
||||
'expire_time' => time() - 3600,
|
||||
],
|
||||
];
|
@ -1,31 +1,8 @@
|
||||
<?php
|
||||
namespace codeception\console\unit\controllers;
|
||||
|
||||
use common\models\OauthAccessToken;
|
||||
use console\controllers\CleanupController;
|
||||
use tests\codeception\common\fixtures\OauthAccessTokenFixture;
|
||||
use tests\codeception\console\unit\TestCase;
|
||||
use Yii;
|
||||
|
||||
class CleanupControllerTest extends TestCase {
|
||||
|
||||
public function _fixtures() {
|
||||
return [
|
||||
'accessTokens' => OauthAccessTokenFixture::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function testActionAccessTokens() {
|
||||
/** @var OauthAccessToken $validAccessToken */
|
||||
$validAccessToken = $this->tester->grabFixture('accessTokens', 'admin-test1');
|
||||
/** @var OauthAccessToken $expiredAccessToken */
|
||||
$expiredAccessToken = $this->tester->grabFixture('accessTokens', 'admin-test1-expired');
|
||||
|
||||
$controller = new CleanupController('cleanup', Yii::$app);
|
||||
$this->assertEquals(0, $controller->actionAccessTokens());
|
||||
|
||||
$this->tester->canSeeRecord(OauthAccessToken::class, ['access_token' => $validAccessToken->access_token]);
|
||||
$this->tester->cantSeeRecord(OauthAccessToken::class, ['access_token' => $expiredAccessToken->access_token]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user