Class: Moodle2CC::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/moodle2cc/migrator.rb

Constant Summary collapse

MOODLE_1_9 =
'1.9'
MOODLE_2 =
'2'

Instance Method Summary collapse

Constructor Details

#initialize(source, destination, options = {}) ⇒ Migrator

Returns a new instance of Migrator.

Raises:



9
10
11
12
13
14
15
16
17
18
# File 'lib/moodle2cc/migrator.rb', line 9

def initialize(source, destination, options={})
  @source = source
  @destination = destination
  @format = options['format'] || 'cc'
  Moodle2CC::Logger.logger = options['logger'] || ::Logger.new(STDOUT)
  raise(Moodle2CC::Error, "'#{@source}' does not exist") unless File.exists?(@source)
  raise(Moodle2CC::Error, "'#{@destination}' is not a directory") unless File.directory?(@destination)
  raise(Moodle2CC::Error, "'#{@format}' is not a valid format. Please use 'cc' or 'canvas'.") unless ['cc', 'canvas'].include?(@format)
  @converter_class = @format == 'cc' ? Moodle2CC::CC::Converter : Moodle2CC::Canvas::Converter
end

Instance Method Details

#imscc_pathObject



31
32
33
# File 'lib/moodle2cc/migrator.rb', line 31

def imscc_path
  @converter.imscc_path
end

#migrateObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/moodle2cc/migrator.rb', line 20

def migrate
  case moodle_version
    when MOODLE_1_9
      migrate_moodle_1_9
    when MOODLE_2
      migrate_moodle_2
  end
rescue StandardError => error
  Moodle2CC::Logger.add_warning 'error migrating content', error
end

#migrate_moodle_1_9Object



35
36
37
38
39
# File 'lib/moodle2cc/migrator.rb', line 35

def migrate_moodle_1_9
  backup = Moodle2CC::Moodle::Backup.read @source
  @converter = @converter_class.new backup, @destination
  @converter.convert
end

#migrate_moodle_2Object



41
42
43
44
# File 'lib/moodle2cc/migrator.rb', line 41

def migrate_moodle_2
  @converter = Moodle2CC::Moodle2Converter::Migrator.new(@source, @destination)
  @converter.migrate
end