Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Can I restrict the number of feed items imported, for example:
- By number, eg. the latest 20
- By date, eg. Not older than 20 days
Comments
Comment #1
luckysmack CreditAttribution: luckysmack commentedSubscribing, i'd like to know the same thing as well. I see no options to choose how many items are pulled when the feed is aggregated. An option for this would be great.
Comment #2
tfranz CreditAttribution: tfranz commentedJust a hint: I had quite a similar problem and solved it this way:
Added some code in "FeedsNodeProcessor.inc", rows 23ff:
Hope it helps somebody ... at least it works for me ... :-)
Comment #3
mlmoseley CreditAttribution: mlmoseley commentedAfter much reading through the code , I solved this problem by changing one line. In feeds-6.x-1.0-beta13, in:
feeds/plugins/FeedsNodeProcessor.inc
On or about line 25, there's a function called:
public function process(FeedsImportBatch $batch, FeedsSource $source)
That function uses the variable '$batch_size', which is the number of nodes to import, as set in settings.php with this statement:
$conf['feeds_node_batch_size'] = 10;
At this point in the code, the function is looping through an array of fifty feed items, and creating nodes from them. Note: the array of feed items already exist. At the bottom of the loop the code compares $batch_size to $processed (the number of nodes processed) and provides an IF statement saying what to do if the $batch_size is equal to or greater than the number processes. In other words, when the loop has hit the limit. Here's the IF statement.
In this context 'return' is supposed to end the execution of the function, but it doesn't. It seems to just end the current iteration of the 'while' loop in which it resides. I replaced 'return' with 'break', and suddenly the node limit in settings.php worked.
This solved my problem because I needed fewer than fifty items. I don't know what would happen if you set the limit to more than fifty.
I would REALLY like to not hack a module. Really. But I just couldn't find any other solution to this.
--Marshall
Comment #4
MegaChriz CreditAttribution: MegaChriz commentedLimiting the number of items to import can be done easily by implementing
hook_feeds_after_parse()
. Via that hook all items to import are passed, so you can simply loop through them and unset the items you don't want to import.Example for Feeds 6.x-1.x:
Example for Feeds 7.x-2.x:
For skipping items that contain a certain phrase, you can also use the Keyword filter plugin from Feeds Tamper.
For skipping items that are older than a certain date, see #2453845: Limit updating items to x days.
Comment #6
sbydrupal CreditAttribution: sbydrupal commentedCan you please comment on #10 at https://www.drupal.org/node/1909974 whether it is possible to
solve ? I don't want to replicate same comment in this thread. Thanks
Comment #7
arne.olafson CreditAttribution: arne.olafson commentedI created a project for this here: https://www.drupal.org/project/single_feeds