From 9cbb9ba038288c20e790d8a17a8e73cd3f6a227e Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Wed, 23 Aug 2017 13:49:19 +0200 Subject: [PATCH] Dev: Re-fix issue #09828 : adding subquestion multiple times update max_subquestions Dev: Adding attribute only if not exist Dev: related https://github.com/LimeSurvey/LimeSurvey/commit/d09e6d4423cdfd1d216231dd9ac1396fcd621f68#diff-4c8b6e0396ccd2f7fad4f57489b63b06L156 and https://github.com/LimeSurvey/LimeSurvey/pull/507 --- application/controllers/admin/database.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/application/controllers/admin/database.php b/application/controllers/admin/database.php index b60b7599ed8..0e17af43487 100644 --- a/application/controllers/admin/database.php +++ b/application/controllers/admin/database.php @@ -152,17 +152,18 @@ function index($sa = null) /* @todo : add it to upgrage DB system, and see for the lsa */ if($sQuestionType=="R" && Survey::model()->findByPk($iSurveyID)->active=="Y") { - QuestionAttribute::model()->find( + $oQuestionAttributeMaxSubQuestions = QuestionAttribute::model()->find( "qid = :qid AND attribute = 'max_subquestions'", array(':qid' => $iQuestionID) ); - - $answerCount=Answer::model()->countByAttributes(array('qid' => $iQuestionID,'language'=>Survey::model()->findByPk($iSurveyID)->language)); - $oQuestionAttribute = new QuestionAttribute(); - $oQuestionAttribute->qid = $iQuestionID; - $oQuestionAttribute->attribute = 'max_subquestions'; - $oQuestionAttribute->value = $answerCount; - $oQuestionAttribute->save(); + if(!$oQuestionAttributeMaxSubQuestions) { + $answerCount=Answer::model()->countByAttributes(array('qid' => $iQuestionID,'language'=>Survey::model()->findByPk($iSurveyID)->language)); + $oQuestionAttributeMaxSubQuestions = new QuestionAttribute(); + $oQuestionAttributeMaxSubQuestions->qid = $iQuestionID; + $oQuestionAttributeMaxSubQuestions->attribute = 'max_subquestions'; + $oQuestionAttributeMaxSubQuestions->value = $answerCount; + $oQuestionAttributeMaxSubQuestions->save(); + } }