Skip to content

Commit

Permalink
fix robots filter session problem #1914
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Aug 27, 2019
1 parent e07f7aa commit 3da7a89
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

All notable changes to this project will be documented in this file. This project make usage of the [Yii Versioning Strategy](https://github.com/yiisoft/yii2/blob/master/docs/internals/versions.md). In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).

## 1.0.13 (in progress)
## 1.0.17 (in progress)

+ [#1914](https://github.com/luyadev/luya/issues/1914) Fixed problem with `RobotsFilter` when used in multiple forms on the same CMS page.
+ [#1912](https://github.com/luyadev/luya/issues/1912) Added `ObjectHelper::isTraitInstanceOf` method to check whether an object contains a certain trait or not.

## 1.0.16 (1. April 2019)
Expand Down
38 changes: 36 additions & 2 deletions core/web/filters/RobotsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use yii\base\ActionFilter;
use yii\base\InvalidCallException;
use yii\helpers\VarDumper;
use yii\base\Controller;
use luya\helpers\ArrayHelper;

/**
Expand Down Expand Up @@ -49,14 +50,26 @@ class RobotsFilter extends ActionFilter
*/
public $delay = 2.5;

/**
* @var string|null A string which identifiers the current robots filter in case you have multiple controllers on the same page with robot filters enabled.
* @since 1.0.17
*/
public $sessionKey;

const ROBOTS_FILTER_SESSION_IDENTIFIER = '__robotsFilterRenderTime';

/**
* @return integer Returns the latest render timestamp.
*/
protected function getRenderTime()
{
return Yii::$app->session->get(self::ROBOTS_FILTER_SESSION_IDENTIFIER, time());
$value = Yii::$app->session->get(self::ROBOTS_FILTER_SESSION_IDENTIFIER, time());

if (isset($value[$this->getSessionKeyByOwner()])) {
return $value[$this->getSessionKeyByOwner];
}

return $value;
}

/**
Expand All @@ -66,7 +79,28 @@ protected function getRenderTime()
*/
protected function setRenderTime($time)
{
Yii::$app->session->set(self::ROBOTS_FILTER_SESSION_IDENTIFIER, $time);
Yii::$app->session->set(self::ROBOTS_FILTER_SESSION_IDENTIFIER, [$this->getSessionKeyByOwner() => $time]);
}

/**
* Get a specific key for the current robots filter session array.
*
* This ensures that when multiple forms are on the same page, only the robot check is handeld for the given module name.
*
* @return string
* @since 1.0.17
*/
protected function getSessionKeyByOwner()
{
if ($this->sessionKey) {
return $this->sessionKey;
}

if ($this->owner instanceof Controller) {
return $this->owner->module->id;
}

return 'generic';
}

/**
Expand Down

0 comments on commit 3da7a89

Please sign in to comment.