mirror of
https://github.com/humhub/humhub.git
synced 2025-04-21 15:41:54 +02:00
Migrated Cron
This commit is contained in:
parent
8eb4261a54
commit
d51021e67f
@ -21,8 +21,4 @@ $config = yii\helpers\ArrayHelper::merge(
|
||||
require(__DIR__ . '/protected/config/web.php')
|
||||
);
|
||||
|
||||
Yii::setAlias('@webroot', __DIR__);
|
||||
Yii::setAlias('@app', __DIR__ . DIRECTORY_SEPARATOR . 'protected');
|
||||
Yii::setAlias('@humhub', '@app/humhub');
|
||||
|
||||
(new humhub\components\Application($config))->run();
|
||||
|
@ -11,17 +11,51 @@ namespace humhub\commands;
|
||||
use Yii;
|
||||
use yii\console\Controller;
|
||||
use yii\helpers\Console;
|
||||
use humhub\models\Setting;
|
||||
|
||||
/**
|
||||
* CronCrontroller
|
||||
*
|
||||
* @author Luke
|
||||
*/
|
||||
class CronController extends \yii\console\controller
|
||||
class CronController extends Controller
|
||||
{
|
||||
|
||||
const EVENT_ON_HOURLY_RUN = "hourly";
|
||||
const EVENT_ON_DAILY_RUN = "daily";
|
||||
const EVENT_ON_WEEKLY_RUN = "weekly";
|
||||
|
||||
public function actionHourly()
|
||||
{
|
||||
$this->stdout("Executing hourly tasks:\n\n", Console::FG_YELLOW);
|
||||
|
||||
$this->trigger(self::EVENT_ON_HOURLY_RUN);
|
||||
|
||||
$this->stdout("\n\nAll cron tasks finished.\n\n", Console::FG_GREEN);
|
||||
Setting::Set('cronLastHourlyRun', time());
|
||||
|
||||
return self::EXIT_CODE_NORMAL;
|
||||
}
|
||||
|
||||
public function actionDaily()
|
||||
{
|
||||
$this->stdout("Executing daily tasks:\n\n", Console::FG_YELLOW);
|
||||
|
||||
$this->trigger(self::EVENT_ON_DAILY_RUN);
|
||||
|
||||
$this->stdout("\n\nAll cron tasks finished.\n\n", Console::FG_GREEN);
|
||||
Setting::Set('cronLastDailyRun', time());
|
||||
|
||||
return self::EXIT_CODE_NORMAL;
|
||||
}
|
||||
|
||||
public function beginTask($taskName)
|
||||
{
|
||||
$this->stdout("\t* " . $taskName . ": ", Console::FG_GREY);
|
||||
}
|
||||
|
||||
public function endTask()
|
||||
{
|
||||
$this->stdout(" OK!\n", Console::FG_GREEN);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,9 @@
|
||||
|
||||
namespace humhub\components\console;
|
||||
|
||||
use Yii;
|
||||
use humhub\models\Setting;
|
||||
|
||||
/**
|
||||
* Description of Application
|
||||
*
|
||||
@ -28,8 +31,13 @@ class Application extends \yii\console\Application
|
||||
{
|
||||
parent::init();
|
||||
$this->trigger(self::EVENT_ON_INIT);
|
||||
|
||||
$baseUrl = Setting::get('baseUrl');
|
||||
|
||||
Yii::setAlias(("@web"), $baseUrl);
|
||||
$this->urlManager->scriptUrl = $baseUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the configuration of the built-in commands.
|
||||
* @return array the configuration of the built-in commands.
|
||||
|
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
Yii::setAlias('@webroot', __DIR__ . '/../../../');
|
||||
|
||||
Yii::setAlias('@app', '@webroot/protected');
|
||||
Yii::setAlias('@humhub', '@app/humhub');
|
||||
|
||||
$config = [
|
||||
'version' => '0.20',
|
||||
'basePath' => dirname(__DIR__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR,
|
||||
|
@ -19,6 +19,10 @@ $config = [
|
||||
'errorHandler' => [
|
||||
'errorAction' => 'site/error',
|
||||
],
|
||||
'session' => [
|
||||
'class' => 'humhub\core\user\components\Session',
|
||||
'sessionTable' => 'user_http_session',
|
||||
],
|
||||
],
|
||||
'modules' => [],
|
||||
];
|
||||
|
@ -2,6 +2,12 @@
|
||||
|
||||
namespace humhub\core\activity;
|
||||
|
||||
use Yii;
|
||||
use humhub\models\Setting;
|
||||
use humhub\core\user\models\User;
|
||||
use humhub\commands\CronController;
|
||||
use humhub\core\activity\components\BaseActivity;
|
||||
|
||||
/**
|
||||
* ActivityModule is responsible for all activities functions.
|
||||
*
|
||||
@ -12,17 +18,55 @@ namespace humhub\core\activity;
|
||||
class Module extends \yii\base\Module
|
||||
{
|
||||
|
||||
/**
|
||||
* Formatted the activity content before delivery
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public static function formatOutput($text)
|
||||
public function getMailUpdate(User $user, $interval)
|
||||
{
|
||||
$text = HHtml::translateMentioning($text, false);
|
||||
$text = HHtml::translateEmojis($text, false);
|
||||
$output = "";
|
||||
|
||||
return $text;
|
||||
$receive_email_activities = $user->getSetting("receive_email_activities", 'core', Setting::Get('receive_email_activities', 'mailing'));
|
||||
|
||||
// User never wants activity content
|
||||
if ($receive_email_activities == User::RECEIVE_EMAIL_NEVER) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// We are in hourly mode and user wants receive a daily summary
|
||||
if ($interval == CronController::EVENT_ON_HOURLY_RUN && $receive_email_activities == User::RECEIVE_EMAIL_DAILY_SUMMARY) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// We are in daily mode and user wants receive not daily
|
||||
if ($interval == CronController::EVENT_ON_DAILY_RUN && $receive_email_activities != User::RECEIVE_EMAIL_DAILY_SUMMARY) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// User is online and want only receive when offline
|
||||
if ($interval == CronController::EVENT_ON_HOURLY_RUN) {
|
||||
$isOnline = (count($user->httpSessions) > 0);
|
||||
if ($receive_email_activities == User::RECEIVE_EMAIL_WHEN_OFFLINE && $isOnline) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
$lastMailDate = $user->last_activity_email;
|
||||
if ($lastMailDate == "" || $lastMailDate == "0000-00-00 00:00:00") {
|
||||
$lastMailDate = new \yii\db\Expression('NOW() - INTERVAL 24 HOUR');
|
||||
}
|
||||
|
||||
$stream = new \humhub\core\dashboard\components\actions\DashboardStream('stream', Yii::$app->controller);
|
||||
$stream->limit = 50;
|
||||
$stream->mode = \humhub\core\content\components\actions\Stream::MODE_ACTIVITY;
|
||||
$stream->user = $user;
|
||||
$stream->init();
|
||||
$stream->activeQuery->andWhere(['>', 'content.created_at', $lastMailDate]);
|
||||
|
||||
foreach ($stream->getWallEntries() as $wallEntry) {
|
||||
$output .= $wallEntry->content->getUnderlyingObject()->getClass()->render(BaseActivity::OUTPUT_MAIL);
|
||||
}
|
||||
|
||||
$user->last_activity_email = new \yii\db\Expression('NOW()');
|
||||
$user->save();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,6 +116,11 @@ class BaseActivity extends \yii\base\Component
|
||||
} elseif ($this->source instanceof ContentContainer) {
|
||||
$model->content->visibility = $this->visibility;
|
||||
$model->content->container = $this->source;
|
||||
|
||||
if (Yii::$app->user->isGuest) {
|
||||
$model->content->created_by = $this->originator->id;
|
||||
$model->created_by = $this->originator->id;
|
||||
}
|
||||
} else {
|
||||
throw new \yii\base\Exception("Invalid source object type!");
|
||||
}
|
||||
@ -137,6 +142,7 @@ class BaseActivity extends \yii\base\Component
|
||||
$params['originator'] = $this->originator;
|
||||
$params['source'] = $this->source;
|
||||
$params['record'] = $this->record;
|
||||
$params['url'] = $this->getUrl();
|
||||
$params['clickable'] = $this->clickable;
|
||||
|
||||
$viewFile = $this->getViewPath() . '/' . $this->viewName . '.php';
|
||||
@ -151,7 +157,7 @@ class BaseActivity extends \yii\base\Component
|
||||
|
||||
$params['content'] = Yii::$app->getView()->renderFile($viewFile, $params, $this);
|
||||
|
||||
return Yii::$app->getView()->renderFile($this->layoutWeb, $params, $this);
|
||||
return Yii::$app->getView()->renderFile(($mode == self::OUTPUT_WEB) ? $this->layoutWeb : $this->layoutMail, $params, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,7 +173,7 @@ class BaseActivity extends \yii\base\Component
|
||||
{
|
||||
return \yii\helpers\Html::encode($content->getContentTitle()) .
|
||||
' "' .
|
||||
\humhub\widgets\RichText::widget(['text' => $content->getContentPreview(), 'minimal' => true, 'maxLength' => 60]).'"';
|
||||
\humhub\widgets\RichText::widget(['text' => $content->getContentPreview(), 'minimal' => true, 'maxLength' => 60]) . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,3 +1,7 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
?>
|
||||
<!-- START NOTIFICATION/ACTIVITY -->
|
||||
<tr>
|
||||
<td align="center" valign="top" class="fix-box">
|
||||
@ -35,9 +39,9 @@
|
||||
|
||||
<td valign="top" align="left" style="padding-right:20px;">
|
||||
<!-- START: USER IMAGE -->
|
||||
<a href="<?php echo Yii::app()->createAbsoluteUrl('user/profile', array('guid' => $activity->content->user->guid)); ?>">
|
||||
<a href="<?php echo $originator->createUrl('/user/profile', [], true); ?>">
|
||||
<img
|
||||
src="<?php echo $activity->content->user->getProfileImage()->getUrl(); ?>"
|
||||
src="<?php echo $originator->getProfileImage()->getUrl(); ?>"
|
||||
width="50"
|
||||
alt=""
|
||||
style="max-width:50px; display:block !important; border-radius: 4px;"
|
||||
@ -58,36 +62,26 @@
|
||||
<!-- content output-->
|
||||
<?php echo $content; ?>
|
||||
|
||||
<!-- check if variable exists and is true -->
|
||||
<?php if (!empty($showSpace)) : ?>
|
||||
|
||||
<!-- check if variable is true -->
|
||||
<?php if ($showSpace == true) : ?>
|
||||
|
||||
<!-- check if activity object has a space -->
|
||||
<?php if ($activity->content->space != null): ?>
|
||||
(<?php echo Yii::t('ActivityModule.views_activityLayoutMail', 'via'); ?>
|
||||
<a href="<?php echo Yii::app()->createUrl('space/space', array('sguid' => $activity->content->space->guid)); ?>"
|
||||
style="text-decoration: none; color: #555555;">
|
||||
<?php echo CHtml::encode($activity->content->space->name); ?>
|
||||
</a>)
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($activity->getUnderlyingObject() != null) : ?>
|
||||
<!-- START: CONTENT LINK -->
|
||||
<span
|
||||
style="text-decoration: none; color: #7191a8;"> - <a
|
||||
href="<?php echo Yii::app()->createUrl('wall/perma/content', array('model' => get_class($activity->getUnderlyingObject()), 'id' => $activity->getUnderlyingObject()->getPrimaryKey())); ?>"
|
||||
style="text-decoration: none; color: #7191a8; "><?php echo Yii::t('ActivityModule.views_activityLayoutMail', 'see online'); ?></a></span>
|
||||
<!-- END: CONTENT LINK -->
|
||||
<?php endif; ?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- check if activity object has a space -->
|
||||
<?php if ($record->content->space !== null): ?>
|
||||
(<?php echo Yii::t('ActivityModule.views_activityLayoutMail', 'via'); ?>
|
||||
<a href="<?php echo $record->content->space->createUrl('/space/space', [], true); ?>"
|
||||
style="text-decoration: none; color: #555555;">
|
||||
<?php echo Html::encode($record->content->space->name); ?>
|
||||
</a>)
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($url != "") : ?>
|
||||
<!-- START: CONTENT LINK -->
|
||||
<span
|
||||
style="text-decoration: none; color: #7191a8;"> - <a
|
||||
href="<?php echo $url; ?>"
|
||||
style="text-decoration: none; color: #7191a8; "><?php echo Yii::t('ActivityModule.views_activityLayoutMail', 'see online'); ?></a></span>
|
||||
<!-- END: CONTENT LINK -->
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace humhub\core\admin;
|
||||
|
||||
use Yii;
|
||||
use humhub\core\admin\libs\OnlineModuleManager;
|
||||
|
||||
/**
|
||||
* @package humhub.modules_core.admin
|
||||
@ -24,26 +25,30 @@ class Events extends \yii\base\Object
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a new Humhub Version available
|
||||
* Check if there is a new Humhub Version available and sends a notification
|
||||
* to super admins
|
||||
*
|
||||
* @param type $event
|
||||
* @param \yii\base\Event $event
|
||||
*/
|
||||
public static function onCronDailyRun($event)
|
||||
{
|
||||
Yii::import('application.modules_core.admin.libs.*');
|
||||
$cron = $event->sender;
|
||||
$controller = $event->sender;
|
||||
|
||||
if (!Yii::app()->getModule('admin')->marketplaceEnabled) {
|
||||
if (!Yii::$app->getModule('admin')->marketplaceEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$controller->stdout("Checking for new HumHub version... ");
|
||||
|
||||
$onlineModuleManager = new OnlineModuleManager();
|
||||
$latestVersion = $onlineModuleManager->getLatestHumHubVersion();
|
||||
|
||||
if ($latestVersion != "" && version_compare($latestVersion, HVersion::VERSION, ">")) {
|
||||
$notification = new notifications\NewVersionAvailable;
|
||||
if ($latestVersion != "" && version_compare($latestVersion, Yii::$app->version, ">")) {
|
||||
$notification = new notifications\NewVersionAvailable();
|
||||
$notification->add(User::find()->where(['super_admin' => 1]));
|
||||
}
|
||||
|
||||
$controller->stdout('done. ' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,12 @@
|
||||
|
||||
namespace humhub\core\content;
|
||||
|
||||
use Yii;
|
||||
use humhub\core\content\models\Content;
|
||||
use humhub\core\user\models\User;
|
||||
use humhub\commands\CronController;
|
||||
use humhub\models\Setting;
|
||||
use yii\helpers\Console;
|
||||
|
||||
/**
|
||||
* Description of Events
|
||||
@ -85,4 +90,61 @@ class Events extends \yii\base\Object
|
||||
);
|
||||
}
|
||||
|
||||
public static function onCronRun($event)
|
||||
{
|
||||
$controller = $event->sender;
|
||||
|
||||
$interval = "";
|
||||
if (Yii::$app->controller->action->id == 'hourly') {
|
||||
$interval = CronController::EVENT_ON_HOURLY_RUN;
|
||||
} elseif (Yii::$app->controller->action->id == 'daily') {
|
||||
$interval = CronController::EVENT_ON_DAILY_RUN;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$users = User::find()->joinWith(['httpSessions', 'profile'])->where(['status' => User::STATUS_ENABLED]);
|
||||
$totalUsers = $users->count();
|
||||
$done = 0;
|
||||
$mailsSent = 0;
|
||||
$defaultLanguage = Yii::$app->language;
|
||||
|
||||
Console::startProgress($done, $totalUsers, 'Sending update e-mails to users... ', false);
|
||||
foreach ($users->each() as $user) {
|
||||
|
||||
// Check user should receive an email
|
||||
Yii::$app->user->switchIdentity($user);
|
||||
if ($user->language != "") {
|
||||
Yii::$app->language = $user->language;
|
||||
} else {
|
||||
Yii::$app->language = $defaultLanguage;
|
||||
}
|
||||
|
||||
$notifications = Yii::$app->getModule('notification')->getMailUpdate($user, $interval);
|
||||
$activities = Yii::$app->getModule('activity')->getMailUpdate($user, $interval);
|
||||
|
||||
if ($notifications != "" || $activities != "") {
|
||||
$mail = Yii::$app->mailer->compose(['html' => '@humhub/core/content/views/mails/Update'], [
|
||||
'activities' => $activities,
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
$mail->setFrom([Setting::Get('systemEmailAddress', 'mailing') => Setting::Get('systemEmailName', 'mailing')]);
|
||||
$mail->setTo($user->email);
|
||||
if ($interval == CronController::EVENT_ON_HOURLY_RUN) {
|
||||
$mail->setSubject(Yii::t('base', "Latest news"));
|
||||
} else {
|
||||
$mail->setSubject(Yii::t('base', "Your daily summary"));
|
||||
}
|
||||
$mail->send();
|
||||
|
||||
$mailsSent++;
|
||||
}
|
||||
|
||||
Console::updateProgress(++$done, $totalUsers);
|
||||
}
|
||||
|
||||
Console::endProgress(true);
|
||||
$controller->stdout('done - ' . $mailsSent . ' email(s) sent.' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,4 +8,4 @@ echo Yii::t('PostModule.views_activities_PostCreated', '{displayName} created a
|
||||
));
|
||||
?>
|
||||
<br />
|
||||
<em>"<?php echo \humhub\widgets\RichText::widget(['text' => $target->message, 'minimal' => true]); ?>"</em>
|
||||
<em>"<?php echo \humhub\widgets\RichText::widget(['text' => $source->getContentPreview(), 'minimal' => true]); ?>"</em>
|
||||
|
@ -4,15 +4,18 @@ use humhub\core\content\Events;
|
||||
use humhub\commands\IntegrityController;
|
||||
use humhub\core\content\widgets\WallEntryControls;
|
||||
use humhub\core\content\widgets\WallEntryAddons;
|
||||
use humhub\commands\CronController;
|
||||
|
||||
\Yii::$app->moduleManager->register(array(
|
||||
'id' => 'content',
|
||||
'class' => \humhub\core\content\Module::className(),
|
||||
'isCoreModule' => true,
|
||||
'events' => array(
|
||||
array('class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array(Events::className(), 'onIntegrityCheck')),
|
||||
array('class' => WallEntryControls::className(), 'event' => WallEntryControls::EVENT_INIT, 'callback' => array(Events::className(), 'onWallEntryControlsInit')),
|
||||
array('class' => WallEntryAddons::className(), 'event' => WallEntryAddons::EVENT_INIT, 'callback' => array(Events::className(), 'onWallEntryAddonInit')),
|
||||
['class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array(Events::className(), 'onIntegrityCheck')],
|
||||
['class' => WallEntryControls::className(), 'event' => WallEntryControls::EVENT_INIT, 'callback' => array(Events::className(), 'onWallEntryControlsInit')],
|
||||
['class' => WallEntryAddons::className(), 'event' => WallEntryAddons::EVENT_INIT, 'callback' => array(Events::className(), 'onWallEntryAddonInit')],
|
||||
['class' => CronController::className(), 'event' => CronController::EVENT_ON_HOURLY_RUN, 'callback' => [Events::className(), 'onCronRun']],
|
||||
['class' => CronController::className(), 'event' => CronController::EVENT_ON_DAILY_RUN, 'callback' => [Events::className(), 'onCronRun']],
|
||||
),
|
||||
));
|
||||
?>
|
@ -109,25 +109,28 @@ class Stream extends \yii\base\Action
|
||||
$this->user = Yii::$app->user->getIdentity();
|
||||
}
|
||||
|
||||
|
||||
// Read parameters
|
||||
$from = Yii::$app->getRequest()->get('from', 0);
|
||||
if ($from != 0) {
|
||||
$this->from = $from;
|
||||
}
|
||||
$sort = Yii::$app->getRequest()->get('sort', '');
|
||||
if ($sort != "") {
|
||||
$this->sort = $sort;
|
||||
}
|
||||
$limit = Yii::$app->getRequest()->get('limit', '');
|
||||
if ($limit != "" && $limit <= self::MAX_LIMIT) {
|
||||
$this->limit = $limit;
|
||||
}
|
||||
$mode = Yii::$app->getRequest()->get('mode', '');
|
||||
if ($mode != "" && ($mode == self::MODE_ACTIVITY || $mode == self::MODE_NORMAL)) {
|
||||
$this->mode = $mode;
|
||||
}
|
||||
foreach (explode(',', Yii::$app->getRequest()->get('filters', "")) as $filter) {
|
||||
$this->filters[] = trim($filter);
|
||||
if (!Yii::$app->request->isConsoleRequest) {
|
||||
$from = Yii::$app->getRequest()->get('from', 0);
|
||||
if ($from != 0) {
|
||||
$this->from = $from;
|
||||
}
|
||||
$sort = Yii::$app->getRequest()->get('sort', '');
|
||||
if ($sort != "") {
|
||||
$this->sort = $sort;
|
||||
}
|
||||
$limit = Yii::$app->getRequest()->get('limit', '');
|
||||
if ($limit != "" && $limit <= self::MAX_LIMIT) {
|
||||
$this->limit = $limit;
|
||||
}
|
||||
$mode = Yii::$app->getRequest()->get('mode', '');
|
||||
if ($mode != "" && ($mode == self::MODE_ACTIVITY || $mode == self::MODE_NORMAL)) {
|
||||
$this->mode = $mode;
|
||||
}
|
||||
foreach (explode(',', Yii::$app->getRequest()->get('filters', "")) as $filter) {
|
||||
$this->filters[] = trim($filter);
|
||||
}
|
||||
}
|
||||
|
||||
$this->setupCriteria();
|
||||
|
66
protected/humhub/core/content/views/mails/Update.php
Normal file
66
protected/humhub/core/content/views/mails/Update.php
Normal file
@ -0,0 +1,66 @@
|
||||
<tr>
|
||||
<td align="center" valign="top" class="fix-box">
|
||||
|
||||
<!-- start container width 600px -->
|
||||
<table width="600" align="center" border="0" cellspacing="0" cellpadding="0" class="container" bgcolor="#ffffff" style="background-color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px;">
|
||||
<tr>
|
||||
<td valign="top">
|
||||
|
||||
<!-- start container width 560px -->
|
||||
<table width="560" align="center" border="0" cellspacing="0" cellpadding="0" class="full-width" bgcolor="#ffffff" style="background-color:#ffffff;">
|
||||
|
||||
<!-- start image content -->
|
||||
<tr>
|
||||
<td valign="top" width="100%">
|
||||
|
||||
<!-- start content left -->
|
||||
<table width="270" border="0" cellspacing="0" cellpadding="0" align="left" class="full-width" >
|
||||
|
||||
|
||||
<!-- start text content -->
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<table border="0" cellspacing="0" cellpadding="0" align="left" >
|
||||
<tr>
|
||||
<td style="font-size: 18px; line-height: 22px; font-family:Open Sans, Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:left;">
|
||||
<span style="color: #555555; font-weight: 300;">
|
||||
<a href="#" style="text-decoration: none; color: #555555; font-weight: 300;"><?php echo Yii::t('base', '<strong>Latest</strong> updates'); ?></a>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!--start space height -->
|
||||
<tr>
|
||||
<td height="20" ></td>
|
||||
</tr>
|
||||
<!--end space height -->
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- end text content -->
|
||||
</table>
|
||||
<!-- end content left -->
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<!-- end image content -->
|
||||
|
||||
</table>
|
||||
<!-- end container width 560px -->
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- end container width 600px -->
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- START NOTIFICATION/ACTIVITY CONTENT-->
|
||||
<?php
|
||||
if ($notifications != '') {
|
||||
echo $notifications;
|
||||
} else if ($activities != '') {
|
||||
echo $activities;
|
||||
}
|
||||
?>
|
||||
<!-- END NOTIFICATION/ACTIVITY CONTENT-->
|
@ -20,6 +20,8 @@
|
||||
|
||||
namespace humhub\core\file;
|
||||
|
||||
use humhub\core\file\models\File;
|
||||
|
||||
/**
|
||||
* FileModuleEvents handles all events described in autostart.php
|
||||
*
|
||||
@ -48,15 +50,17 @@ class Events extends \yii\base\Object
|
||||
*/
|
||||
public static function onCronDailyRun($event)
|
||||
{
|
||||
/*
|
||||
$cron = $event->sender;
|
||||
|
||||
// Delete unused files
|
||||
$deleteTime = time() - (60 * 60 * 24 * 1); // Older than 1 day
|
||||
foreach (File::model()->findAllByAttributes(array(), 'created_at < :date AND (object_model IS NULL or object_model = "")', array(':date' => date('Y-m-d', $deleteTime))) as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
*/
|
||||
$controller = $event->sender;
|
||||
$controller->stdout("Deleting old unassigned files... ");
|
||||
|
||||
// Delete unused files
|
||||
$deleteTime = time() - (60 * 60 * 24 * 1); // Older than 1 day
|
||||
foreach (File::find()->andWhere(['<', 'created_at', date('Y-m-d', $deleteTime)])->andWhere('(object_model IS NULL or object_model = "")')->all() as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
|
||||
$controller->stdout('done.' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ class InitialData
|
||||
|
||||
//Yii::$app->search->rebuild();
|
||||
|
||||
Setting::Set('baseUrl', Url::home(true));
|
||||
Setting::Set('baseUrl', \yii\helpers\BaseUrl::base(true));
|
||||
Setting::Set('paginationSize', 10);
|
||||
Setting::Set('displayNameFormat', '{profile.firstname} {profile.lastname}');
|
||||
|
||||
|
@ -96,16 +96,17 @@ class Events extends \yii\base\Object
|
||||
*/
|
||||
public static function onCronDailyRun($event)
|
||||
{
|
||||
$controller = $event->sender;
|
||||
|
||||
$cron = $event->sender;
|
||||
|
||||
$controller->stdout("Deleting old notifications... ");
|
||||
/**
|
||||
* Delete seen notifications which are older than 2 months
|
||||
*/
|
||||
$deleteTime = time() - (60 * 60 * 24 * 31 * 2); // Notifcations which are older as ~ 2 Months
|
||||
foreach (Notification::model()->findAllByAttributes(array('seen' => 1), 'created_at < :date', array(':date' => date('Y-m-d', $deleteTime))) as $notification) {
|
||||
foreach (Notification::find()->where(['seen' => 1])->andWhere(['<', 'created_at', date('Y-m-d', $deleteTime)])->all() as $notification) {
|
||||
$notification->delete();
|
||||
}
|
||||
$controller->stdout('done.' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
|
||||
}
|
||||
|
||||
public static function onActiveRecordDelete($event)
|
||||
|
@ -2,6 +2,12 @@
|
||||
|
||||
namespace humhub\core\notification;
|
||||
|
||||
use humhub\core\user\models\User;
|
||||
use humhub\core\notification\models\Notification;
|
||||
use humhub\core\notification\components\BaseNotification;
|
||||
use humhub\models\Setting;
|
||||
use humhub\commands\CronController;
|
||||
|
||||
/**
|
||||
* NotificationModule
|
||||
*
|
||||
@ -11,17 +17,45 @@ namespace humhub\core\notification;
|
||||
class Module extends \yii\base\Module
|
||||
{
|
||||
|
||||
/**
|
||||
* Formatted the notification content before delivery
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public static function formatOutput($text)
|
||||
public function getMailUpdate(User $user, $interval)
|
||||
{
|
||||
//$text = HHtml::translateMentioning($text, false);
|
||||
//$text = HHtml::translateEmojis($text, false);
|
||||
$output = "";
|
||||
|
||||
return $text;
|
||||
$receive_email_notifications = $user->getSetting("receive_email_notifications", 'core', Setting::Get('receive_email_notifications', 'mailing'));
|
||||
|
||||
// Never receive notifications
|
||||
if ($receive_email_notifications == User::RECEIVE_EMAIL_NEVER) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// We are in hourly mode and user wants daily
|
||||
if ($interval == CronController::EVENT_ON_HOURLY_RUN && $receive_email_notifications == User::RECEIVE_EMAIL_DAILY_SUMMARY) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// We are in daily mode and user dont wants daily reports
|
||||
if ($interval == CronController::EVENT_ON_DAILY_RUN && $receive_email_notifications != User::RECEIVE_EMAIL_DAILY_SUMMARY) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// User wants only when offline and is online
|
||||
if ($interval == CronController::EVENT_ON_HOURLY_RUN) {
|
||||
$isOnline = (count($user->httpSessions) > 0);
|
||||
if ($receive_email_notifications == User::RECEIVE_EMAIL_WHEN_OFFLINE && $isOnline) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
$query = Notification::find()->where(['user_id' => $user->id])->andWhere(["!=", 'seen', 1]);
|
||||
|
||||
foreach ($query->all() as $notification) {
|
||||
$output .= $notification->getClass()->render(BaseNotification::OUTPUT_MAIL);
|
||||
|
||||
$notification->emailed = 1;
|
||||
$notification->save();
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class BaseNotification extends \yii\base\Component implements ViewContextInterfa
|
||||
|
||||
$params['content'] = Yii::$app->getView()->renderFile($viewFile, $params, $this);
|
||||
|
||||
return Yii::$app->getView()->renderFile($this->layoutWeb, $params, $this);
|
||||
return Yii::$app->getView()->renderFile(($mode == self::OUTPUT_WEB) ? $this->layoutWeb : $this->layoutMail, $params, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,8 @@
|
||||
<!-- START NOTIFICATION/ACTIVITY -->
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
?>
|
||||
<!-- START NOTIFICATION -->
|
||||
<tr>
|
||||
<td align="center" valign="top" class="fix-box">
|
||||
|
||||
@ -34,13 +38,12 @@
|
||||
<tr>
|
||||
|
||||
<td valign="top" align="left" style="padding-right:20px;">
|
||||
|
||||
<!-- check if variable exists and is true -->
|
||||
<?php if ($notification->getCreator() !== null && empty($hideUserImage)): ?>
|
||||
|
||||
<?php if ($originator !== null): ?>
|
||||
<!-- START: USER IMAGE -->
|
||||
<a href="<?php echo Yii::app()->createAbsoluteUrl('user/profile', array('guid' => $notification->getCreator()->guid)); ?>">
|
||||
<a href="<?php echo $originator->createUrl('/user/profile', [], true); ?>">
|
||||
<img
|
||||
src="<?php echo $notification->getCreator()->getProfileImage()->getUrl(); ?>"
|
||||
src="<?php echo $originator->getProfileImage()->getUrl(); ?>"
|
||||
width="50"
|
||||
alt=""
|
||||
style="max-width:50px; display:block !important; border-radius: 4px;"
|
||||
@ -48,7 +51,7 @@
|
||||
</a>
|
||||
<!-- END: USER IMAGE -->
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
@ -62,29 +65,19 @@
|
||||
|
||||
<?php echo $content; ?>
|
||||
|
||||
<!-- check if variable exists and is true -->
|
||||
<?php if (!empty($showSpace)) : ?>
|
||||
|
||||
<!-- check if variable is true -->
|
||||
<?php if ($showSpace == true) : ?>
|
||||
|
||||
<!-- check if activity object has a space -->
|
||||
<?php if ($notification->space != null): ?>
|
||||
(<?php echo Yii::t('NotificationModule.views_notificationLayoutMail', 'via'); ?>
|
||||
<a href="<?php echo Yii::app()->createUrl('space/space', array('sguid' => $notification->space->guid)); ?>"
|
||||
style="text-decoration: none; color: #555555;">
|
||||
<?php echo CHtml::encode($notification->space->name); ?>
|
||||
</a>)
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- check if activity object has a space -->
|
||||
<?php if ($space !== null): ?>
|
||||
(<?php echo Yii::t('NotificationModule.views_notificationLayoutMail', 'via'); ?>
|
||||
<a href="<?php echo $space->createUrl('/space/space', [], true); ?>"
|
||||
style="text-decoration: none; color: #555555;">
|
||||
<?php echo Html::encode($space->name); ?>
|
||||
</a>)
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- START: CONTENT LINK -->
|
||||
<span
|
||||
style="text-decoration: none; color: #7191a8;"> - <a
|
||||
href="<?php echo $notification->getUrl(); ?>"
|
||||
href="<?php echo $url; ?>"
|
||||
style="text-decoration: none; color: #7191a8; "><?php echo Yii::t('NotificationModule.views_notificationLayoutMail', 'see online'); ?></a></span>
|
||||
<!-- END: CONTENT LINK -->
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
namespace humhub\core\search;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* Description of SearchModuleEvents
|
||||
*
|
||||
@ -30,6 +32,14 @@ class Events extends \yii\base\Object
|
||||
}
|
||||
}
|
||||
|
||||
public static function onHourlyCron($event)
|
||||
{
|
||||
$controller = $event->sender;
|
||||
$controller->stdout("Optimizing search index... ");
|
||||
Yii::$app->search->optimize();
|
||||
$controller->stdout('done.' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
|
||||
}
|
||||
|
||||
public static function onConsoleApplicationInit($event)
|
||||
{
|
||||
|
||||
|
@ -3,15 +3,17 @@
|
||||
use humhub\widgets\TopMenuRightStack;
|
||||
use humhub\core\search\Events;
|
||||
use humhub\components\console\Application;
|
||||
use humhub\commands\CronController;
|
||||
|
||||
Yii::$app->moduleManager->register(array(
|
||||
'isCoreModule' => true,
|
||||
'id' => 'search',
|
||||
'class' => \humhub\core\search\Module::className(),
|
||||
'events' => array(
|
||||
array('class' => TopMenuRightStack::className(), 'event' => TopMenuRightStack::EVENT_INIT, 'callback' => array(Events::className(), 'onTopMenuRightInit')),
|
||||
array('class' => Application::className(), 'event' => Application::EVENT_ON_INIT, 'callback' => array(Events::className(), 'onConsoleApplicationInit')),
|
||||
//array('class' => 'Comment', 'event' => 'onAfterSave', 'callback' => array('SearchModuleEvents', 'onAfterSaveComment')),
|
||||
['class' => TopMenuRightStack::className(), 'event' => TopMenuRightStack::EVENT_INIT, 'callback' => array(Events::className(), 'onTopMenuRightInit')],
|
||||
['class' => Application::className(), 'event' => Application::EVENT_ON_INIT, 'callback' => array(Events::className(), 'onConsoleApplicationInit')],
|
||||
['class' => CronController::className(), 'event' => CronController::EVENT_ON_HOURLY_RUN, 'callback' => [Events::className(), 'onHourlyCron']],
|
||||
//array('class' => 'Comment', 'event' => 'onAfterSave', 'callback' => array('SearchModuleEvents', 'onAfterSaveComment')),
|
||||
),
|
||||
));
|
||||
?>
|
21
protected/humhub/core/user/components/Session.php
Normal file
21
protected/humhub/core/user/components/Session.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\core\user\components;
|
||||
|
||||
use yii\web\DbSession;
|
||||
|
||||
/**
|
||||
* Description of Session
|
||||
*
|
||||
* @author luke
|
||||
*/
|
||||
class Session extends DbSession
|
||||
{
|
||||
//put your code here
|
||||
}
|
31
protected/humhub/core/user/models/Session.php
Normal file
31
protected/humhub/core/user/models/Session.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\core\user\models;
|
||||
|
||||
use humhub\components\ActiveRecord;
|
||||
|
||||
/**
|
||||
* This is the model class for table "user_http_session".
|
||||
*
|
||||
* The followings are the available columns in table 'user_http_session':
|
||||
* @property string $id
|
||||
* @property integer $expire
|
||||
* @property integer $user_id
|
||||
* @property string $data
|
||||
*
|
||||
* @package humhub.modules_core.user.models
|
||||
* @since 0.5
|
||||
* @author Luke
|
||||
*/
|
||||
class Session extends ActiveRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string the associated database table name
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'user_http_session';
|
||||
}
|
||||
|
||||
}
|
@ -95,14 +95,13 @@ class User extends \humhub\core\content\components\activerecords\ContentContaine
|
||||
* not really exists yet.
|
||||
*/
|
||||
if ($name == 'profile') {
|
||||
if (!$this->isRelationPopulated('profile')) {
|
||||
$profile = $this->getProfile()->findFor('profile', $this);
|
||||
if ($profile === null) {
|
||||
$profile = new Profile();
|
||||
$profile->user_id = $this->id;
|
||||
}
|
||||
$profile = parent::__get('profile');
|
||||
if (!$this->isRelationPopulated('profile') || $profile === null) {
|
||||
$profile = new Profile();
|
||||
$profile->user_id = $this->id;
|
||||
$this->populateRelation('profile', $profile);
|
||||
}
|
||||
return $profile;
|
||||
}
|
||||
return parent::__get($name);
|
||||
}
|
||||
@ -567,6 +566,14 @@ class User extends \humhub\core\content\components\activerecords\ContentContaine
|
||||
->viaTable('space_membership', ['user_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return type
|
||||
*/
|
||||
public function getHttpSessions()
|
||||
{
|
||||
return $this->hasMany(\humhub\core\user\models\Session::className(), ['user_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the user can create a space
|
||||
*
|
||||
|
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is the model class for table "user_http_session".
|
||||
*
|
||||
* The followings are the available columns in table 'user_http_session':
|
||||
* @property string $id
|
||||
* @property integer $expire
|
||||
* @property integer $user_id
|
||||
* @property string $data
|
||||
*
|
||||
* @package humhub.modules_core.user.models
|
||||
* @since 0.5
|
||||
* @author Luke
|
||||
*/
|
||||
class UserHttpSession extends CActiveRecord {
|
||||
|
||||
/**
|
||||
* Returns the static model of the specified AR class.
|
||||
* @param string $className active record class name.
|
||||
* @return UserHttpSession the static model class
|
||||
*/
|
||||
public static function model($className = __CLASS__) {
|
||||
return parent::model($className);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the associated database table name
|
||||
*/
|
||||
public function tableName() {
|
||||
return 'user_http_session';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array validation rules for model attributes.
|
||||
*/
|
||||
public function rules() {
|
||||
// NOTE: you should only define rules for those attributes that
|
||||
// will receive user inputs.
|
||||
return array(
|
||||
array('id', 'required'),
|
||||
array('expire, user_id', 'numerical', 'integerOnly' => true),
|
||||
array('id', 'length', 'max' => 255),
|
||||
array('data', 'safe'),
|
||||
// The following rule is used by search().
|
||||
// Please remove those attributes that should not be searched.
|
||||
array('id, expire, user_id, data', 'safe', 'on' => 'search'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array relational rules.
|
||||
*/
|
||||
public function relations() {
|
||||
// NOTE: you may need to adjust the relation name and the related
|
||||
// class name for the relations automatically generated below.
|
||||
return array(
|
||||
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array customized attribute labels (name=>label)
|
||||
*/
|
||||
public function attributeLabels() {
|
||||
return array(
|
||||
'id' => 'ID',
|
||||
'expire' => 'Expire',
|
||||
'user_id' => 'User',
|
||||
'data' => 'Data',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of models based on the current search/filter conditions.
|
||||
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
|
||||
*/
|
||||
public function search() {
|
||||
// Warning: Please modify the following code to remove attributes that
|
||||
// should not be searched.
|
||||
|
||||
$criteria = new CDbCriteria;
|
||||
|
||||
$criteria->compare('id', $this->id, true);
|
||||
$criteria->compare('expire', $this->expire);
|
||||
$criteria->compare('user_id', $this->user_id);
|
||||
$criteria->compare('data', $this->data, true);
|
||||
|
||||
return new CActiveDataProvider($this, array(
|
||||
'criteria' => $criteria,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
@ -13,11 +13,12 @@ Quick Guide about
|
||||
- Modules
|
||||
- Change autostart.php -> avoid old loading probs?
|
||||
- Uninstall
|
||||
- Namespaces
|
||||
- Theming
|
||||
- Also check themed files like module_images
|
||||
- Check Update Progress
|
||||
- Themed Image files User/Space Default Profile Image
|
||||
- Notification/Activity Mail Views
|
||||
- Emailing (New Config Option)
|
||||
- CronJobs
|
||||
- Integritychecker
|
||||
- Tests
|
||||
- RichText
|
||||
- Max Length & minimal Option
|
||||
|
@ -3,9 +3,6 @@ Notifications
|
||||
|
||||
Notifications are used to inform one or a given set of users about something.
|
||||
|
||||
|
||||
## Steps to create Notifications
|
||||
|
||||
### Create
|
||||
|
||||
Create a folder ** notifications ** in your module and a new class ** SomethingHappend **
|
||||
@ -22,11 +19,8 @@ use humhub\core\notification\components\BaseNotification;
|
||||
*/
|
||||
class SomethingHappend extends BaseNotification
|
||||
{
|
||||
|
||||
public $viewName = "somethingHappend";
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
```
|
||||
|
@ -96,7 +96,7 @@ class ProfileImage
|
||||
$path .= 'img/' . $this->defaultImage;
|
||||
$path .= '.jpg';
|
||||
}
|
||||
return Url::to($path, Yii::$app->request->isConsoleRequest);
|
||||
return Yii::getAlias($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,10 +25,6 @@ $config = yii\helpers\ArrayHelper::merge(
|
||||
|
||||
);
|
||||
|
||||
Yii::setAlias('@app', __DIR__);
|
||||
Yii::setAlias('@webroot', __DIR__ . DIRECTORY_SEPARATOR . '..');
|
||||
Yii::setAlias('@humhub', '@app/humhub');
|
||||
|
||||
$application = new humhub\components\console\Application($config);
|
||||
$exitCode = $application->run();
|
||||
exit($exitCode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user