don't unresolve links in quiz data when shifting dates

test plan:
* create a quiz with a question with a link to a file
 (or anything, really)
* copy the course with date shifting
* the link should work when taking the quiz as a student

closes #CNVS-22615

Change-Id: I5eaf1026d74473e14ffbcbd166b71b245cc2f731
Reviewed-on: https://gerrit.instructure.com/62360
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Tested-by: Jenkins
QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2015-09-02 08:13:08 -06:00
parent 002e11e88d
commit 19e16ce43a
4 changed files with 63 additions and 0 deletions

View File

@ -157,6 +157,7 @@ module Importers
shift_options = self.shift_date_options(course, shift_options)
migration.imported_migration_items_by_class(Assignment).each do |event|
event.reload # just in case
event.due_at = shift_date(event.due_at, shift_options)
event.lock_at = shift_date(event.lock_at, shift_options)
event.unlock_at = shift_date(event.unlock_at, shift_options)
@ -165,6 +166,7 @@ module Importers
end
migration.imported_migration_items_by_class(Announcement).each do |event|
event.reload
event.delayed_post_at = shift_date(event.delayed_post_at, shift_options)
event.save_without_broadcasting
end
@ -176,18 +178,21 @@ module Importers
end
migration.imported_migration_items_by_class(DiscussionTopic).each do |event|
event.reload
event.delayed_post_at = shift_date(event.delayed_post_at, shift_options)
event.lock_at = shift_date(event.lock_at, shift_options)
event.save_without_broadcasting
end
migration.imported_migration_items_by_class(CalendarEvent).each do |event|
event.reload
event.start_at = shift_date(event.start_at, shift_options)
event.end_at = shift_date(event.end_at, shift_options)
event.save_without_broadcasting
end
migration.imported_migration_items_by_class(Quizzes::Quiz).each do |event|
event.reload # have to reload the quiz_data to keep link resolution - the others are just in case
event.due_at = shift_date(event.due_at, shift_options)
event.lock_at = shift_date(event.lock_at, shift_options)
event.unlock_at = shift_date(event.unlock_at, shift_options)

View File

@ -0,0 +1,10 @@
class FixUnresolvedLinksInQuizzes < ActiveRecord::Migration
tag :postdeploy
def up
DataFixup::FixUnresolvedLinksInQuizzes.send_later_if_production_enqueue_args(:run,
:priority => Delayed::LOW_PRIORITY, :n_strand => 'long_datafixups')
end
def down
end
end

View File

@ -0,0 +1,12 @@
module DataFixup
module FixUnresolvedLinksInQuizzes
def self.run
Quizzes::Quiz.find_ids_in_ranges(:batch_size => 10000) do |min_id, max_id|
Quizzes::Quiz.where(id: min_id..max_id).where("quiz_data like ?", "%LINK.PLACEHOLDER%").find_each do |quiz|
quiz.generate_quiz_data
quiz.save
end
end
end
end
end

View File

@ -382,5 +382,41 @@ describe ContentMigration do
expect(@copy_to.start_at).to eq start_at
expect(@copy_to.conclude_at).to eq conclude_at
end
it "should not break link resolution in quiz_data" do
topic = @copy_from.discussion_topics.create!(:title => "some topic", :message => "<p>some text</p>")
html = "<a href='/courses/#{@copy_from.id}/discussion_topics/#{topic.id}'>link</a>"
bank = @copy_from.assessment_question_banks.create!(:title => 'bank')
data = {'question_name' => 'test question', 'question_type' => 'essay_question', 'question_text' => html}
aq = bank.assessment_questions.create!(:question_data => data)
quiz = @copy_from.quizzes.create!(:due_at => "05 Jul 2012 06:00:00 UTC +00:00")
qq = quiz.quiz_questions.create!(:question_data => data)
quiz.generate_quiz_data
quiz.published_at = Time.now
quiz.workflow_state = 'available'
quiz.save!
options = {
:everything => true,
:shift_dates => true,
:old_start_date => 'Jul 1, 2012',
:old_end_date => 'Jul 11, 2012',
:new_start_date => 'Aug 5, 2012',
:new_end_date => 'Aug 15, 2012'
}
@cm.copy_options = options
@cm.save!
run_course_copy
topic_to = @copy_to.discussion_topics.where(:migration_id => mig_id(topic)).first
quiz_to = @copy_to.quizzes.where(:migration_id => mig_id(quiz)).first
data = quiz_to.quiz_data.to_yaml
expect(data).to_not include("LINK.PLACEHOLDER")
expect(data).to include("courses/#{@copy_to.id}/discussion_topics/#{topic_to.id}")
end
end
end