1

I have three importers set up and working fine; all creating nodes from an XML file using HTTP fetcher.

The created nodes reference each other (using Node Reference), so the importers must run in a certain order.

To automate this, I'm not using the periodic import option as it won't keep things in sync. Instead, I created a simple Rules action:

<?php
function my_import_action_import($importer_name, $feeds_node) {
  while (FEEDS_BATCH_COMPLETE != feeds_source($importer_name, $feeds_node)->import());
}
?>

Then I created a rule that runs on cron with three actions (one to trigger each importer).

As far as I can tell, it seems to work. But I get a warning notice that doesn't happen when I run the importers manually:

Notice: Undefined offset: 2 in references_feeds_set_target() (line 203 of /home/mysites/drupal7/sites/default/modules/references/references.feeds.inc).

I also have a feeling that Feeds was meant to use job scheduler for a reason, and not run on cron in this way?

Thanks!

1 Answer 1

5

I had almost the exact same need where I had to import data from xml files usinf HTTP fetcher. I had 5 importers and had to run one after the other.

I declared a function that triggered the importers programmatically one after the other.

For triggering each importer this is what I did -

$feeds_source = feeds_source($importer_id);
$feeds_config = $feeds_source->getConfigFor($feeds_source->importer->fetcher);
$feeds_config['source'] = $url;
$feeds_source->setConfigFor($feeds_source->importer->fetcher, $feeds_config);
$feeds_source->save();
$feeds_source->startImport();

where $importer_id is the machine name of the importer; you can find it in the table 'feeds_source' and $url is the url where you have your xml file. feeds_source()

And there's this awesome cron module - Elysia Cron which gives in its own words 'a fine grain control over each task and several ways to add custom cron jobs to your site'.

With Elysia's hook_cronapi() you can set up a cron job which calls your function at your set up intervals.

Though it seems really a long since your question.....I hope this is of some help.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.