Class: Users::MigrateToGhostUserService

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Concern
Defined in:
app/services/users/migrate_to_ghost_user_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ MigrateToGhostUserService

Returns a new instance of MigrateToGhostUserService.


15
16
17
# File 'app/services/users/migrate_to_ghost_user_service.rb', line 15

def initialize(user)
  @user = user
end

Instance Attribute Details

#ghost_userObject (readonly)

Returns the value of attribute ghost_user


13
14
15
# File 'app/services/users/migrate_to_ghost_user_service.rb', line 13

def ghost_user
  @ghost_user
end

#userObject (readonly)

Returns the value of attribute user


13
14
15
# File 'app/services/users/migrate_to_ghost_user_service.rb', line 13

def user
  @user
end

Instance Method Details

#executeObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/users/migrate_to_ghost_user_service.rb', line 19

def execute
  transition = user.block_transition

  user.transaction do
    # Block the user before moving records to prevent a data race.
    # For example, if the user creates an issue after `migrate_issues`
    # runs and before the user is destroyed, the destroy will fail with
    # an exception.
    user.block

    # Reverse the user block if record migration fails
    if !migrate_records_in_transaction && transition
      transition.rollback
      user.save!
    end
  end

  user.reset
end