Commit 730f010c authored by Олег Гиммельшпах's avatar Олег Гиммельшпах

Merge branch 'master' of git.task-on.com:ktask/task-on.com

parents 4113e5d5 783d1add
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace common\modules\bids\models; namespace common\modules\bids\models;
use common\modules\users\models\User;
use Yii; use Yii;
use common\models\Settings; use common\models\Settings;
...@@ -145,4 +146,19 @@ class Bid extends \common\components\ActiveRecordModel ...@@ -145,4 +146,19 @@ class Bid extends \common\components\ActiveRecordModel
{ {
} }
} }
/**
* @param bool $insert
* @param array $changedAttributes
* @return bool
*/
public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
/** @var User $user */
$user = User::find()->where(['email' => $this->email])->one();
if (!is_null($user)) {
$user->afterSubscribe(['email' => $this->email], true);
}
}
} }
...@@ -68,6 +68,7 @@ class DefaultController extends BaseController ...@@ -68,6 +68,7 @@ class DefaultController extends BaseController
* Метод для крона и ручного вызова. Проверяет таблицу с расписанием, выполняет сработавшие триггеры. * Метод для крона и ручного вызова. Проверяет таблицу с расписанием, выполняет сработавшие триггеры.
*/ */
public function actionRechecktriggers(){ public function actionRechecktriggers(){
set_time_limit(5000);
// Производим проверку по расписанию // Производим проверку по расписанию
/** @var TriggerTrigger[] $actualTriggers */ /** @var TriggerTrigger[] $actualTriggers */
// Получили текущую дату и время // Получили текущую дату и время
...@@ -116,6 +117,15 @@ class DefaultController extends BaseController ...@@ -116,6 +117,15 @@ class DefaultController extends BaseController
} }
} }
/**
* Вызов логики, проверяющей список всех пользователей и просмотренные ими страницы.
* В случае если юзер не смотрел какой либо из кейсов, выбирается и отправляется ОДИН
* случайный кейс из просмотренных.
*
* @param int $category_id
* @param int $template_id
* @param int $neededTime
*/
public function actionRecheckcases($category_id = 4, $template_id=1, $neededTime=10) { public function actionRecheckcases($category_id = 4, $template_id=1, $neededTime=10) {
$date = new \DateTime(); $date = new \DateTime();
/** @var User[] $users */ /** @var User[] $users */
......
...@@ -26,7 +26,7 @@ class TriggerLogs extends \yii\db\ActiveRecord ...@@ -26,7 +26,7 @@ class TriggerLogs extends \yii\db\ActiveRecord
public static function logAction() public static function logAction()
{ {
if (!Yii::$app->user->isGuest && !Yii::$app->request->isAjax) { if (!Yii::$app->user->isGuest && Yii::$app->controller->action->id!='settimeoflogs'/*&& !Yii::$app->request->isAjax*/) {
$action = self::USER_VISITED; $action = self::USER_VISITED;
if (Yii::$app->controller->action->id=='registration') if (Yii::$app->controller->action->id=='registration')
$action = self::USER_REGISTRATION; $action = self::USER_REGISTRATION;
......
...@@ -221,7 +221,7 @@ class TriggerTrigger extends \common\components\ActiveRecordModel ...@@ -221,7 +221,7 @@ class TriggerTrigger extends \common\components\ActiveRecordModel
elseif(empty($email) && !Yii::$app->user->isGuest) { elseif(empty($email) && !Yii::$app->user->isGuest) {
$email = Yii::$app->user->identity->email; $email = Yii::$app->user->identity->email;
} else { } else {
return 'Email not found'; return 'Trigger initiate error. Email not found';
} }
$user = User::find()->where(['email' => $email])->one(); $user = User::find()->where(['email' => $email])->one();
......
...@@ -641,7 +641,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -641,7 +641,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
* @param array $params * @param array $params
* @return bool * @return bool
*/ */
public function afterSubscribe($params=array()){ public function afterSubscribe($params=array(), $return=false){
$date = new \DateTime(); $date = new \DateTime();
/** @var TriggerTrigger[] $actualTriggers */ /** @var TriggerTrigger[] $actualTriggers */
$actualTriggers = TriggerTrigger::getActualTriggers(); $actualTriggers = TriggerTrigger::getActualTriggers();
...@@ -655,30 +655,48 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -655,30 +655,48 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
// Указываем дату следующей отправки (по умолчанию сегодня, в момент срабатывания триггера) // Указываем дату следующей отправки (по умолчанию сегодня, в момент срабатывания триггера)
$user=User::findOne($this->id); $user=User::findOne($this->id);
$user->delivery_date = $date->format('Y-m-d'); $user->delivery_date = $date->format('Y-m-d');
$user->save(false); if ($user->save()) {
// Вызываем перезапуск всех триггеров // Вызываем перезапуск всех триггеров
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, Yii::$app->urlManager->createAbsoluteUrl('/triggers/default/rechecktriggers')); curl_setopt($curl, CURLOPT_URL, Yii::$app->urlManager->createAbsoluteUrl('/triggers/default/rechecktriggers'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (!curl_exec($curl)) { if (!curl_exec($curl)) {
if ($return===false) {
$this->addError('email', curl_error($curl)); $this->addError('email', curl_error($curl));
return false; return false;
} else
return curl_error($curl);
} }
// Затем инициируем рассылку // Затем инициируем рассылку
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, Yii::$app->urlManager->createAbsoluteUrl('/triggers/default/recheckcases')); curl_setopt($curl, CURLOPT_URL, Yii::$app->urlManager->createAbsoluteUrl('/triggers/default/recheckcases'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (!curl_exec($curl)) { if (!curl_exec($curl)) {
if ($return===false) {
$this->addError('email', curl_error($curl)); $this->addError('email', curl_error($curl));
return false; return false;
} else
return curl_error($curl);
} }
return true; return true;
} else { } else {
if ($return===false) {
$this->addError('email', current(current($user->getErrors())));
return false;
} else
return current(current($user->getErrors()));
}
} else {
if ($return===false) {
$this->addError('email', $init); $this->addError('email', $init);
return false; return false;
} else {
return $init;
}
} }
} }
} }
return true;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment