diff options
Diffstat (limited to 'app/models/bulk_imports')
-rw-r--r-- | app/models/bulk_imports/entity.rb | 9 | ||||
-rw-r--r-- | app/models/bulk_imports/tracker.rb | 30 |
2 files changed, 33 insertions, 6 deletions
diff --git a/app/models/bulk_imports/entity.rb b/app/models/bulk_imports/entity.rb index 16224fde502..9127dab56a6 100644 --- a/app/models/bulk_imports/entity.rb +++ b/app/models/bulk_imports/entity.rb @@ -37,8 +37,9 @@ class BulkImports::Entity < ApplicationRecord validates :project, absence: true, if: :group validates :group, absence: true, if: :project - validates :source_type, :source_full_path, :destination_name, - :destination_namespace, presence: true + validates :source_type, :source_full_path, :destination_name, presence: true + validates :destination_namespace, exclusion: [nil], if: :group + validates :destination_namespace, presence: true, if: :project validate :validate_parent_is_a_group, if: :parent validate :validate_imported_entity_type @@ -117,8 +118,8 @@ class BulkImports::Entity < ApplicationRecord if source.self_and_descendants.any? { |namespace| namespace.full_path == destination_namespace } errors.add( - :destination_namespace, - s_('BulkImport|destination group cannot be part of the source group tree') + :base, + s_('BulkImport|Import failed: Destination cannot be a subgroup of the source group. Change the destination and try again.') ) end end diff --git a/app/models/bulk_imports/tracker.rb b/app/models/bulk_imports/tracker.rb index 02e0904e1af..182c0bbaa8a 100644 --- a/app/models/bulk_imports/tracker.rb +++ b/app/models/bulk_imports/tracker.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -# This model is responsible for keeping track of the requests/pagination -# happening during a Group Migration (BulkImport). class BulkImports::Tracker < ApplicationRecord self.table_name = 'bulk_import_trackers' @@ -15,4 +13,32 @@ class BulkImports::Tracker < ApplicationRecord uniqueness: { scope: :bulk_import_entity_id } validates :next_page, presence: { if: :has_next_page? } + + validates :stage, presence: true + + state_machine :status, initial: :created do + state :created, value: 0 + state :started, value: 1 + state :finished, value: 2 + state :failed, value: -1 + state :skipped, value: -2 + + event :start do + transition created: :started + end + + event :finish do + transition started: :finished + transition failed: :failed + transition skipped: :skipped + end + + event :skip do + transition any => :skipped + end + + event :fail_op do + transition any => :failed + end + end end |