Skip to content

Commit

Permalink
Fixed issue #07995: Memory issue in Survey Activation
Browse files Browse the repository at this point in the history
Dev: fixnumbering need to be review
Dev: All SQL need reviewing (put this for 2.05)
  • Loading branch information
Shnoulle committed Jul 11, 2013
1 parent 99edb2c commit 8da619a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 8 additions & 6 deletions application/helpers/admin/activate_helper.php
Expand Up @@ -15,7 +15,9 @@

/**
* fixes the numbering of questions
* @param <type> $fixnumbering
* This can happen if question 1 have subquestion code 1 and have question 11 in same survey and group (then same SGQA)
* @param int $fixnumbering
* @todo can call this function (no $_GET, but getParam) AND do it with Yii
*/
function fixNumbering($fixnumbering, $iSurveyID)
{
Expand All @@ -24,11 +26,10 @@ function fixNumbering($fixnumbering, $iSurveyID)

LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
//Fix a question id - requires renumbering a question
$oldqid = $fixnumbering;
$query = "SELECT qid FROM {{questions}} ORDER BY qid DESC";
$result = dbSelectLimitAssoc($query, 1);
foreach ($result->readAll() as $row) {$lastqid=$row['qid'];}
$oldqid = (int) $fixnumbering;
$lastqid=Questions::model()->getMaxId();
$newqid=$lastqid+1;

$query = "UPDATE {{questions}} SET qid=$newqid WHERE qid=$oldqid";
$result = db_execute_assosc($query);
// Update subquestions
Expand Down Expand Up @@ -182,7 +183,8 @@ function checkQuestions($postsid, $iSurveyID, $qtypes)
$conquery= "SELECT {{conditions}}.qid, cqid, {{questions}}.question, "
. "{{questions}}.gid "
. "FROM {{conditions}}, {{questions}}, {{groups}} "
. "WHERE {{conditions}}.qid={{questions}}.qid "
. "WHERE {{questions}}.sid={$iSurveyID} "
. "AND {{conditions}}.qid={{questions}}.qid "
. "AND {{questions}}.gid={{groups}}.gid ORDER BY {{conditions}}.qid";
$conresult=Yii::app()->db->createCommand($conquery)->query()->readAll();
//2: Check each conditions cqid that it occurs later than the cqid
Expand Down
18 changes: 17 additions & 1 deletion application/models/Questions.php
Expand Up @@ -54,7 +54,23 @@ public function primaryKey()
{
return 'qid';
}

/**
* Return the max id (primary key)
*
* Actually used in activate_helper fixNumbering function
* Don't use static because can be call after adding a question
*
* @since 130711
* @return false|int
*/
public function getMaxId()
{
$maxId = $this->dbConnection->createCommand()
->select('MAX(' . $this->primaryKey() . ')')
->from($this->tableName())
->queryScalar();
return $maxId;
}
/**
* Defines the relations for this model
*
Expand Down

0 comments on commit 8da619a

Please sign in to comment.