1
0
mirror of https://github.com/elyby/accounts.git synced 2025-03-14 15:54:25 +05:30
ErickSkrauch c0aa78d156 Implemented WebHooks delivery queue.
Completely removed usage of the RabbitMQ. Queue now based on Redis channels.
Worker process now extracted as separate docker container.
Base image upgraded to the 1.8.0 version (PHP 7.2.7 and pcntl extension).
2018-07-08 18:20:19 +03:00

42 lines
1005 B
PHP

<?php
namespace api\modules\accounts\models;
use api\exceptions\ThisShouldNotHappenException;
use api\modules\internal\helpers\Error as E;
use common\models\Account;
use Yii;
class PardonAccountForm extends AccountActionForm {
public function rules(): array {
return [
[['account'], 'validateAccountBanned'],
];
}
public function validateAccountBanned(): void {
if ($this->getAccount()->status !== Account::STATUS_BANNED) {
$this->addError('account', E::ACCOUNT_NOT_BANNED);
}
}
public function performAction(): bool {
if (!$this->validate()) {
return false;
}
$transaction = Yii::$app->db->beginTransaction();
$account = $this->getAccount();
$account->status = Account::STATUS_ACTIVE;
if (!$account->save()) {
throw new ThisShouldNotHappenException('Cannot pardon account');
}
$transaction->commit();
return true;
}
}