summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/project/sample/relation_tree_restorer.rb
blob: 034122a9f142c3f6664eb9e82150ee04ae10883c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module Gitlab
  module ImportExport
    module Project
      module Sample
        class RelationTreeRestorer < ImportExport::Project::RelationTreeRestorer
          def initialize(...)
            super(...)

            @date_calculator = Gitlab::ImportExport::Project::Sample::DateCalculator.new(dates)
          end

          private

          def relation_factory_params(*args)
            super.merge(date_calculator: @date_calculator)
          end

          def dates
            return [] if @relation_reader.legacy?

            RelationFactory::DATE_MODELS.flat_map do |tag|
              @relation_reader.consume_relation(@importable_path, tag, mark_as_consumed: false).map do |model|
                model.first['due_date']
              end
            end
          end
        end
      end
    end
  end
end