Moodle
  1. Moodle
  2. MDL-19210

Multiple dataitems generated when using regenerate option

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.9.5
    • Fix Version/s: None
    • Component/s: Questions
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Rank:
      5288

      Description

      When using the regenerate option to create new dataitems, there is a possiblitéy to generate dataitems that have similar itemnumber.
      This do not invalidate the questions but these doublets should be eliminate if present and not generated.
      This was unnoticed before the new messages on Moodle HEAD on database processes like this one

      Did you remember to make the first column something unique in your call to get_records? Duplicate value 'a' found in column 'name'.

      • line 567 of lib\dml\mysqli_native_moodle_database.php: call to debugging()
      • line 1475 of question\type\calculated\questiontype.php: call to mysqli_native_moodle_database->get_records_sql()
      • line 343 of question\type\calculated\questiontype.php: call to question_calculated_qtype->pick_question_dataset()
      • line 1110 of lib\questionlib.php: call to question_calculated_qtype->create_session_and_responses()
      • line 1151 of lib\questionlib.php: call to question_load_states()
      • line 137 of question\preview.php: call to get_question_states()

      A solution has been found but further tests need to be done before CVS.

        Activity

        Hide
        Pierre Pichet added a comment -

        First we need to eliminate the generation of multiple dataitems having the same item number.
        This happens when you
        add say 20 items
        delete 10 items so only 10 remained on the display although the items 12 to 20 remain in the database.
        You decide then to add 10 items.
        You have the choice of
        using the items already generated in the first step, so nothing is done only the item number is increased
        or
        set the regerate button so that new values will be generated.
        However there was a flaw in the flow chart and new dataitems with item number between 12 and 20 are generated.
        Given the way that these new items are retrieved from the database, the new items with the new values are the one used.

        The proposed code solve the problem
        if (isset($datasetdefs[$defid]->items[$numberadded]) ){
        // in case of regenerate it modifies the already existingrecord
        if ( $regenerate ) {
        $datasetitem = new stdClass;
        $datasetitem->id = $datasetdefs[$defid]>items[$numberadded]>id;
        $datasetitem->definition = $datasetdef->id ;
        $datasetitem->itemnumber = $numberadded;
        $datasetitem->value = $this->generate_dataset_item($datasetdef->options);
        if (!$DB->update_record('question_dataset_items', $datasetitem))

        { print_error('cannotupdateitem', 'question'); }

        }
        //if not regenerate do nothing as there is already a record
        } else {
        I will CVS first on HEAD then merge ( without the $DB ...) on 1.9 and older versions.
        For HEAD and 1.9 I will also change the dataitems retrieving to make the first column something unique.

        Show
        Pierre Pichet added a comment - First we need to eliminate the generation of multiple dataitems having the same item number. This happens when you add say 20 items delete 10 items so only 10 remained on the display although the items 12 to 20 remain in the database. You decide then to add 10 items. You have the choice of using the items already generated in the first step, so nothing is done only the item number is increased or set the regerate button so that new values will be generated. However there was a flaw in the flow chart and new dataitems with item number between 12 and 20 are generated. Given the way that these new items are retrieved from the database, the new items with the new values are the one used. The proposed code solve the problem if (isset($datasetdefs [$defid] ->items [$numberadded] ) ){ // in case of regenerate it modifies the already existingrecord if ( $regenerate ) { $datasetitem = new stdClass; $datasetitem->id = $datasetdefs [$defid] >items [$numberadded] >id; $datasetitem->definition = $datasetdef->id ; $datasetitem->itemnumber = $numberadded; $datasetitem->value = $this->generate_dataset_item($datasetdef->options); if (!$DB->update_record('question_dataset_items', $datasetitem)) { print_error('cannotupdateitem', 'question'); } } //if not regenerate do nothing as there is already a record } else { I will CVS first on HEAD then merge ( without the $DB ...) on 1.9 and older versions. For HEAD and 1.9 I will also change the dataitems retrieving to make the first column something unique.
        Hide
        Michael de Raadt added a comment -

        Thanks for reporting this issue.

        We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

        If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

        Michael d;

        lqjjLKA0p6

        Show
        Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; lqjjLKA0p6
        Hide
        Michael de Raadt added a comment -

        I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

        Show
        Michael de Raadt added a comment - I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: