You are here

function drush_feeds_import_all in Feeds 7.2

Imports all feeds.

Parameters

string $importer_id: (optional) The importer id to filter on.

File

./feeds.drush.inc, line 448
Drush commands for Feeds module.

Code

function drush_feeds_import_all($importer_id = NULL) {
  if (!($limit = drush_get_option('limit'))) {
    $limit = DRUSH_FEEDS_DEFAULT_LIMIT;
  }

  // Set flag for whether or not executing the batch. When all importers are not
  // not confirmed there are no batches set and in that case there are no
  // batches to process.
  $execute_batch = FALSE;
  foreach (_drush_feeds_get_all($importer_id, $limit) as $feed) {
    if (!isset($feed->source) || !strlen($feed->source)) {
      continue;
    }
    try {
      $source = feeds_source($feed->id, $feed->feed_nid)
        ->existing();
    } catch (FeedsNotExistingException $e) {
      continue;
    }

    // Compose messages.
    $vars = array(
      '@importer_id' => $source->id,
      '@feed_nid' => $source->feed_nid,
    );
    if ($source->feed_nid) {
      $feed_node = node_load($source->feed_nid);
      if ($feed_node) {
        $vars['@title'] = $feed_node->title;
      }
      else {
        drush_set_error(dt('The feed node @feed_nid (@importer_id) does not exist.', $vars));
        continue;
      }
      $confirm_message = dt("Do you want to import items with the importer '@importer_id' for the feed '@title'?", $vars);
      $skip_message = dt("Skipping importer '@importer_id' for feed '@title'.", $vars);
    }
    else {
      $confirm_message = dt("Do you want to import items with the importer '@importer_id'?", $vars);
      $skip_message = dt("Skipping importer '@importer_id'.", $vars);
    }
    if (drush_confirm($confirm_message)) {
      _drush_feeds_create_import_batch($feed->id, $feed->feed_nid);
      $execute_batch = TRUE;
    }
    else {
      drush_log($skip_message, 'ok');
    }
  }
  if ($execute_batch) {
    drush_backend_batch_process();
  }
}