Minor refactoring of Stream action class.

This commit is contained in:
buddh4 2020-10-10 16:06:59 +02:00
parent d05aaa4e70
commit 4c04c82e13
2 changed files with 47 additions and 31 deletions

View File

@ -8,6 +8,7 @@ use humhub\modules\content\components\ContentActiveRecord;
use humhub\modules\content\models\Content;
use humhub\modules\content\widgets\stream\StreamEntryWidget;
use humhub\modules\content\widgets\stream\WallStreamEntryWidget;
use humhub\modules\user\models\User;
use Yii;
use yii\base\Exception;
use yii\db\ActiveQuery;
@ -33,6 +34,31 @@ trait LegacyStreamTrait
*/
public $activeQuery;
/**
* Optional stream user
* if no user is specified, the current logged in user will be used.
*
* @var User
* @deprecated since 1.7 use StreamQuery->user
*/
public $user;
/**
* First wall entry id to deliver
*
* @var int
* @deprecated since 1.7 use $streamQuery->from
*/
public $from;
/**
* Entry id of the top stream entry used for update requests
*
* @var int
* @deprecated since 1.7 use $streamQuery->to
*/
public $to;
/**
* Returns an array contains all information required to display a content
* in stream.

View File

@ -12,14 +12,11 @@ use humhub\modules\stream\events\StreamResponseEvent;
use Yii;
use yii\base\Action;
use yii\base\Exception;
use yii\base\ActionEvent;
use humhub\modules\content\widgets\stream\StreamEntryWidget;
use humhub\modules\content\widgets\stream\StreamEntryOptions;
use humhub\modules\stream\models\StreamQuery;
use humhub\modules\stream\models\WallStreamQuery;
use humhub\modules\content\models\Content;
use humhub\modules\user\models\User;
/**
* Stream is the basic action for content streams.
@ -44,20 +41,22 @@ abstract class Stream extends Action
use LegacyStreamTrait;
/**
* @event ActionEvent Event triggered before stream filter handlers are applied
* @event Event triggered before stream filter handlers are applied
* This can be used for adding filters.
* @since 1.7
*/
const EVENT_BEFORE_APPLY_FILTERS = 'beforeApplyFilters';
/**
* @event ActionEvent Event triggered after stream filter handlers are applied
* @event Event triggered after stream filter handlers are applied
* This can be used for last modifications to the query.
* @since 1.7
*/
const EVENT_AFTER_APPLY_FILTERS = 'afterApplyFilters';
/**
* @event Event triggered after query fetch, can be used to manipulate the
* stream response. E.g. inject additional entries.
* @since 1.7
*/
const EVENT_AFTER_FETCH = 'afterQueryFetch';
@ -92,6 +91,7 @@ abstract class Stream extends Action
/**
* Maximum wall entries per request
* @deprecated since 1.7 not in use
*/
const MAX_LIMIT = 50;
@ -101,22 +101,6 @@ abstract class Stream extends Action
*/
public $contentId;
/**
* First wall entry id to deliver
*
* @var int
* @deprecated since 1.7 use $streamQuery->from
*/
public $from;
/**
* Entry id of the top stream entry used for update requests
*
* @var int
* @deprecated since 1.7 use $streamQuery->to
*/
public $to;
/**
* Sorting Mode
*
@ -138,20 +122,12 @@ abstract class Stream extends Action
public $filters = [];
/**
* Can be used to append or overwrite filter handlers without the need of overwriting the stream class.
* Can be used to append or overwrite filter handlers without the need of overwriting the StreamQuery class.
* @var array
* @since 1.7
*/
public $filterHandlers = [];
/**
* Optional stream user
* if no user is specified, the current logged in user will be used.
*
* @var User
*/
public $user;
/**
* Used to filter the stream content entry classes against a given array.
* @var array
@ -171,7 +147,7 @@ abstract class Stream extends Action
* @var StreamQuery
* @since 1.2
*/
public $streamQuery;
protected $streamQuery;
/**
* @var string suppress similar content types in a row
@ -190,6 +166,7 @@ abstract class Stream extends Action
/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
@ -199,6 +176,9 @@ abstract class Stream extends Action
$this->streamQuery = $this->initQuery();
// Just make sure legacy user property is available
$this->user = $this->streamQuery->user;
if (!Yii::$app->request->isConsoleRequest) {
$this->streamQuery->load(Yii::$app->request->get());
}
@ -234,8 +214,10 @@ abstract class Stream extends Action
protected function initQuery($options = [])
{
$streamQueryClass = $this->streamQueryClass;
/* @var $instance StreamQuery */
$instance = $streamQueryClass::find();
$instance->forUser(Yii::$app->user->identity);
$instance->setAttributes($options, false);
return $instance;
}
@ -359,4 +341,12 @@ abstract class Stream extends Action
return null;
}
/**
* @return StreamQuery
*/
public function getStreamQuery()
{
return $this->streamQuery;
}
}