mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
В проект внедрён RabbitMQ.
Контроллер для работы с RabbitMQ научился создавать типизированные аргументы для $body Добавлена таблица с историей ников Добавлена таблица Mojang ников Добавлена проверка активированности аккаунта в AccountsController
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
<?php
|
||||
namespace console\controllers;
|
||||
|
||||
use common\components\RabbitMQ\Component as RabbitMQComponent;
|
||||
use common\components\Mojang\Api as MojangApi;
|
||||
use common\components\Mojang\exceptions\NoContentException;
|
||||
use common\models\amqp\UsernameChanged;
|
||||
use common\models\MojangUsername;
|
||||
use console\controllers\base\AmqpController;
|
||||
use Yii;
|
||||
|
||||
class AccountQueueController extends AmqpController {
|
||||
|
||||
@@ -16,17 +20,38 @@ class AccountQueueController extends AmqpController {
|
||||
|
||||
public function getExchangeDeclareArgs() {
|
||||
return array_replace(parent::getExchangeDeclareArgs(), [
|
||||
1 => RabbitMQComponent::TYPE_DIRECT, // exchange-type -> direct
|
||||
3 => false, // no-ack -> false
|
||||
3 => true, // durable -> true
|
||||
]);
|
||||
}
|
||||
|
||||
public function getQueueBindArgs($exchangeName, $queueName) {
|
||||
return [$exchangeName, $queueName, '#']; // Мы хотим получать сюда все события по аккаунту
|
||||
}
|
||||
public function routeUsernameChanged(UsernameChanged $body) {
|
||||
$mojangApi = new MojangApi();
|
||||
try {
|
||||
$response = $mojangApi->usernameToUUID($body->newUsername);
|
||||
} catch (NoContentException $e) {
|
||||
$response = false;
|
||||
}
|
||||
|
||||
public function routeChangeUsername($body) {
|
||||
// TODO: implement this
|
||||
/** @var MojangUsername|null $mojangUsername */
|
||||
$mojangUsername = MojangUsername::findOne($body->newUsername);
|
||||
if ($response === false) {
|
||||
if ($mojangUsername !== null) {
|
||||
$mojangUsername->delete();
|
||||
}
|
||||
} else {
|
||||
if ($mojangUsername === null) {
|
||||
$mojangUsername = new MojangUsername();
|
||||
$mojangUsername->username = $response->name;
|
||||
$mojangUsername->uuid = $response->id;
|
||||
} else {
|
||||
$mojangUsername->uuid = $response->id;
|
||||
$mojangUsername->touch('last_pulled_at');
|
||||
}
|
||||
|
||||
$mojangUsername->save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use console\db\Migration;
|
||||
|
||||
class m160414_231110_account_nicknames_history extends Migration {
|
||||
|
||||
public function safeUp() {
|
||||
$this->createTable('{{%usernames_history}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'username' => $this->string()->notNull(),
|
||||
'account_id' => $this->getDb()->getSchema()->getTableSchema('{{%accounts}}')->getColumn('id')->dbType . ' NOT NULL',
|
||||
'applied_in' => $this->integer()->notNull(),
|
||||
], $this->tableOptions);
|
||||
|
||||
$this->addForeignKey('FK_usernames_history_to_account', '{{%usernames_history}}', 'account_id', '{{%accounts}}', 'id', 'CASCADE', 'CASCADE');
|
||||
|
||||
$accountNicknames = $this->getDb()->createCommand('
|
||||
SELECT id,
|
||||
username,
|
||||
updated_at
|
||||
FROM {{%accounts}}
|
||||
')->queryAll();
|
||||
|
||||
foreach($accountNicknames as $row) {
|
||||
$this->insert('{{%usernames_history}}', [
|
||||
'username' => $row['username'],
|
||||
'account_id' => $row['id'],
|
||||
'applied_in' => $row['updated_at'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function safeDown() {
|
||||
$this->dropTable('{{%usernames_history}}');
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use console\db\Migration;
|
||||
|
||||
class m160422_230911_mojang_account_collisions extends Migration {
|
||||
|
||||
public function safeUp() {
|
||||
$this->createTable('{{%mojang_usernames}}', [
|
||||
'username' => $this->string()->notNull(),
|
||||
'uuid' => $this->string(32)->notNull(),
|
||||
'last_pulled_at' => $this->integer()->unsigned()->notNull(),
|
||||
], $this->tableOptions);
|
||||
|
||||
$this->addPrimaryKey('username', '{{%mojang_usernames}}', 'username');
|
||||
}
|
||||
|
||||
public function safeDown() {
|
||||
$this->dropTable('{{%mojang_usernames}}');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user