Class: Gitlab::ImportExport::Project::TreeRestorer

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/import_export/project/tree_restorer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(user:, shared:, project:) ⇒ TreeRestorer

Returns a new instance of TreeRestorer.


13
14
15
16
17
# File 'lib/gitlab/import_export/project/tree_restorer.rb', line 13

def initialize(user:, shared:, project:)
  @user = user
  @shared = shared
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project


11
12
13
# File 'lib/gitlab/import_export/project/tree_restorer.rb', line 11

def project
  @project
end

#sharedObject (readonly)

Returns the value of attribute shared


10
11
12
# File 'lib/gitlab/import_export/project/tree_restorer.rb', line 10

def shared
  @shared
end

#userObject (readonly)

Returns the value of attribute user


9
10
11
# File 'lib/gitlab/import_export/project/tree_restorer.rb', line 9

def user
  @user
end

Instance Method Details

#restoreObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gitlab/import_export/project/tree_restorer.rb', line 19

def restore
  unless relation_reader
    raise Gitlab::ImportExport::Error, 'invalid import format'
  end

  @project_attributes = relation_reader.consume_attributes(importable_path)
  @project_members = relation_reader.consume_relation(importable_path, 'project_members')
    .map(&:first)

  # ensure users are mapped before tree restoration
  # so that even if there is no content to associate
  # users with, they are still added to the project
  members_mapper.map

  if relation_tree_restorer.restore
    import_failure_service.with_retry(action: 'set_latest_merge_request_diff_ids!') do
      @project.merge_requests.set_latest_merge_request_diff_ids!
    end

    true
  else
    false
  end
rescue => e
  @shared.error(e)
  false
end