Skip to content

Commit

Permalink
update sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Nov 24, 2022
1 parent b7c4a99 commit 65c13e8
Showing 1 changed file with 49 additions and 9 deletions.
58 changes: 49 additions & 9 deletions src/DbSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
namespace skeeks\cms\mysqlSession;


use yii\base\Exception;
use yii\helpers\Json;
use yii\helpers\VarDumper;
/**
* @author Semenov Alexander <semenov@skeeks.com>
*/
Expand All @@ -31,19 +34,55 @@ class DbSession extends \yii\web\DbSession
public function init()
{
$this->writeCallback = function ($session) {

/*$string = '';
try {
throw new Exception("1");
} catch (\Exception $e) {
$string = VarDumper::dumpAsString($e);
}*/

return [
'cms_user_id' => \Yii::$app->user->id,
'cms_site_id' => \Yii::$app->skeeks->site ? \Yii::$app->skeeks->site->id : null,
'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null,
'https_user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null,
'updated_at' => time(),
//'url' => \Yii::$app->request->absoluteUrl,
/*'controller' => \Yii::$app->controller ? \Yii::$app->controller->uniqueId : '',
'ref' => \Yii::$app->request->referrer ? \Yii::$app->request->referrer : "",
'url' => \Yii::$app->request->absoluteUrl,
'server' => Json::encode($_SERVER),
'cookie' => Json::encode($_COOKIE),*/
//'stack' => $string,
];
};

parent::init();
}

/*public function openSession($savePath, $sessionName)
{
//Если бот то не записываем сессию
/*if ($this->isBot()) {
return true;
}
if ($this->_isNoStartSessionByRequest()) {
return true;
}*/

/*if (YII_ENV_DEV) {
print_r(\Yii::$app->controller->uniqueId);die;
throw new Exception("111");
var_dump($this->getUseStrictMode());
die;
return parent::openSession($savePath, $sessionName);
}*/


/**
* @param string $id
Expand Down Expand Up @@ -73,17 +112,18 @@ public function writeSession($id, $data)
* На этих действиях не нужно сохранять сессию
* @return bool
*/
protected function _isNoStartSessionByRequest() {
protected function _isNoStartSessionByRequest()
{
if (\Yii::$app->controller && in_array(\Yii::$app->controller->uniqueId, [
'seo/robots',
'cms/favicon',
'cms/online',
'cms/image-preview',
])) {
'seo/robots',
'cms/favicon',
'cms/online',
'cms/image-preview',

])) {
return true;
}

return false;
}

Expand Down

0 comments on commit 65c13e8

Please sign in to comment.