Added activity mail summary queuing

This commit is contained in:
Lucas Bartholemy 2017-01-18 12:49:25 +01:00
parent e149b8be7e
commit e0720e9964
2 changed files with 46 additions and 3 deletions

View File

@ -9,8 +9,8 @@
namespace humhub\modules\activity;
use Yii;
use humhub\modules\activity\components\MailSummaryProcessor;
use humhub\modules\activity\components\MailSummary;
use humhub\modules\activity\jobs\SendMailSummary;
use humhub\modules\activity\models\Activity;
/**
@ -29,9 +29,9 @@ class Events extends \yii\base\Object
public static function onCronRun($event)
{
if (Yii::$app->controller->action->id == 'hourly') {
MailSummaryProcessor::process(MailSummary::INTERVAL_HOURY);
Yii::$app->queue->push(new SendMailSummary(['interval' => MailSummary::INTERVAL_HOURY]));
} elseif (Yii::$app->controller->action->id == 'daily') {
MailSummaryProcessor::process(MailSummary::INTERVAL_DAILY);
Yii::$app->queue->push(new SendMailSummary(['interval' => MailSummary::INTERVAL_DAILY]));
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\activity\jobs;
use Yii;
use humhub\components\queue\ActiveJob;
use humhub\modules\activity\components\MailSummaryProcessor;
use humhub\modules\activity\components\MailSummary;
/**
* SendMailSummary
*
* @since 1.2
* @author Luke
*/
class SendMailSummary extends ActiveJob
{
/**
* @var int the interval
*/
public $interval;
/**
* @inheritdoc
*/
public function run()
{
if ($this->interval === MailSummary::INTERVAL_DAILY || $this->interval === MailSummary::INTERVAL_HOURY) {
MailSummaryProcessor::process($this->interval);
} else {
Yii::error('Invalid summary interval given'. $this->interval, 'activity.job');
return;
}
}
}