You are here

function drush_migrate_import in Migrate 6

Same name and namespace in other branches
  1. 6.2 migrate.drush.inc \drush_migrate_import()
  2. 7.2 migrate.drush.inc \drush_migrate_import()

Import one specified content set

Parameters

$content_set: The mcsid or the name of the content set

File

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

Code

function drush_migrate_import($content_set = NULL) {
  drush_migrate_set_verbose();
  if (drush_get_option('all')) {
    $all = TRUE;
    if ($content_set) {
      drush_set_error(NULL, dt('You must specify either a content set or --all, not both'));
      return;
    }
  }
  else {
    $all = FALSE;
    if (!$content_set) {
      drush_set_error(NULL, dt('You must specify either a content set or the -all option'));
      return;
    }
    if (is_numeric($content_set)) {
      $row = db_fetch_object(db_query("SELECT mcsid,description FROM {migrate_content_sets}\n                                 WHERE mcsid=%d", $content_set));
    }
    else {
      $row = db_fetch_object(db_query("SELECT mcsid,description FROM {migrate_content_sets}\n                                 WHERE LOWER('%s') = LOWER(machine_name)", $content_set));
    }
    $mcsid = $row->mcsid;
    $description = $row->description;
  }
  $options = array();
  if ($idlist = drush_get_option('idlist', FALSE)) {
    $options['idlist'] = $idlist;
  }
  if ($itemlimit = drush_get_option('itemlimit', FALSE)) {
    $options['itemlimit'] = $itemlimit;
  }
  $options['feedback'] = array(
    'function' => 'drush_log',
  );
  $feedback = drush_get_option('feedback');
  if ($feedback) {
    $parts = explode(' ', $feedback);
    $options['feedback']['frequency'] = $parts[0];
    $options['feedback']['frequency_unit'] = $parts[1];
    if ($options['feedback']['frequency_unit'] != 'seconds' && $options['feedback']['frequency_unit'] != 'items') {
      drush_set_error(NULL, dt("Invalid feedback frequency unit '!unit'", array(
        '!unit' => $options['feedback']['frequency_unit'],
      )));
      return;
    }
  }
  if ($all) {
    $sql = "SELECT mcsid,description FROM {migrate_content_sets} ORDER BY weight";
    $result = db_query($sql);
    while ($row = db_fetch_object($result)) {
      _drush_migrate_do_import($row->mcsid, $row->description, $options);
    }
  }
  else {
    _drush_migrate_do_import($mcsid, $description, $options);
  }
}