fix importing module items with missing content
fixes an issue that arose with rails 3, where module items that were not set with content (and thus shouldn't have been saved) were being autosaved and breaking the entire modules page test plan: * import the package(s) referenced in the ticket * the modules page should still be functional fixes #CNVS-14777 Change-Id: I82fe287a4db9492489461e971911a0f7c15fbcb0 Reviewed-on: https://gerrit.instructure.com/39404 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Clare Strong <clare@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
ce84a3575c
commit
d25d9e23bc
|
@ -93,7 +93,7 @@ module Importers
|
|||
hash[:migration_id] ||= Digest::MD5.hexdigest(hash[:title]) if hash[:title]
|
||||
existing_item = context_module.content_tags.find_by_id(hash[:id]) if hash[:id].present?
|
||||
existing_item ||= context_module.content_tags.find_by_migration_id(hash[:migration_id]) if hash[:migration_id]
|
||||
existing_item ||= context_module.content_tags.new(:context => context)
|
||||
existing_item ||= ContentTag.new(:context_module => context_module, :context => context)
|
||||
if hash[:workflow_state] == 'unpublished'
|
||||
existing_item.workflow_state = 'unpublished'
|
||||
else
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class FixContentTagsWithoutContent < ActiveRecord::Migration
|
||||
tag :postdeploy
|
||||
|
||||
def up
|
||||
DataFixup::FixContentTagsWithoutContent.send_later_if_production(:run)
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
module DataFixup::FixContentTagsWithoutContent
|
||||
def self.run
|
||||
while ContentTag.where("context_module_id IS NOT NULL AND content_id IS NULL AND
|
||||
content_type IS NULL AND tag_type = ?", "default").limit(1000).delete_all > 0
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
||||
require 'db/migrate/20140815192313_fix_content_tags_without_content.rb'
|
||||
|
||||
describe 'FixContentTagsWithoutContents' do
|
||||
describe "up" do
|
||||
it "should delete corrupt content tags from migrations" do
|
||||
course
|
||||
mod = @course.context_modules.create!
|
||||
tag = mod.content_tags.new(:context => @course)
|
||||
tag.save(:validate => false)
|
||||
FixContentTagsWithoutContent.new.up
|
||||
|
||||
ContentTag.find_by_id(tag.id).should be_nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -109,4 +109,31 @@ describe "Importing modules" do
|
|||
tag2.content.should == tool2
|
||||
end
|
||||
|
||||
it "should not create a blank tag if the content is not found" do
|
||||
data = { :migration_id => "1", :title => "derp",
|
||||
:items => [{
|
||||
:migration_id => 'mig1',
|
||||
:type => "linked_resource",
|
||||
:linked_resource_title => "whatevs",
|
||||
:linked_resource_type => "externalurl",
|
||||
:url => "http://exmpale.com/stuff"
|
||||
},
|
||||
{
|
||||
:migration_id => 'mig2',
|
||||
:type => "linked_resource",
|
||||
:linked_resource_title => "whatevs",
|
||||
:linked_resource_type => "WikiPage",
|
||||
:linked_resource_id => '2'
|
||||
}],
|
||||
:completion_requirements => [{:type => "must_view", :item_migration_id => "mig1"}]
|
||||
}
|
||||
|
||||
course_model
|
||||
migration = ContentMigration.new
|
||||
mod = Importers::ContextModuleImporter.import_from_migration(data, @course, migration)
|
||||
mod.reload
|
||||
|
||||
mod.content_tags.count.should == 1
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue