import files for canvas cartridges

refs #3396

Change-Id: I0d8bc800a9556705f30cf609084e3bbf9bbf7600
Reviewed-on: https://gerrit.instructure.com/3122
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Bracken Mosbacker 2011-04-15 22:09:56 -06:00 committed by Brian Palmer
parent 9c058e377d
commit c9b8a23cb2
5 changed files with 60 additions and 2 deletions

View File

@ -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

View File

@ -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])

View File

@ -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'

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
#
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