diff options
Diffstat (limited to 'app/services/users/migrate_to_ghost_user_service.rb')
-rw-r--r-- | app/services/users/migrate_to_ghost_user_service.rb | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/app/services/users/migrate_to_ghost_user_service.rb b/app/services/users/migrate_to_ghost_user_service.rb index a471f55e644..515d7821416 100644 --- a/app/services/users/migrate_to_ghost_user_service.rb +++ b/app/services/users/migrate_to_ghost_user_service.rb @@ -14,23 +14,30 @@ module Users def initialize(user) @user = user + @ghost_user = User.ghost end 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 + # 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 + begin + user.transaction do + migrate_records + end + rescue Exception # rubocop:disable Lint/RescueException # Reverse the user block if record migration fails - if !migrate_records_in_transaction && transition + if transition transition.rollback user.save! end + + raise end user.reset @@ -38,14 +45,6 @@ module Users private - def migrate_records_in_transaction - user.transaction(requires_new: true) do - @ghost_user = User.ghost - - migrate_records - end - end - def migrate_records migrate_issues migrate_merge_requests |