I'm using the following code to dynamically load an already existing Feeds source for a CSV importer, change the default file location, and make it start importing nodes.

The hard part for me was to figure out how to change the default file name/location of the importer.

  $myFeed = feeds_source('geocache_importer');
  $config = array('FeedsFileFetcher'=>array('source'=>'sites/default/files/' . $file));
  $myFeed->addConfig($config);
  while (FEEDS_BATCH_COMPLETE != $myFeed->import());

I know it's asking a lot, but adding setter methods would make the Feeds class a lot more user friendly. It took a print_r() and some trial and error before I figured out how to set the config array parameter, and if you make any code changes, my code may break.

Somethings like the setter below would make it easier for user to figure out how to affect the feed source class, and would also make the user's code insensitive to any changes you make to the class's underlying implementation:

feeds_source->setFetcherSource()

Just a thought :)

Comments

alex_b’s picture

Good feature request. This crease has been on my mind for a while.

The basic problem is this: The user of the API has to have some knowledge of which fetcher is in use in the first place, as a fetcher could have very specific requirements on what to configure in order for fetching to be successful. However, we do have the assumption that every fetcher can condense their source into a single string (see feeds_source table) - which we use for instance for determining whether a specific source is already present when importing from OPML.

So to make the story short: I would welcome a setFetcherSource() that sets the common source key for fetchers. We should also document the special role of the 'source' key better.

twistor’s picture

Version: 6.x-1.0-alpha12 » 6.x-1.x-dev
Issue summary: View changes

This is still a good idea.

twistor’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev