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
Comment #1
osopolarI 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.
Comment #1.0
osopolarJust added a little more information...
Comment #2
bluegeek9 commentedDrupal 7 reached end of life and the D7 version of Feeds is no longer being developed. To keep the issue queue focused on supported versions, we’re closing older D7 issues.
If you still have questions about using Feeds on Drupal 7, feel free to ask. While we won’t fix D7 bugs anymore, we’re happy to offer guidance to help you move forward. You can do so by opening (or reopening) a D7 issue, or by reaching out in the #feeds channel on Drupal Slack.
If this issue is still relevant for Drupal 10+, please open a follow-up issue or merge request with proposed changes. Contributions are always welcome!