You are here

function drush_migrate_clear in Migrate 6

Clear one specified content set

Parameters

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

File

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

Code

function drush_migrate_clear($content_set = NULL) {

  // node_delete() has silly perm requirements in d5/d6.
  drush_set_option('user', 1);
  drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_LOGIN);
  drush_migrate_set_verbose();
  if (drush_get_option('all')) {
    $all = TRUE;
    if (isset($content_set)) {
      drush_log(dt('You must specify either a content set or --all, not both'), 'warning');
      return;
    }
  }
  else {
    $all = FALSE;
    if (!$content_set) {
      drush_log(dt('You must specify either a content set or the --all option'), 'warning');
      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 DESC";
    $result = db_query($sql);
    while ($row = db_fetch_object($result)) {
      _drush_migrate_do_clear($row->mcsid, $row->description, $options);
    }
  }
  else {
    _drush_migrate_do_clear($mcsid, $description, $options);
  }
}