Class: DataMigration::ImportsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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
# File 'app/controllers/data_migration/imports_controller.rb', line 13

def create
  authorize @migration_plan, :execute?

  unless params[:archive_file].present?
    redirect_to "/data_migration/migration_plans/#{@migration_plan.id}/import/new",
                alert: 'Please select a file to upload.'
    return
  end

  uploaded_file = params[:archive_file]

  # Save uploaded file to tmp directory
  file_path = save_uploaded_file(uploaded_file)

  # Use provided filter params or default to empty hash
  filter_params = params[:filter_params].present? ? params[:filter_params] : {}

  execution = MigrationExecution.create!(
    migration_plan: @migration_plan,
    user: current_user,
    execution_type: :import,
    status: :pending,
    file_path: file_path,
    filter_params: filter_params
  )

  ImportJob.perform_later(execution.id)

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

#newObject



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

def new
  authorize @migration_plan, :execute?
  @filter_params = extract_placeholders_from_plan
  @last_export = @migration_plan.migration_executions.export_type.completed.order(created_at: :desc).first
end