You are here

function drush_migrate_stop in Migrate 6

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

Stop clearing or importing a given content set.

Parameters

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

File

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

Code

function drush_migrate_stop($content_set = NULL) {
  if (drush_get_option('all')) {
    $all = TRUE;
    if (isset($content_set)) {
      drush_set_error(NULL, dt('You must specify either a content set or --all, not both'));
      return;
    }
  }
  else {
    $all = FALSE;
    if (!isset($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,status FROM {migrate_content_sets}\n                                 WHERE mcsid=%d", $content_set));
    }
    else {
      $row = db_fetch_object(db_query("SELECT mcsid,description,status FROM {migrate_content_sets}\n                                 WHERE LOWER('%s') = LOWER(machine_name)", $content_set));
    }
    $mcsid = $row->mcsid;
    $description = $row->description;
    $status = $row->status;
  }
  if ($all) {
    $sql = "SELECT mcsid,description,status FROM {migrate_content_sets}\n            WHERE status <> %d";
    $result = db_query($sql, MIGRATE_STATUS_IDLE);
    while ($row = db_fetch_object($result)) {
      drush_log(dt('Stopping !type operation on "!description"', array(
        '!type' => $row->status == MIGRATE_STATUS_CLEARING ? 'clearing' : 'importing',
        '!description' => $row->description,
      )));
      db_query("UPDATE {migrate_content_sets} SET status=%d WHERE mcsid=%d", MIGRATE_STATUS_IDLE, $row->mcsid);
    }
  }
  else {
    if ($status != MIGRATE_STATUS_IDLE) {
      drush_log(dt('Stopping !type operation on "!description"', array(
        '!type' => $status == MIGRATE_STATUS_CLEARING ? 'clearing' : 'importing',
        '!description' => $description,
      )));
      db_query("UPDATE {migrate_content_sets} SET status=%d WHERE mcsid=%d", MIGRATE_STATUS_IDLE, $mcsid);
    }
  }
}