Class: Groups::ImportExport::ImportService

Inherits:
Object
  • Object
show all
Defined in:
app/services/groups/import_export/import_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group:, user:) ⇒ ImportService

Returns a new instance of ImportService.


8
9
10
11
12
13
# File 'app/services/groups/import_export/import_service.rb', line 8

def initialize(group:, user:)
  @group = group
  @current_user = user
  @shared = Gitlab::ImportExport::Shared.new(@group)
  @logger = Gitlab::Import::Logger.build
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user


6
7
8
# File 'app/services/groups/import_export/import_service.rb', line 6

def current_user
  @current_user
end

#groupObject (readonly)

Returns the value of attribute group


6
7
8
# File 'app/services/groups/import_export/import_service.rb', line 6

def group
  @group
end

#paramsObject (readonly)

Returns the value of attribute params


6
7
8
# File 'app/services/groups/import_export/import_service.rb', line 6

def params
  @params
end

Instance Method Details

#async_executeObject


15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/groups/import_export/import_service.rb', line 15

def async_execute
  group_import_state = GroupImportState.safe_find_or_create_by!(group: group)
  jid = GroupImportWorker.perform_async(current_user.id, group.id)

  if jid.present?
    group_import_state.update!(jid: jid)
  else
    group_import_state.fail_op('Failed to schedule import job')

    false
  end
end

#executeObject


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/groups/import_export/import_service.rb', line 28

def execute
  if valid_user_permissions? && import_file && restorer.restore
    notify_success

    @group
  else
    notify_error!
  end

ensure
  remove_base_tmp_dir
  remove_import_file
end