Class: Gitlab::BackgroundMigration::LegacyUploadMover

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/background_migration/legacy_upload_mover.rb

Overview

This class takes a legacy upload and migrates it to the correct location

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(upload) ⇒ LegacyUploadMover

Returns a new instance of LegacyUploadMover.


12
13
14
15
16
17
# File 'lib/gitlab/background_migration/legacy_upload_mover.rb', line 12

def initialize(upload)
  @upload = upload
  @note = Note.find_by(id: upload.model_id)
  @project = note&.project
  @logger = Gitlab::BackgroundMigration::Logger.build
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger


10
11
12
# File 'lib/gitlab/background_migration/legacy_upload_mover.rb', line 10

def logger
  @logger
end

#noteObject (readonly)

Returns the value of attribute note


9
10
11
# File 'lib/gitlab/background_migration/legacy_upload_mover.rb', line 9

def note
  @note
end

#projectObject (readonly)

Returns the value of attribute project


9
10
11
# File 'lib/gitlab/background_migration/legacy_upload_mover.rb', line 9

def project
  @project
end

#uploadObject (readonly)

Returns the value of attribute upload


9
10
11
# File 'lib/gitlab/background_migration/legacy_upload_mover.rb', line 9

def upload
  @upload
end

Instance Method Details

#executeObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/background_migration/legacy_upload_mover.rb', line 19

def execute
  return unless upload
  return unless upload.model_type == 'Note'

  if !project
    # if we don't have models associated with the upload we can not move it
    warn('Deleting upload due to model not found.')

    destroy_legacy_upload
  elsif note.is_a?(LegacyDiffNote)
    return unless move_legacy_diff_file

    migrate_upload
  elsif !legacy_file_exists?
    warn('Deleting upload due to file not found.')
    destroy_legacy_upload
  else
    migrate_upload
  end
end