copy/import module links correctly. fixes #4312
Change-Id: I98ecc6bb63252269bf789320a8a5b2de5612efda Reviewed-on: https://gerrit.instructure.com/3308 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
parent
c1ae78e895
commit
47601e1e4e
|
@ -1450,17 +1450,6 @@ class Assignment < ActiveRecord::Base
|
||||||
item
|
item
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_or_create_for_new_context(new_context, old_context, old_id)
|
|
||||||
res = new_context.assignments.active.find_by_cloned_item_id(old_context.assignments.find_by_id(old_id).cloned_item_id || 0) rescue nil
|
|
||||||
res = nil if res && !res.cloned_item_id
|
|
||||||
if !res
|
|
||||||
old = old_context.assignments.active.find_by_id(old_id)
|
|
||||||
res = old.clone_for(new_context) if old
|
|
||||||
res.save if res
|
|
||||||
end
|
|
||||||
res
|
|
||||||
end
|
|
||||||
|
|
||||||
def expects_submission?
|
def expects_submission?
|
||||||
submission_types && submission_types.strip != "" && submission_types != "none" && submission_types != 'not_graded' && submission_types != "on_paper"
|
submission_types && submission_types.strip != "" && submission_types != "none" && submission_types != 'not_graded' && submission_types != "on_paper"
|
||||||
end
|
end
|
||||||
|
|
|
@ -609,17 +609,6 @@ class Attachment < ActiveRecord::Base
|
||||||
"application/x-shockwave-flash" => "flash"
|
"application/x-shockwave-flash" => "flash"
|
||||||
}[content_type] || "file"
|
}[content_type] || "file"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_or_create_for_new_context(new_context, old_context, old_id)
|
|
||||||
res = new_context.attachments.active.find_by_cloned_item_id(old_context.attachments.find_by_id(old_id).cloned_item_id || 0) rescue nil
|
|
||||||
res = nil if res && !res.cloned_item_id
|
|
||||||
if !res
|
|
||||||
old = old_context.attachments.active.find_by_id(old_id)
|
|
||||||
res = old.clone_for(new_context) if old
|
|
||||||
res.save if res
|
|
||||||
end
|
|
||||||
res
|
|
||||||
end
|
|
||||||
|
|
||||||
set_policy do
|
set_policy do
|
||||||
given { |user, session| self.cached_context_grants_right?(user, session, :manage_files) } #admins.include? user }
|
given { |user, session| self.cached_context_grants_right?(user, session, :manage_files) } #admins.include? user }
|
||||||
|
|
|
@ -276,17 +276,6 @@ class CalendarEvent < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
item
|
item
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_or_create_for_new_context(new_context, old_context, old_id)
|
|
||||||
res = new_context.calendar_events.active.find_by_cloned_item_id(old_context.calendar_events.find_by_id(old_id).cloned_item_id || 0) rescue nil
|
|
||||||
res = nil if res && !res.cloned_item_id
|
|
||||||
if !res
|
|
||||||
old = old_context.calendar_events.active.find_by_id(old_id)
|
|
||||||
res = old.clone_for(new_context) if old
|
|
||||||
res.save if res
|
|
||||||
end
|
|
||||||
res
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.max_visible_calendars
|
def self.max_visible_calendars
|
||||||
10
|
10
|
||||||
|
|
|
@ -1034,6 +1034,18 @@ class Course < ActiveRecord::Base
|
||||||
def turnitin_enabled?
|
def turnitin_enabled?
|
||||||
!!self.turnitin_settings
|
!!self.turnitin_settings
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.find_or_create_for_new_context(obj_class, new_context, old_context, old_id)
|
||||||
|
association_name = obj_class.table_name
|
||||||
|
old_item = old_context.send(association_name).find_by_id(old_id)
|
||||||
|
res = new_context.send(association_name).active.find_by_cloned_item_id(old_item.cloned_item_id) if old_item
|
||||||
|
if !res
|
||||||
|
old_item = old_context.send(association_name).active.find_by_id(old_id)
|
||||||
|
res = old_item.clone_for(new_context) if old_item
|
||||||
|
res.save if res
|
||||||
|
end
|
||||||
|
res
|
||||||
|
end
|
||||||
|
|
||||||
def self.migrate_content_links(html, from_context, to_context, supported_types=nil, user_to_check_for_permission=nil)
|
def self.migrate_content_links(html, from_context, to_context, supported_types=nil, user_to_check_for_permission=nil)
|
||||||
return html unless from_context
|
return html unless from_context
|
||||||
|
@ -1058,7 +1070,8 @@ class Course < ActiveRecord::Base
|
||||||
'files' => Attachment,
|
'files' => Attachment,
|
||||||
'conferences' => WebConference,
|
'conferences' => WebConference,
|
||||||
'quizzes' => Quiz,
|
'quizzes' => Quiz,
|
||||||
'groups' => Group
|
'groups' => Group,
|
||||||
|
'modules' => ContextModule
|
||||||
}.each do |type, obj_class|
|
}.each do |type, obj_class|
|
||||||
sub_regex = Regexp.new("#{type}/(\\d+)[^\\s]*$")
|
sub_regex = Regexp.new("#{type}/(\\d+)[^\\s]*$")
|
||||||
is_sub_item ||= sub_spot.match(sub_regex)
|
is_sub_item ||= sub_spot.match(sub_regex)
|
||||||
|
@ -1076,7 +1089,7 @@ class Course < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if !new_id && allow_migrate_content && to_context != from_context
|
if !new_id && allow_migrate_content && to_context != from_context
|
||||||
new_obj = obj_class.find_or_create_for_new_context(to_context, from_context, item[1]) rescue nil
|
new_obj = self.find_or_create_for_new_context(obj_class, to_context, from_context, item[1])
|
||||||
new_id ||= new_obj.id if new_obj
|
new_id ||= new_obj.id if new_obj
|
||||||
end
|
end
|
||||||
if !limit_migrations_to_listed_types || new_id
|
if !limit_migrations_to_listed_types || new_id
|
||||||
|
|
|
@ -711,17 +711,6 @@ class Quiz < ActiveRecord::Base
|
||||||
dup
|
dup
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_or_create_for_new_context(new_context, old_context, old_id)
|
|
||||||
res = new_context.quizzes.active.find_by_cloned_item_id(old_context.quizzes.find_by_id(old_id).cloned_item_id || 0) rescue nil
|
|
||||||
res = nil if res && !res.cloned_item_id
|
|
||||||
if !res
|
|
||||||
old = old_context.quizzes.active.find_by_id(old_id)
|
|
||||||
res = old.clone_for(new_context) if old
|
|
||||||
res.save if res
|
|
||||||
end
|
|
||||||
res
|
|
||||||
end
|
|
||||||
|
|
||||||
def statistics_csv(options={})
|
def statistics_csv(options={})
|
||||||
options ||= {}
|
options ||= {}
|
||||||
columns = []
|
columns = []
|
||||||
|
|
Loading…
Reference in New Issue