Class: DataMigration::ExportsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/data_migration/exports_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/data_migration/exports_controller.rb', line 12

def create
  authorize @migration_plan, :execute?

  # Validate that all required filter parameters are provided
  required_params = extract_placeholders_from_plan

  # Permit the filter_params dynamically based on what's required
  provided_params = if params[:filter_params].present? && required_params.any?
                      params.require(:filter_params).permit(*required_params.keys)
                    else
                      {}
                    end

  missing_params = required_params.keys.select do |param|
    provided_params[param].blank?
  end

  if missing_params.any?
    flash[:alert] = "Please provide values for: #{missing_params.join(', ')}"
    @filter_params = required_params
    render :new and return
  end

  execution = MigrationExecution.create!(
    migration_plan: @migration_plan,
    user: current_user,
    execution_type: :export,
    status: :pending,
    filter_params: provided_params.to_h
  )

  ExportJob.perform_later(execution.id)

  redirect_to "/data_migration/migration_executions/#{execution.id}",
              notice: 'Export started. You will be notified when it completes.'
end

#newObject



7
8
9
10
# File 'app/controllers/data_migration/exports_controller.rb', line 7

def new
  authorize @migration_plan, :execute?
  @filter_params = extract_placeholders_from_plan
end