Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-12063

Multianswer (Cloze) left orphan database items(multiplechoice,numerical) when saving a modified question.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.3
    • Fix Version/s: None
    • Component/s: Questions
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE

      Description

      When saving the questions, it reuse the same subquestion without checking that the qtype has changed.
      So if the first subquestion is a numerical one and in the modifed question this became a shortanswer the question_numerical database item always exist and refers to a question that is a shortanswer.
      Unused subquestions are simply deleted by
      // Delete redundant wrapped questions
      if(is_array($oldwrappedids) && count($oldwrappedids))

      { $oldwrappedids = implode(',', $oldwrappedids); delete_records_select('question', "id IN ($oldwrappedids)"); }

      the other database items are ignored...
      As I am writing a new code for multiquestion i will solve this.

        Gliffy Diagrams

          Activity

          Hide
          ppichet Pierre Pichet added a comment -

          qtype question where not deleted when deleting unused questions or when the qtype change when using existing one.
          here the diffs
          — questiontype.php 6 Oct 2007 20:51:28 -0000 1.41
          +++ questiontype.php 20 Nov 2007 03:12:44 -0000
          @@ -74,6 +74,24 @@
          // if we still have some old wrapped question ids, reuse the next of them
          if ($oldwrappedid = array_shift($oldwrappedids)) {
          $wrapped->id = $oldwrappedid;
          + //
          + $oldqtype = get_field('question', 'qtype', 'id',$oldwrappedid) ;
          + if($oldqtype != $wrapped->qtype ) {
          + echo "<p>oldqtype $oldqtype newqtype".$wrapped->qtype."</p>";
          + switch ($oldqtype)

          { + case 'multichoice': + delete_records('question_multichoice', 'question', $oldwrappedid); + break; + case 'shortanswer': + delete_records('question_shortanswer', 'question', $oldwrappedid); + break; + case 'numerical': + delete_records('question_numerical', 'question', $oldwrappedid); + break; + default: + error("questiontype $wrapped->qtype not recognized"); + }

          + }
          }
          $wrapped->name = $question->name;
          $wrapped->parent = $question->id;
          @@ -85,8 +103,9 @@

          // Delete redundant wrapped questions
          if(is_array($oldwrappedids) && count($oldwrappedids)){

          • $oldwrappedids = implode(',', $oldwrappedids);
          • delete_records_select('question', "id IN ($oldwrappedids)");
            + foreach ($oldwrappedids as $id) { + delete_question($id) ; + }

            }

          if (!empty($sequence)) {

          Show
          ppichet Pierre Pichet added a comment - qtype question where not deleted when deleting unused questions or when the qtype change when using existing one. here the diffs — questiontype.php 6 Oct 2007 20:51:28 -0000 1.41 +++ questiontype.php 20 Nov 2007 03:12:44 -0000 @@ -74,6 +74,24 @@ // if we still have some old wrapped question ids, reuse the next of them if ($oldwrappedid = array_shift($oldwrappedids)) { $wrapped->id = $oldwrappedid; + // + $oldqtype = get_field('question', 'qtype', 'id',$oldwrappedid) ; + if($oldqtype != $wrapped->qtype ) { + echo "<p>oldqtype $oldqtype newqtype".$wrapped->qtype."</p>"; + switch ($oldqtype) { + case 'multichoice': + delete_records('question_multichoice', 'question', $oldwrappedid); + break; + case 'shortanswer': + delete_records('question_shortanswer', 'question', $oldwrappedid); + break; + case 'numerical': + delete_records('question_numerical', 'question', $oldwrappedid); + break; + default: + error("questiontype $wrapped->qtype not recognized"); + } + } } $wrapped->name = $question->name; $wrapped->parent = $question->id; @@ -85,8 +103,9 @@ // Delete redundant wrapped questions if(is_array($oldwrappedids) && count($oldwrappedids)){ $oldwrappedids = implode(',', $oldwrappedids); delete_records_select('question', "id IN ($oldwrappedids)"); + foreach ($oldwrappedids as $id) { + delete_question($id) ; + } } if (!empty($sequence)) {

            People

            • Assignee:
              ppichet Pierre Pichet
              Reporter:
              ppichet Pierre Pichet
              Tester:
              Nobody
              Participants:
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: