Skip to content

Commit

Permalink
DEV: remove the model->insertRecords() methods 3 (#978)
Browse files Browse the repository at this point in the history
* DEV: remove/deprecate insertRecords() - assessments

* DEV: remove/deprecate insertRecords() - Answer & Quota

* DEV: remove/deprecate insertRecords() - QuestionAttribute & LabelSets

* DEV: remove/deprecate insertRecords() - ExpressionErrors Permission QuotaMember

* DEV: remove/deprecate insertRecords() - DefaultValue

* Revert "DEV: remove/deprecate insertRecords() - DefaultValue"

This reverts commit 9e69b80.

* DEV: remove/deprecate insertRecords() - QuestionGroup

* Revert "DEV: remove/deprecate insertRecords() - QuestionGroup"

This reverts commit cbb4fe8.

* DEV: remove the model->insertRecords() methods - QuestionGroup

* DEV: remove the model->insertRecords() methods - DefaultValue

* Revert "DEV: remove the model->insertRecords() methods - DefaultValue"

This reverts commit 47a4bda.
  • Loading branch information
TonisOrmisson committed Feb 3, 2018
1 parent 89b954f commit 9cf61a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
25 changes: 21 additions & 4 deletions application/helpers/admin/import_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ function XMLImportGroup($sFullFilePath, $iNewSID)
unset($insertdata['language']);
}
if (!isset($aGIDReplacements[$oldgid])) {
$newgid = QuestionGroup::model()->insertRecords($insertdata) or safeDie(gT("Error").": Failed to insert data [3]<br />");
$questionGroup = new QuestionGroup();
$questionGroup->attributes = $insertdata;
if(!$questionGroup->save()){
safeDie(gT("Error").": Failed to insert data [3]<br />");
}

$newgid = $questionGroup->gid;

$aGIDReplacements[$oldgid] = $newgid; // add old and new qid to the mapping array
$results['groups']++;
}
Expand Down Expand Up @@ -1332,7 +1339,14 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
unset($insertdata['language']);
}
if (!isset($aGIDReplacements[$oldgid])) {
$newgid = QuestionGroup::model()->insertRecords($insertdata) or safeDie(gT("Error").": Failed to insert data [3]<br />");
$questionGroup = new QuestionGroup();
$questionGroup->attributes = $insertdata;
$questionGroup->sid = $iNewSID;
if(!$questionGroup->save()){
safeDie(gT("Error").": Failed to insert data [3]<br />");
}

$newgid = $questionGroup->gid;
$aGIDReplacements[$oldgid] = $newgid; // add old and new qid to the mapping array
$results['groups']++;
}
Expand Down Expand Up @@ -2667,11 +2681,14 @@ function TSVImportSurvey($sFullFilePath)
} else {
$insertdata['group_order'] = $gseq;
}
$newgid = QuestionGroup::model()->insertRecords($insertdata);
if (!$newgid) {
$questionGroup = new QuestionGroup();
$questionGroup->attributes = $insertdata;

if (!$questionGroup->save()) {
$results['error'][] = gT("Error")." : ".gT("Failed to insert group").". ".gT("Text file row number ").$rownumber." (".$gname.")";
break;
}
$newgid = $questionGroup->gid;
if (!isset($ginfo[$sGroupseq])) {
$results['groups']++;
$gid = $newgid;
Expand Down
6 changes: 3 additions & 3 deletions application/models/QuestionGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ public function search()
protected function beforeSave()
{
if (parent::beforeSave()) {
$surveyIsActive = Survey::model()->findByPk($this->sid)->active !== 'N';
if ($surveyIsActive && $this->getIsNewRecord()) {
/* And for multi lingual, when add a new language ? */
$survey = Survey::model()->findByPk($this->sid);
if (!empty($survey) && $survey->isActive && $this->getIsNewRecord()) {
/* And for multi lingual, when add a new language ? */
$this->addError('gid', gT("You can not add a group if survey is active."));
return false;
}
Expand Down

0 comments on commit 9cf61a6

Please sign in to comment.