2016-11-24 02:11:33 +05:30
|
|
|
|
<?php
|
|
|
|
|
namespace console\controllers;
|
|
|
|
|
|
2017-03-07 22:44:54 +05:30
|
|
|
|
use common\models\EmailActivation;
|
2016-11-24 02:11:33 +05:30
|
|
|
|
use yii\console\Controller;
|
|
|
|
|
|
|
|
|
|
class CleanupController extends Controller {
|
|
|
|
|
|
2017-06-12 00:39:07 +05:30
|
|
|
|
public function actionTest() {
|
|
|
|
|
$validator = \Yii::createObject(\api\components\ReCaptcha\Validator::class);
|
|
|
|
|
var_dump($validator);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 22:44:54 +05:30
|
|
|
|
public function actionEmailKeys() {
|
|
|
|
|
$query = EmailActivation::find();
|
|
|
|
|
$conditions = ['OR'];
|
|
|
|
|
foreach ($this->getEmailActivationsDurationsMap() as $typeId => $expiration) {
|
|
|
|
|
$conditions[] = [
|
|
|
|
|
'AND',
|
|
|
|
|
['type' => $typeId],
|
|
|
|
|
['<', 'created_at', time() - $expiration],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 16:49:24 +05:30
|
|
|
|
/** @var \yii\db\BatchQueryResult|EmailActivation[] $expiredEmails */
|
|
|
|
|
$expiredEmails = $query->andWhere($conditions)->each();
|
2017-03-07 22:44:54 +05:30
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 02:11:33 +05:30
|
|
|
|
}
|