Commit 9ea74447 authored by Chenu Denis's avatar Chenu Denis

[dev] Move logic of keep previousSessionId to model

[dev] This fix issue with 409 by self
parent 8a8bda30
......@@ -23,6 +23,8 @@ class surveySession extends CActiveRecord
/* @const integer The max time for session, if it's not set in session or by server (0 in session_time_limit) */
const maxSessionTime = 30;
/* @const integer The max session id number to keep */
const KeepSessionNumber = 40;
/** @inheritdoc */
public static function model($className=__CLASS__) {
......@@ -101,6 +103,7 @@ class surveySession extends CActiveRecord
}
$oSessionSurvey->lastaction = date('Y-m-d H:i:s');
$oSessionSurvey->session = Yii::app()->getSession()->getSessionID();
self::addCurrrentSessionInPrevious(Yii::app()->getSession()->getSessionID());
$oSessionSurvey->save();
return $oSessionSurvey;
}
......@@ -136,6 +139,7 @@ class surveySession extends CActiveRecord
/* Same session : save time and quit */
if($oSessionSurvey->session == Yii::app()->getSession()->getSessionID()) {
$oSessionSurvey->lastaction = date('Y-m-d H:i:s');
self::addCurrrentSessionInPrevious(Yii::app()->getSession()->getSessionID());
$oSessionSurvey->save();
return null;
}
......@@ -161,4 +165,28 @@ class surveySession extends CActiveRecord
$sessionTimeLimit = intval(Yii::app()->getConfig('surveysessiontime_limit',self::maxSessionTime));
return $sessionTimeLimit;
}
/**
* try to keep previous session in session …
* @param string $sessionId, ifb not set : current one
* @return void
*/
public static function addCurrrentSessionInPrevious($sessionId=null)
{
$previousSessionIds = Yii::app()->session['previousSessionId'];
if(empty($previousSessionIds)) {
$previousSessionIds = array();
}
if(empty($sessionId)) {
$sessionId = Yii::app()->getSession()->getSessionID();
}
if(!in_array($sessionId,$previousSessionIds)) {
$previousSessionIds[] = $sessionId;
}
$previousSessionIds = array_unique($previousSessionIds);
if(count($previousSessionIds) > self::KeepSessionNumber ) {
array_shift($previousSessionIds);
}
Yii::app()->session['previousSessionId'] = $previousSessionIds;
}
}
......@@ -26,7 +26,6 @@ class reloadAnyResponse extends PluginBase {
static protected $dbVersion = 1;
const KeepSessionNumber = 40;
/**
* @var array[] the settings
*/
......@@ -161,7 +160,6 @@ class reloadAnyResponse extends PluginBase {
/* Get the survey by srid and code */
/* Save current session */
$this->subscribe('beforeSurveyPage');
$this->subscribe('getPluginTwigPath');
/* Replace existing system if srid = new */
$this->subscribe('beforeLoadResponse');
/* Survey settings */
......@@ -405,16 +403,7 @@ class reloadAnyResponse extends PluginBase {
/* Save current session Id to allow same user to reload survey in same browser */
/* resetAllSessionVariables regenerate session id */
/* Keep previous session id, if user reload start url it reset the sessionId, need to leav access */
$previousSessionId = Yii::app()->session['previousSessionId'];
if(empty($previousSessionId)) {
$previousSessionId = array();
}
$previousSessionId[] = Yii::app()->getSession()->getSessionID();
$previousSessionId = array_unique($previousSessionId);
if(count($previousSessionId) > self::KeepSessionNumber ) {
array_shift($previousSessionId);
}
Yii::app()->session['previousSessionId'] = $previousSessionId;
$surveyid = $this->getEvent()->get('surveyId');
$multiAccessTime = $this->_getCurrentSetting('multiAccessTime',$surveyid);
if($multiAccessTime !== '') {
......@@ -490,26 +479,6 @@ class reloadAnyResponse extends PluginBase {
$this->_addUnloadScript($surveyid,$srid);
}
/** @inheritdoc
* Need to update current previousSessionId after all other action done
**/
public function getPluginTwigPath()
{
$surveyid = Yii::app()->getRequest()->getParam('sid',Yii::app()->getRequest()->getParam('surveyid'));
if(empty($surveyid)) {
return;
}
$previousSessionId = Yii::app()->session['previousSessionId'];
if(empty($previousSessionId)) {
$previousSessionId = array();
}
$previousSessionId[] = Yii::app()->getSession()->getSessionID();
$previousSessionId = array_unique($previousSessionId);
if(count($previousSessionId) > self::KeepSessionNumber ) {
array_shift($previousSessionId);
}
Yii::app()->session['previousSessionId'] = $previousSessionId;
}
/**
* Delete SurveySession for this event srid
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment