mirror of
https://github.com/elyby/accounts.git
synced 2024-11-14 09:16:22 +05:30
cba769a1ec
Контроллер для работы с RabbitMQ научился создавать типизированные аргументы для $body Добавлена таблица с историей ников Добавлена таблица Mojang ников Добавлена проверка активированности аккаунта в AccountsController
58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
namespace console\controllers;
|
|
|
|
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 {
|
|
|
|
public function getExchangeName() {
|
|
return 'account';
|
|
}
|
|
|
|
public function getQueueName() {
|
|
return 'account-operations';
|
|
}
|
|
|
|
public function getExchangeDeclareArgs() {
|
|
return array_replace(parent::getExchangeDeclareArgs(), [
|
|
3 => true, // durable -> true
|
|
]);
|
|
}
|
|
|
|
public function routeUsernameChanged(UsernameChanged $body) {
|
|
$mojangApi = new MojangApi();
|
|
try {
|
|
$response = $mojangApi->usernameToUUID($body->newUsername);
|
|
} catch (NoContentException $e) {
|
|
$response = false;
|
|
}
|
|
|
|
/** @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;
|
|
}
|
|
|
|
}
|