Class: Moodle2CC::Moodle2Converter::FileConverter

Inherits:
Object
  • Object
show all
Includes:
ConverterHelper
Defined in:
lib/moodle2cc/moodle2converter/file_converter.rb

Constant Summary

Constants included from ConverterHelper

ConverterHelper::ACTIVITY_LOOKUP, ConverterHelper::ASSESSMENT_SUFFIX, ConverterHelper::ASSIGNMENT_SUFFIX, ConverterHelper::CHAPTER_SUFFIX, ConverterHelper::CHOICE_ASSESSMENT_SUFFIX, ConverterHelper::COURSE_SUFFIX, ConverterHelper::DISCUSSION_SUFFIX, ConverterHelper::EXTERNAL_URL_SUFFIX, ConverterHelper::FEEDBACK_ASSESSMENT_SUFFIX, ConverterHelper::FILE_SUFFIX, ConverterHelper::FOLDER_SUFFIX, ConverterHelper::GLOSSARY_SUFFIX, ConverterHelper::INTRO_SUFFIX, ConverterHelper::LTI_SUFFIX, ConverterHelper::MAX_TITLE_LENGTH, ConverterHelper::MODULE_SUFFIX, ConverterHelper::PAGE_SUFFIX, ConverterHelper::QUESTIONNAIRE_ASSESSMENT_SUFFIX, ConverterHelper::QUESTION_BANK_SUFFIX, ConverterHelper::SUMMARY_PAGE_SUFFIX

Instance Method Summary collapse

Methods included from ConverterHelper

#activity_content_type, #generate_unique_identifier, #generate_unique_identifier_for, #generate_unique_identifier_for_activity, #generate_unique_resource_path, #get_unique_identifier_for_activity, #truncate_text, #workflow_state

Instance Method Details

#convert(moodle_file) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/moodle2cc/moodle2converter/file_converter.rb', line 5

def convert(moodle_file)
  canvas_file = Moodle2CC::CanvasCC::Models::CanvasFile.new

  unique_id = moodle_file.content_hash
  # we probably shouldn't have been using these as identifiers but if we change it now we'll break updates on re-import

  id_set = Migrator.unique_id_set
  if id_set.include?(unique_id)
    original_id = unique_id
    index = 0
    while id_set.include?(unique_id)
      index += 1
      unique_id = "#{original_id}#{index}"
    end
  end
  id_set << unique_id

  canvas_file.identifier = unique_id
  canvas_file.file_path = moodle_file.file_path + moodle_file.file_name
  canvas_file.file_location = moodle_file.file_location
  canvas_file
end