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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Migrator.

Raises:



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

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 Attribute Details

#last_errorObject

Returns the value of attribute last_error.



6
7
8
# File 'lib/moodle2cc/migrator.rb', line 6

def last_error
  @last_error
end

Instance Method Details

#imscc_pathObject



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

def imscc_path
  @converter.imscc_path
end

#migrateObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/moodle2cc/migrator.rb', line 22

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

#migrate_moodle_1_9Object



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

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

#migrate_moodle_2Object



45
46
47
48
# File 'lib/moodle2cc/migrator.rb', line 45

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