don't use quiz_question setter for question_data

test plan:
  - run against a quiz with left and right matching questions
  - matches should still be there

refs LS-1678
flag=none

Change-Id: Id813ea430ef6f98671934e9c001ddc5aafeb75b1
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/254434
Reviewed-by: Nate Armstrong <narmstrong@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2020-12-06 15:38:48 -07:00
parent efc00abd74
commit d71f3c712a
1 changed files with 8 additions and 8 deletions

View File

@ -28,8 +28,9 @@ module QuizMathDataFixup
questions = questions.where("updated_at>?", check_date) if check_date questions = questions.where("updated_at>?", check_date) if check_date
questions.find_each do |quiz_question| questions.find_each do |quiz_question|
begin begin
new_data = fixup_question_data(quiz_question.question_data) old_data = quiz_question.question_data.to_hash
quiz_question.question_data = new_data new_data = fixup_question_data(quiz_question.question_data.to_hash)
quiz_question.write_attribute(:question_data, new_data) if new_data != old_data
if quiz_question.changed? if quiz_question.changed?
stat = question_bank ? 'updated_math_qb_question' : 'updated_math_question' stat = question_bank ? 'updated_math_qb_question' : 'updated_math_question'
InstStatsd::Statsd.increment(stat) InstStatsd::Statsd.increment(stat)
@ -61,13 +62,11 @@ module QuizMathDataFixup
end end
end end
def fixup_question_data(question) def fixup_question_data(data)
question[:answers]&.each_with_index do |answer, index| data[:answers]&.each_with_index do |answer, index|
old_answer = answer.dup data[:answers][index] = fixup_answer(answer)
new_answer = fixup_answer(answer)
question[:answers][index] = new_answer if new_answer != old_answer
end end
question data
end end
def fixup_answer(answer) def fixup_answer(answer)
@ -82,6 +81,7 @@ module QuizMathDataFixup
if (answer[shtml] && answer[shtml].length > 0) if (answer[shtml] && answer[shtml].length > 0)
html = answer[shtml] html = answer[shtml]
html = Nokogiri::HTML::DocumentFragment.parse(html) html = Nokogiri::HTML::DocumentFragment.parse(html)
html.search('[id^="MathJax"]').each(&:remove)
if html.children.length == 1 && html.children[0].node_type == Nokogiri::XML::Node::TEXT_NODE if html.children.length == 1 && html.children[0].node_type == Nokogiri::XML::Node::TEXT_NODE
m = %r{equation_images\/([^\s]+)}.match(html.content) m = %r{equation_images\/([^\s]+)}.match(html.content)
if m && m[1] if m && m[1]