You are here

function migrate_ui_dashboard_submit in Migrate 6.2

Submit callback for the dashboard form.

1 string reference to 'migrate_ui_dashboard_submit'
_migrate_ui_dashboard_form in migrate_ui/migrate_ui.pages.inc
Form for reviewing migrations.

File

migrate_ui/migrate_ui.pages.inc, line 238

Code

function migrate_ui_dashboard_submit($form, &$form_state) {
  $operation = $form_state['values']['operation'];
  $limit = $form_state['values']['limit'];
  $update = $form_state['values']['update'];
  $force = $form_state['values']['force'];
  $machine_names = array_filter($form_state['values']['dashboard']);
  $operations = array();

  // Rollback in reverse order.
  if (in_array($operation, array(
    'rollback',
    'rollback_and_import',
  ))) {
    $machine_names = array_reverse($machine_names);
    foreach ($machine_names as $machine_name) {
      $operations[] = array(
        'migrate_ui_batch',
        array(
          'rollback',
          $machine_name,
          $limit,
          $force,
        ),
      );
    }

    // Reset order of machines names in preparation for final operation.
    $machine_names = array_reverse($machine_names);
    $operation = $operation == 'rollback_and_import' ? 'import' : NULL;
  }

  // Perform non-rollback operation, if one exists.
  if ($operation) {
    foreach ($machine_names as $machine_name) {
      $migration = Migration::getInstance($machine_name);
      switch ($operation) {
        case 'import':

          // Update (if necessary) once, before starting
          if ($update && method_exists($migration, 'prepareUpdate')) {
            $migration
              ->prepareUpdate();
          }
          $operations[] = array(
            'migrate_ui_batch',
            array(
              $operation,
              $machine_name,
              $limit,
              $force,
            ),
          );
          break;
        case 'stop':
          $migration
            ->stopProcess();
          break;
        case 'reset':
          $migration
            ->resetStatus();
          break;
      }
    }
  }

  // Only rollback and import operations will need to go through Batch API.
  if (count($operations) > 0) {
    $batch = array(
      'operations' => $operations,
      'title' => t('Migration processing'),
      'file' => drupal_get_path('module', 'migrate_ui') . '/migrate_ui.pages.inc',
      'init_message' => t('Starting migration process'),
      'progress_message' => t(''),
      'error_message' => t('An error occurred. Some or all of the migrate processing has failed.'),
      'finished' => 'migrate_ui_batch_finish',
    );
    batch_set($batch);
  }
}