Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When you go to Edit an existing quiz with some results the quiz results are recalculated incorrectly. You don't need to make any changes, just re-saving the settings triggers the bug.I've isolated the bug to the
quiz_update_max_score_properties
function. It looks like the original query wasn't translated correctly into the new Drupal 7 style. I worked around this by using translating the D6 db_query to the D7 db_query api. I have a patch if anyone is interested.
Comment | File | Size | Author |
---|---|---|---|
#6 | quiz-results-incorrectly-recalculated-1314072-6.patch | 3.38 KB | ppc.coder |
#1 | quiz_results_incorrectly_recalculated-1314072-2.patch | 2.84 KB | ppc.coder |
Comments
Comment #1
ppc.coder CreditAttribution: ppc.coder commentedHere is the patch.
UPDATE: I found something wrong with this patch that causes an error when questions are being modified on a quiz. Working on an update.
Comment #2
SteveK CreditAttribution: SteveK commentedgetting this same issue. would love a fix. looking into it as well...
Comment #3
SteveK CreditAttribution: SteveK commentedI haven't received any errors when applying this patch and re-saving existing or adding new questions to the quiz. Can you elaborate where you notice the code failing?
Comment #4
Sabareesh CreditAttribution: Sabareesh commentedI found out the patch in http://drupal.org/files/quiz-quiz.pages_.inc_.patch, This offers some kind of solution to this issue. Looking forward to officially fix this at the earliest.
Comment #5
SteveK CreditAttribution: SteveK commentedSabareesh.KF, it doesn't look like that patch worked. re-saves all entries incorrectly.
Comment #6
ppc.coder CreditAttribution: ppc.coder commentedI've attached my patch that basically rewrites the db queries to do the calculation without the D7 dynamic queries which weren't ported over correctly. The cases that I missed in my first patch were in when a quiz was brand new and had no quiz results to update. I added a simple check return from the function in that situation.
Comment #7
Beanjammin CreditAttribution: Beanjammin commentedUsing the patch from #6 I run into a PDO exception when saving a quiz node edit:
Comment #8
Beanjammin CreditAttribution: Beanjammin commentedTo follow up on my post in #7, it turns out there was a problem in my database and when working with a properly set up quiz the quiz node saves without error when edited. On mysql the query could be rewritten to avoid the NULL problem:
I don't know how portable IFNULL() is, so it may not be practical.
Comment #9
Beanjammin CreditAttribution: Beanjammin commentedThere is still an issue with results calculations if a question is removed from the quiz after a user has taken the quiz. The simplest illustration of this is that a user with a 100% result before a question is removed will have a result of greater than 100% after a question is removed.
Comment #10
zeezhao CreditAttribution: zeezhao commentedIt is also an issue when you have "long answer" or "short answer" type questions in a quiz, and you edit it to score them.
Comment #11
Sabareesh CreditAttribution: Sabareesh commentedThe actual problem starts here, quiz.module line 2552. I think this is a redundant query. I commented the execute() and tried in my local instance, it worked fine wit out any errors.
I am not sure how this has to be done in a proper way, waiting to get suggestion form you all.
Comment #12
falcon CreditAttribution: falcon commentedI've commited a fix, but haven't done much testing.
Comment #13
zeezhao CreditAttribution: zeezhao commentedStill incorrect for existing quiz with "long answer" or "short answer" type questions,since those quizzes are edited to score the questions. I am using alpha version quiz-7.x-4.0-alpha1.
Unless will always be wrong for old quizzes? Please confirm. Thanks.
Comment #14
falcon CreditAttribution: falcon commentedNew version doesn't fix existing quizzes, but I have commited another very important fix for this issue now.
Comment #16
zeezhao CreditAttribution: zeezhao commentedI tried latest dev version, and it still incorrect for quiz with "long answer" or "short answer" type questions, since those quizzes are edited to score the questions.
Comment #19
ezraw CreditAttribution: ezraw commentedCould not reproduce this in 7.x-5.0-alpha-1. Tested by editing a quiz with a long answer and removing a long answer.
Comment #20
ezraw CreditAttribution: ezraw commentedIf this is still happening with 7.x-4.x please provide steps to reproduce.
Comment #24
falcon CreditAttribution: falcon commentedSeems to be fixed. Please re-open if the problem still exists.