The error returned being:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

To duplicate the error you need more than 10 questions in they system to choose from, I have 40.

1. select the first 10 questions
2. Click save
SUCCESS
3. select the next lot of 10 questions
4. Click save
FAILED

To be able to add all 40 questions to the quiz I edited the query limit from 10 to 50 on line 1341 in quiz.module.

It seems that on every save action it is attempting to re-add the same questions rather than just the ones you have added since the last save (the ones with the * next to them)

Hope this helps.

Comments

Ibesan’s picture

Same here.

Sabareesh’s picture

Hi i found a way in which this error can be avoided. 'quiz_update_quiz_question_relationship' function in quiz.module has a query which according to me has no special purpose.
So i thought of commenting the Execute(); in the function. After commenting the execute function i saw the correct behavior in quiz module.
I am not sure whether this is the correct way to find a solution, but still it saved me some good time.
I have shared a piece of code that i changed in this function.

if (!empty($quiz_questions) && ($new_quiz_vid != $old_quiz_vid) ) {
    $query = db_insert('quiz_node_relationship')
      ->fields(array('parent_nid', 'child_nid', 'child_vid', 'question_status', 'weight', 'max_score', 'parent_vid'));
    foreach ($quiz_questions as $quiz_question) {
      $value = array(
        'parent_nid' => $quiz_nid,
        'parent_vid' => $new_quiz_vid,
        'child_nid' => $quiz_question['child_nid'],
        'child_vid' => $quiz_question['child_vid'],
        'question_status' => $quiz_question['question_status'],
        'weight' => $quiz_question['weight'],
        'max_score' => $quiz_question['max_score']
      );
      $query->values($value); 
    }
   // $query->execute(); Comment this line
  }
Ibesan’s picture

Works fine, thank you ;)

Sabareesh’s picture

Status: Active » Closed (fixed)
catproject’s picture

Title: Error assigning of questions to quiz » thanxxxx
Version: 7.x-4.x-dev » 7.x-5.x-dev

thanxxxx a lottt..... your way saved me ... :) thanx a lot man ... u are a true saviour ..:)

nahomadis’s picture

I would like to extend my thanks to Sabareesh.KF for that suggestion. I've spent some time trying to get it to work and your suggestion worked perfectly.

Thank you.