Merge branch 'develop'

This commit is contained in:
ErickSkrauch 2017-03-29 13:53:55 +03:00
commit 96c6992f73
7 changed files with 67 additions and 1 deletions

View File

@ -48,6 +48,7 @@ class Component extends \yii\base\Component {
$authServer->setAuthCodeStorage(new AuthCodeStorage());
$authServer->setRefreshTokenStorage(new RefreshTokenStorage());
$authServer->setScopeDelimiter(',');
$authServer->setAccessTokenTTL(86400); // 1d
$this->_authServer = $authServer;

View File

@ -1,6 +1,6 @@
<?php
return [
'version' => '1.1.7',
'version' => '1.1.8',
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [

View File

@ -1,8 +1,45 @@
<?php
namespace console\controllers;
use common\models\EmailActivation;
use yii\console\Controller;
class CleanupController extends Controller {
public function actionEmailKeys() {
$query = EmailActivation::find();
$conditions = ['OR'];
foreach ($this->getEmailActivationsDurationsMap() as $typeId => $expiration) {
$conditions[] = [
'AND',
['type' => $typeId],
['<', 'created_at', time() - $expiration],
];
}
/** @var EmailActivation[] $expiredEmails */
$expiredEmails = $query->andWhere($conditions)->all();
foreach ($expiredEmails as $email) {
$email->delete();
}
return self::EXIT_CODE_NORMAL;
}
private function getEmailActivationsDurationsMap(): array {
$durationsMap = [];
foreach (EmailActivation::getClassMap() as $typeId => $className) {
/** @var EmailActivation $object */
$object = new $className;
/** @var \common\behaviors\EmailActivationExpirationBehavior $behavior */
$behavior = $object->getBehavior('expirationBehavior');
$expiration = $behavior->expirationTimeout ?? 1123200; // 13d по умолчанию
// Приращаем 1 день, чтобы пользователи ещё могли получать сообщения об истечении кода активации
/** @noinspection SummerTimeUnsafeTimeManipulationInspection */
$durationsMap[$typeId] = $expiration + 86400;
}
return $durationsMap;
}
}

View File

2
docker/cron/cleanup Normal file
View File

@ -0,0 +1,2 @@
# https://crontab.guru/every-day
0 0 * * * root /usr/local/bin/php /var/www/html/yii cleanup/email-keys >/dev/null 2>&1

View File

@ -37,4 +37,10 @@ return [
'_data' => serialize(['newEmail' => 'my-new-email@ely.by']),
'created_at' => time() - 10,
],
'deeplyExpiredConfirmation' => [
'key' => 'H29HBDCHHAG2HGHGHS',
'account_id' => 1,
'type' => \common\models\EmailActivation::TYPE_NEW_EMAIL_CONFIRMATION,
'created_at' => 1487695872,
],
];

View File

@ -1,8 +1,28 @@
<?php
namespace codeception\console\unit\controllers;
use common\models\EmailActivation;
use console\controllers\CleanupController;
use tests\codeception\common\fixtures\EmailActivationFixture;
use tests\codeception\console\unit\TestCase;
use Yii;
class CleanupControllerTest extends TestCase {
public function _fixtures() {
return [
'emailActivations' => EmailActivationFixture::class,
];
}
public function testActionAccessTokens() {
/** @var EmailActivation $expiredConfirmation */
$expiredConfirmation = $this->tester->grabFixture('emailActivations', 'deeplyExpiredConfirmation');
$controller = new CleanupController('cleanup', Yii::$app);
$this->assertEquals(0, $controller->actionEmailKeys());
$this->tester->cantSeeRecord(EmailActivation::className(), ['key' => $expiredConfirmation->key]);
}
}