View Issue Details

This issue affects 1 person(s).
 4
IDProjectCategoryView StatusLast Update
18397Bug reportsSurvey editingpublic2026-10-20 17:06
Reportergabrieljenik Assigned Toc_schmitz  
PrioritynoneSeveritypartial_block 
Status closedResolutionfixed 
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 heat4
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
Git branch / Pull Request URL

Relationships

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

Users monitoring this issue

There are no users monitoring this issue.

Activities

c_schmitz

c_schmitz

2026-10-13 20:08

administrator   ~86438

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=40833

LimeBot

LimeBot

2026-10-20 17:06

administrator   ~86603

Fixed in Release 7.7.0+261020

Related Changesets

LimeSurvey: master 49ecc31f

2026-10-13 20:08

c_schmitz


Details Diff
Fixed issue 18397: When copying a question, subquestions and answer options that could not be copied were dropped without an error message
Dev A failed subquestion no longer stops all following subquestions from being copied; the validation errors of all parts (subquestions, answer options, default answers, texts, settings) are shown as warning after the copy and in the survey copy results
Affected Issues
18397
mod - application/controllers/QuestionAdministrationController.php Diff File
mod - application/models/services/CopyQuestion.php Diff File
mod - application/models/services/CopySurvey.php Diff File
add - tests/unit/services/CopyQuestionTest.php Diff File

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
2026-10-13 20:08 c_schmitz Changeset attached => LimeSurvey master 49ecc31f
2026-10-13 20:08 c_schmitz Note Added: 86438
2026-10-13 20:08 c_schmitz Assigned To => c_schmitz
2026-10-13 20:08 c_schmitz Status confirmed => resolved
2026-10-13 20:08 c_schmitz Resolution open => fixed
2026-10-13 20:08 c_schmitz Bug heat 0 => 2
2026-10-20 17:06 LimeBot Note Added: 86603
2026-10-20 17:06 LimeBot Status resolved => closed
2026-10-20 17:06 LimeBot Bug heat 2 => 4