Dependency Graph

Dependency Graph
related to related to child of child of duplicate of duplicate of

View Issue Details

This bug affects 1 person(s).
 0
IDProjectCategoryView StatusLast Update
18397Bug reportsSurvey editingpublic2022-10-04 15:08
Reportergabrieljenik Assigned To 
PrioritynoneSeveritypartial_block 
Status confirmedResolutionopen 
Product Version5.3.x 
Summary18397: When copying a question with sub-questions, errors from subquestion models are not showed
Description

Caught while reviewing 18323.

Although models throw error, they are not handled.
Not even logged.

service/CopyQuestion.php

    public function copyQuestion($copyOptions)
    {
        $copySuccessful = $this->createNewCopiedQuestion(
            $this->copyQuestionValues->getQuestionCode(),
            $this->copyQuestionValues->getQuestionGroupId(),
            $this->copyQuestionValues->getQuestiontoCopy()
        );
        if ($copySuccessful) {
            //copy question languages
            $this->copyQuestionLanguages($this->copyQuestionValues->getQuestiontoCopy(), $this->copyQuestionValues->getQuestionL10nData());

            //copy subquestions
            if ($copyOptions['copySubquestions']) {
                $this->copyQuestionsSubQuestions($this->copyQuestionValues->getQuestiontoCopy()->qid);
            }
      ...
      ...

No checking of errors after save()

    private function copyQuestionsSubQuestions($parentId)
    {
        //copy subquestions
        $areSubquestionsCopied = true;
        $subquestions = \Question::model()->findAllByAttributes(['parent_qid' => $parentId]);

        foreach ($subquestions as $subquestion) {
            $copiedSubquestion = new \Question();
            $copiedSubquestion->attributes = $subquestion->attributes;
            $copiedSubquestion->parent_qid = $this->newQuestion->qid;
            $copiedSubquestion->qid = null; //new question id needed ...
            $areSubquestionsCopied = $areSubquestionsCopied && $copiedSubquestion->save();
            foreach ($subquestion->questionl10ns as $subquestLanguage) {
                $newSubquestLanguage = new \QuestionL10n();
                $newSubquestLanguage->attributes = $subquestLanguage->attributes;
                $newSubquestLanguage->qid = $copiedSubquestion->qid;
                $newSubquestLanguage->id = null;
                $newSubquestLanguage->save();
            }
        }

        return $areSubquestionsCopied;
    }
Steps To Reproduce

Same as in 18323
Debug a bit to be able to see the error.

TagsNo tags attached.
Bug heat0
Complete LimeSurvey version number (& build)5.3.30
I will donate to the project if issue is resolvedNo
BrowserOpera
Database type & versionmariadb Ver 15.1 Distrib 10.4.25-MariaDB, for Linux (x86_64) using readline 5.1
Server OS (if known)
Webserver software & version (if known)
PHP Version7.4

Relationships

related to 18323 closedgabrieljenik When copying a question with sub-questions, the sub-questions are not copied 

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2022-10-04 15:06 gabrieljenik New Issue
2022-10-04 15:06 gabrieljenik Issue generated from: 18323
2022-10-04 15:06 gabrieljenik Relationship added related to 18323
2022-10-04 15:07 gabrieljenik Description Updated
2022-10-04 15:08 gabrieljenik Status new => confirmed