diff --git a/app/models/content_migration.rb b/app/models/content_migration.rb index b0aac1db87f..e575b37ed28 100644 --- a/app/models/content_migration.rb +++ b/app/models/content_migration.rb @@ -185,6 +185,7 @@ class ContentMigration < ActiveRecord::Base @zip_file = Zip::ZipFile.open(@exported_data_zip.path) data = JSON.parse(@zip_file.read('course_export.json')) data = data.with_indifferent_access if data.is_a? Hash + data['all_files_export'] ||= {} if @zip_file.find_entry('all_files.zip') # the file importer needs an actual file to process @@ -192,7 +193,7 @@ class ContentMigration < ActiveRecord::Base @zip_file.extract('all_files.zip', all_files_path) data['all_files_export']['file_path'] = all_files_path else - data['all_files_export']['file_path'] = nil if data['all_files_export'] + data['all_files_export']['file_path'] = nil end @zip_file.close diff --git a/app/models/discussion_topic.rb b/app/models/discussion_topic.rb index c4bc18aca4b..7331dcb17b8 100644 --- a/app/models/discussion_topic.rb +++ b/app/models/discussion_topic.rb @@ -499,7 +499,7 @@ class DiscussionTopic < ActiveRecord::Base item.delayed_post_at ||= Canvas::MigratorHelper.get_utc_time_from_timestamp(hash[:start_date]) if hash[:start_date] item.position = hash[:position] if hash[:position] if hash[:attachment_migration_id] - item.attachment context.attachments.find_by_migration_id(hash[:attachment_migration_id]) + item.attachment = context.attachments.find_by_migration_id(hash[:attachment_migration_id]) end if hash[:external_feed_migration_id] item.external_feed = context.external_feeds.find_by_migration_id(hash[:external_feed_migration_id]) diff --git a/lib/cc/importer.rb b/lib/cc/importer.rb index c91c737e271..e864419c5e9 100644 --- a/lib/cc/importer.rb +++ b/lib/cc/importer.rb @@ -27,5 +27,6 @@ require_dependency 'cc/importer/learning_outcomes_converter' require_dependency 'cc/importer/wiki_converter' require_dependency 'cc/importer/assignment_converter' require_dependency 'cc/importer/topic_converter' +require_dependency 'cc/importer/webcontent_converter' require_dependency 'cc/importer/course_settings' require_dependency 'cc/importer/cc_converter' diff --git a/lib/cc/importer/cc_converter.rb b/lib/cc/importer/cc_converter.rb index 9bf5cd87161..6fe9ac5c9c2 100644 --- a/lib/cc/importer/cc_converter.rb +++ b/lib/cc/importer/cc_converter.rb @@ -22,6 +22,7 @@ module CC::Importer include WikiConverter include AssignmentConverter include TopicConverter + include WebcontentConverter MANIFEST_FILE = "imsmanifest.xml" @@ -40,6 +41,8 @@ module CC::Importer @course[:wikis] = convert_wikis @course[:assignments] = convert_assignments @course[:discussion_topics] = convert_topics + @course[:file_map] = create_file_map + package_course_files #close up shop save_to_file diff --git a/lib/cc/importer/webcontent_converter.rb b/lib/cc/importer/webcontent_converter.rb new file mode 100644 index 00000000000..778b7667676 --- /dev/null +++ b/lib/cc/importer/webcontent_converter.rb @@ -0,0 +1,53 @@ +# +# Copyright (C) 2011 Instructure, Inc. +# +# This file is part of Canvas. +# +# Canvas is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, version 3 of the License. +# +# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along +# with this program. If not, see . +# +module CC::Importer + module WebcontentConverter + include CC::Importer + + def create_file_map + file_map = {} + + @manifest.css("resource[type=#{WEBCONTENT}][href^=#{WEB_RESOURCES_FOLDER}]").each do |res| + file = {} + file['migration_id'] = res['identifier'] + file['path_name'] = res['href'].sub(WEB_RESOURCES_FOLDER + '/', '') + file['file_name'] = File.basename file['path_name'] + file['type'] = 'FILE_TYPE' + + file_map[file['migration_id']] = file + end + + file_map + end + + def package_course_files + zip_file = File.join(@base_export_dir, 'all_files.zip') + make_export_dir + path = get_full_path(WEB_RESOURCES_FOLDER) + Zip::ZipFile.open(zip_file, 'w') do |zipfile| + Dir["#{path}/**/**"].each do |file| + file_path = file.sub(path+'/', '') + zipfile.add(file_path, file) + end + end + + File.expand_path(zip_file) + end + + end +end