Class: Pages::MigrateLegacyStorageToDeploymentService

Inherits:
Object
  • Object
show all
Includes:
BaseServiceUtility
Defined in:
app/services/pages/migrate_legacy_storage_to_deployment_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(project, ignore_invalid_entries: false, mark_projects_as_not_deployed: false) ⇒ MigrateLegacyStorageToDeploymentService

Returns a new instance of MigrateLegacyStorageToDeploymentService.



9
10
11
12
13
# File 'app/services/pages/migrate_legacy_storage_to_deployment_service.rb', line 9

def initialize(project, ignore_invalid_entries: false, mark_projects_as_not_deployed: false)
  @project = project
  @ignore_invalid_entries = ignore_invalid_entries
  @mark_projects_as_not_deployed = mark_projects_as_not_deployed
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



7
8
9
# File 'app/services/pages/migrate_legacy_storage_to_deployment_service.rb', line 7

def project
  @project
end

Instance Method Details

#executeObject



15
16
17
18
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
46
47
# File 'app/services/pages/migrate_legacy_storage_to_deployment_service.rb', line 15

def execute
  zip_result = ::Pages::ZipDirectoryService.new(project.pages_path, ignore_invalid_entries: @ignore_invalid_entries).execute

  if zip_result[:status] == :error
    return error("Can't create zip archive: #{zip_result[:message]}")
  end

  archive_path = zip_result[:archive_path]

  unless archive_path
    return error("Archive not created. Missing public directory in #{@project.pages_path}") unless @mark_projects_as_not_deployed

    project.set_first_pages_deployment!(nil)

    return success(
      message: "Archive not created. Missing public directory in #{project.pages_path}? Marked project as not deployed")
  end

  deployment = nil
  File.open(archive_path) do |file|
    deployment = project.pages_deployments.create!(
      file: file,
      file_count: zip_result[:entries_count],
      file_sha256: Digest::SHA256.file(archive_path).hexdigest
    )
  end

  project.set_first_pages_deployment!(deployment)

  success
ensure
  FileUtils.rm_f(archive_path) if archive_path
end