Skip to content

Commit

Permalink
Fixed #6876: Error when taking survey with datestamps on answers enabled
Browse files Browse the repository at this point in the history
dev: values changed on activation were not picked up
  • Loading branch information
mennodekker committed Nov 16, 2012
1 parent 69e7295 commit efc71f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions application/controllers/admin/surveyadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ public function activate($iSurveyID)
$survey->refurl = Yii::app()->request->getPost('refurl');
$survey->savetimings = Yii::app()->request->getPost('savetimings');
$survey->save();
Survey::model()->resetCache(); // Make sure the saved values will be picked up
}

$aResult=activateSurvey($iSurveyID);
Expand Down
3 changes: 2 additions & 1 deletion application/core/LSYii_Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public function setLang(Limesurvey_lang $lang)
*/
function traceVar($variable, $depth = 10) {
$msg = CVarDumper::dumpAsString($variable, $depth, false);
$trace=array_shift(debug_backtrace());
$fullTrace = debug_backtrace();
$trace=array_shift($fullTrace);
if(isset($trace['file'],$trace['line']) && strpos($trace['file'],YII_PATH)!==0)
{
$msg = $trace['file'].' ('.$trace['line']."):\n" . $msg;
Expand Down
23 changes: 19 additions & 4 deletions application/models/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@

class Survey extends CActiveRecord
{
/**
* This is a static cache, it lasts only during the active request. If you ever need
* to clear it, like on activation of a survey when in the same request a row is read,
* saved and read again you can use resetCache() method.
*
* @var array
*/
protected $findByPkCache = array();

/**
* Returns the table's name
*
Expand Down Expand Up @@ -355,14 +364,13 @@ public function deleteSurvey($iSurveyID, $recursive=true)
}

public function findByPk($pk, $condition = '', $params = array()) {
static $lastResult = array();
if (empty($condition) && empty($params)) {
if (array_key_exists($pk, $lastResult)) {
return $lastResult[$pk];
if (array_key_exists($pk, $this->findByPkCache)) {
return $this->findByPkCache[$pk];
} else {
$result = parent::findByPk($pk, $condition, $params);
if (!is_null($result)) {
$lastResult[$pk] = $result;
$this->findByPkCache[$pk] = $result;
}

return $result;
Expand All @@ -371,4 +379,11 @@ public function findByPk($pk, $condition = '', $params = array()) {

return parent::findByPk($pk, $condition, $params);
}

/**
* findByPk uses a cache to store a result. Use this method to force clearing that cache.
*/
public function resetCache() {
$this->findByPkCache = array();
}
}

0 comments on commit efc71f4

Please sign in to comment.