You are here

function migrate_ui_configure_form in Migrate 7.2

Form for reviewing migrations.

1 string reference to 'migrate_ui_configure_form'
migrate_ui_configure in migrate_ui/migrate_ui.pages.inc
Menu callback

File

migrate_ui/migrate_ui.pages.inc, line 1742
Pages for managing migration processes.

Code

function migrate_ui_configure_form($form, &$form_state) {
  $build = array();
  $description = t('To register (or reregister with updated arguments) any
    migrations defined in hook_migrate_api(), click the <strong>Register</strong>
    button below.');
  $build['registration'] = array(
    '#type' => 'fieldset',
    '#title' => t('Registration'),
    '#description' => $description,
  );
  $build['registration']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Register statically defined classes'),
    '#submit' => array(
      'migrate_ui_configure_register_submit',
    ),
  );
  $migrations = array();
  $result = db_select('migrate_status', 'ms')
    ->fields('ms', array(
    'class_name',
    'machine_name',
  ))
    ->execute();
  $migration_list = '';
  foreach ($result as $row) {
    if (!class_exists($row->class_name)) {
      $migrations[] = $row->machine_name;
      $migration_list .= '<li>' . t('!migration (class !class)', array(
        '!migration' => filter_xss_admin($row->machine_name),
        '!class' => filter_xss_admin($row->class_name),
      )) . "</li>\n";
    }
  }
  if (!empty($migrations)) {
    $description = t('No class currently exists for the following migrations: <ul>!list</ul>', array(
      '!list' => $migration_list,
    ));
    $build['deregistration'] = array(
      '#type' => 'fieldset',
      '#title' => t('Orphaned migration tasks'),
      '#description' => $description,
    );
    $build['deregistration']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Deregister orphans'),
      '#submit' => array(
        'migrate_ui_configure_deregister_submit',
      ),
    );
  }
  $build['settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Settings'),
  );
  $build['settings']['deprecation_warnings'] = array(
    '#type' => 'checkbox',
    '#title' => t('Warn on usage of deprecated patterns'),
    '#default_value' => variable_get('migrate_deprecation_warnings', 1),
    '#description' => t('When checked, you will receive warnings when using methods and patterns that are deprecated as of Migrate 2.6.'),
  );
  $build['settings']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save settings'),
    '#submit' => array(
      'migrate_ui_configure_settings_submit',
    ),
  );

  // Configure background imports if the drush command has been set.
  $drush_path = trim(variable_get('migrate_drush_path', ''));
  $drush_validated = FALSE;
  if ($drush_path && is_executable($drush_path)) {

    // Try running a drush status command to verify it's properly configured.
    $uri = $GLOBALS['base_url'];
    $uid = $GLOBALS['user']->uid;

    // If on Acquia, call required shell script to add environment variables.
    $command = isset($_ENV['AH_SITE_ENVIRONMENT']) ? "/mnt/users/{$_ENV['AH_SITE_GROUP']}/{$_ENV['AH_SITE_ENVIRONMENT']}.shell " : '';
    $command .= "{$drush_path} status --user={$uid} --uri={$uri} --root=" . DRUPAL_ROOT;
    exec($command, $output, $status);
    if ($status == 0) {
      $version = '';
      foreach ($output as $line) {
        if (preg_match('|Drush version +: +(.*)|', $line, $matches)) {
          $version = trim($matches[1]);
        }
        elseif (preg_match('|Drupal bootstrap +: +Successful *|', $line, $matches)) {
          $drush_validated = TRUE;
        }
      }
    }
    if ($drush_validated) {
      $description = t('Configure the use of <a href="@drush">drush</a> version @version to run import and rollback operations in the background.', array(
        '@drush' => 'http://drupal.org/project/drush',
        '@version' => $version,
      ));
    }
    else {
      $description = t('<a href="@drush">Drush</a> is misconfigured on the server. Please review the <a href="@config">documentation</a> on <a href="@dorg">drupal.org</a>, and make sure everything is set up correctly.', array(
        '@drush' => 'http://drupal.org/project/drush',
        '@config' => 'http://drupal.org/node/1958170',
      ));
    }
  }
  else {
    $description = t('To enable running operations in the background with <a href="@drush">drush</a>, (which is <a href="@recommended">recommended</a>), some configuration must be done on the server. See the <a href="@config">documentation</a> on <a href="@dorg">drupal.org</a>.', array(
      '@drush' => 'http://drupal.org/project/drush',
      '@recommended' => 'http://drupal.org/node/1806824',
      '@config' => 'http://drupal.org/node/1958170',
      '@dorg' => 'http://drupal.org/',
    ));
  }
  $build['drush'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#title' => t('Background operations'),
    '#description' => $description,
  );
  if ($drush_validated) {
    $options = array(
      0 => t('Immediate operation only'),
      1 => t('Background operation only'),
      2 => t('Allows both immediate and background operations'),
    );
    $build['drush']['migrate_import_method'] = array(
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => variable_get('migrate_import_method', 0),
      '#title' => t('Import method'),
      '#description' => t('Choose whether the dashboard will perform operations immediately, in the background via drush, or offer a choice.'),
    );
    $build['drush']['migrate_drush_mail'] = array(
      '#type' => 'checkbox',
      '#default_value' => variable_get('migrate_drush_mail', 0),
      '#title' => t('Send email notification when a background operation completes.'),
    );
    $build['drush']['migrate_drush_mail_subject'] = array(
      '#type' => 'textfield',
      '#default_value' => variable_get('migrate_drush_mail_subject', t('Migration operation completed')),
      '#title' => t('Subject'),
      '#states' => array(
        'visible' => array(
          ':input[name="migrate_drush_mail"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $build['drush']['migrate_drush_mail_body'] = array(
      '#type' => 'textarea',
      '#rows' => 10,
      '#default_value' => variable_get('migrate_drush_mail_body', t('The migration operation is complete. Please review the results on your dashboard')),
      '#title' => t('Body'),
      '#states' => array(
        'visible' => array(
          ':input[name="migrate_drush_mail"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $build['drush']['save_drush_config'] = array(
      '#type' => 'submit',
      '#value' => t('Save background configuration'),
      '#submit' => array(
        'migrate_ui_configure_drush_submit',
      ),
    );
  }
  $build['handlers'] = array(
    '#type' => 'fieldset',
    '#title' => t('Handlers'),
    '#description' => t('In some cases, such as when a field handler for a contributed module is implemented in both migrate_extras and the module itself, you may need to disable a particular handler. In this case, you may uncheck the undesired handler below.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $build['handlers']['destination'] = array(
    '#type' => 'fieldset',
    '#title' => t('Destination handlers'),
    '#collapsible' => TRUE,
  );
  $header = array(
    'module' => array(
      'data' => t('Module'),
    ),
    'class' => array(
      'data' => t('Class'),
    ),
    'types' => array(
      'data' => t('Destination types handled'),
    ),
  );
  $disabled = unserialize(variable_get('migrate_disabled_handlers', serialize(array())));
  $class_list = _migrate_class_list('MigrateDestinationHandler');
  $rows = array();
  $default_values = array();
  foreach ($class_list as $class_name => $handler) {
    $row = array();
    $module = db_select('registry', 'r')
      ->fields('r', array(
      'module',
    ))
      ->condition('name', $class_name)
      ->condition('type', 'class')
      ->execute()
      ->fetchField();
    $row['module'] = check_plain($module);
    $row['class'] = check_plain($class_name);
    $row['types'] = filter_xss_admin(implode(', ', $handler
      ->getTypesHandled()));
    $default_values[$class_name] = !in_array($class_name, $disabled);
    $rows[$class_name] = $row;
  }
  $build['handlers']['destination']['destination_handlers'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#default_value' => $default_values,
    '#empty' => t('No destination handlers found'),
  );
  $build['handlers']['field'] = array(
    '#type' => 'fieldset',
    '#title' => t('Field handlers'),
    '#collapsible' => TRUE,
  );
  $header = array(
    'module' => array(
      'data' => t('Module'),
    ),
    'class' => array(
      'data' => t('Class'),
    ),
    'types' => array(
      'data' => t('Field types handled'),
    ),
  );
  $class_list = _migrate_class_list('MigrateFieldHandler');
  $rows = array();
  $default_values = array();
  foreach ($class_list as $class_name => $handler) {
    $row = array();
    $module = db_select('registry', 'r')
      ->fields('r', array(
      'module',
    ))
      ->condition('name', $class_name)
      ->condition('type', 'class')
      ->execute()
      ->fetchField();
    $row['module'] = check_plain($module);
    $row['class'] = check_plain($class_name);
    $row['types'] = filter_xss_admin(implode(', ', $handler
      ->getTypesHandled()));
    $default_values[$class_name] = !in_array($class_name, $disabled);
    $rows[$class_name] = $row;
  }
  $build['handlers']['field']['field_handlers'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#default_value' => $default_values,
    '#empty' => t('No field handlers found'),
  );
  $build['handlers']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save handler statuses'),
    '#submit' => array(
      'migrate_ui_configure_submit',
    ),
  );
  return $build;
}