You are here

function drush_migrate_validate_common in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 migrate.drush.inc \drush_migrate_validate_common()
9 calls to drush_migrate_validate_common()
drush_migrate_analyze_validate in ./migrate.drush.inc
drush_migrate_audit_validate in ./migrate.drush.inc
drush_migrate_fields_destination_validate in ./migrate.drush.inc
drush_migrate_fields_source_validate in ./migrate.drush.inc
drush_migrate_import_validate in ./migrate.drush.inc

... See full list

File

./migrate.drush.inc, line 957
Drush support for the migrate module

Code

function drush_migrate_validate_common($args) {

  // Let's load user 1, seems to be needed for creating path aliases and deleting content.
  global $user;
  $user_one = user_load(array(
    'uid' => '1',
  ));
  $user = $user_one;
  session_save_session(FALSE);
  if (drush_get_option('all')) {
    if (!empty($args) || drush_get_option('group')) {
      return drush_set_error(NULL, dt('You must specify exactly one of a migration name, --all, or --group'));
    }
  }
  elseif (drush_get_option('group')) {
    if (!empty($args) || drush_get_option('all')) {
      return drush_set_error(NULL, dt('You must specify exactly one of a migration name, --all, or --group'));
    }
  }
  else {
    if (empty($args)) {
      return drush_set_error(NULL, dt('You must specify exactly one of a migration name, --all, or --group'));
    }
    $machine_names = explode(',', $args);
    foreach ($machine_names as $machine_name) {
      $machine_name = trim($machine_name);
      $class_name = db_select('migrate_status', 'ms')
        ->fields('ms', array(
        'class_name',
      ))
        ->condition('machine_name', $machine_name)
        ->execute()
        ->fetchField();
      if (!$class_name || !class_exists($class_name)) {
        drush_set_error(dt('Unrecognized migration: !name', array(
          '!name' => $machine_name,
        )));
      }
    }
  }
  $feedback = drush_get_option('feedback');
  if ($feedback) {
    $parts = explode(' ', $feedback);
    $options['feedback']['value'] = $parts[0];
    $options['feedback']['unit'] = $parts[1];
    if ($options['feedback']['unit'] != 'seconds' && $options['feedback']['unit'] != 'second' && $options['feedback']['unit'] != 'items' && $options['feedback']['unit'] != 'item') {
      drush_set_error(NULL, dt("Invalid feedback frequency unit '!unit'", array(
        '!unit' => $options['feedback']['unit'],
      )));
      return;
    }
  }
}