Thanks for the excellent module, and hopefully this question is an easy one...

I've have two feeds which HAVE to be imported in the right order, i.e. feed1 first, feed2 second, because there are entity-reference relationships between them. To further complicate things, we must delete all the imported data before re-importing. For this reason I don't think I can use the standard expire / import CRON options already provided.

To work around this, I setup a custom CRON job which used DrupalQueue to queue the importers. The code that does the import is here: -

<?php
function _example_import_feed($feed_id, &$context = array()) {
  $feed_source = feeds_source($feed_id);
  // add the source URL to the config
  $source_config = $feed_source->getConfig();
  $feed_url = "http://example.xml";
  $source_config['FeedsHTTPFetcher']['source'] = $feed_url;
  // process the feed (delete and import)
  $feed_source->setConfig($source_config);
  $feed_source->save();
  $feed_source->startClear();
  $feed_source->startImport();
  $feed_source->schedule();
  // get the feed name and pass to status messages
  $feed = feeds_importer($feed_id);
  $config = $feed->getConfig();
  $feed_name = $config['name'];
  $context['results'][] = check_plain($feed_name);
  $context['message'] = t('Processing feed "@title"', array('@title' => $feed_name));
  watchdog("example", t('Processed feed "@title"', array('@title' => $feed_name)));
}
?>

I also call feeds_reschedule(TRUE); in the actual CRON hook.

This imports the content just fine, and in the right order, but it DOESN'T delete the old content first. The ->startClear() is just ignored.

How can I get the startClear() to run from a DrupalQueue?

I should point out that the same function above can be called manually using BatchAPI and in this case it deletes fine - it's just when it's called with DrupalQueue.

Thanks,

Dubs

Comments

osopolar’s picture

I guess the import is working, because it's done via the schedule as background job. startClear in your case maybe uses the batch-API. Using the batch API requires to call batch_process if its not invoked via FormAPI. See related issue #1553190: data not import during cron run #34.

osopolar’s picture

Issue summary: View changes

Just added a little more information...