Problem/Motivation

When you want to import content for multiple feeds, it would be handy to be able to select the feeds you want to import content for at admin/content/feed and apply an action to them to trigger an import for them all.

Proposed resolution

An action plugin and a kernel test that covers the action plugin should be written.

The action plugin

Add a file to src/Plugin/Action and implement an action plugin that triggers the batch import for every feed that is passed to the action plugin.
The action plugin should call startBatchImport() on the feed.

The kernel test

The kernel test could be written as follows:

  1. Create feed type. I think using the parser "syndication" (for parsing RSS feeds) is the easiest for this test.
  2. Create two feeds: one for which drupalplanet.rss2 is selected as a source and another whose source is googlenewstz.rss2. These RSS feeds are found in tests/resources/rss.
  3. Apply the action plugin.
  4. Assert that content for both feeds was imported.

Remaining tasks

  1. Write an action plugin
  2. Write a kernel test that covers the action plugin

User interface changes

New entry in the 'With selection' dropdown menu:

Original report by SocialNicheGuru

On admin/content/feed, I only have the option to delete feeds.

Is there a way to bulk import feeds or to update them all?

Issue fork feeds-3049631

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

SocialNicheGuru created an issue. See original summary.

megachriz’s picture

Title: Is there a way to bulk import feeds? » Add an action to bulk import feeds
Category: Support request » Feature request

No, not yet without custom code.

With custom code, you would load each feed you want to update and then call either startBatchImport() (to import using the UI) or startCronImport() (to import during cron runs). For small feeds you can also call import() on it, which performs the whole import in one go.

use Drupal\feeds\Entity\Feed;

// Load feeds 2, 5 and 7.
$feeds = Feed::loadMultiple([2, 5, 7]);

// Import in background.
foreach ($feeds as $feed) {
  $feed->startCronImport();
}

Note that when using cron to import, imports would run kinda simultaneously. So the import for the second feed starts before the import for the first feed is completed (unless the first feed only has one item to import).
I'm not sure if this also the case for the batch import. I think in this case, the imports would run after each other.

megachriz’s picture

Issue summary: View changes

I've expanded the issue summary a bit, so it hopefully becomes more clear for contributors on how to work on this issue.

megachriz’s picture

Assigned: Unassigned » megachriz

I've got #3165187: Add an action to bulk delete imported items ready for review. I plan to pick this one up as well now, and base it on the code introduced by the other issue.

megachriz’s picture

Status: Active » Needs review

This is ready for review.

  • MegaChriz committed 5fceea18 on 8.x-3.x
    Issue #3049631 by MegaChriz: Added an action to bulk import feeds.
    
megachriz’s picture

Status: Needs review » Fixed

I merged the code!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

kopeboy’s picture

Great! Thank you @MegaCriz !!

kopeboy’s picture

Is it possible to add the "Import in background" action as well?

megachriz’s picture

@kopeboy
I had thought about that, but the issue is then that the order in which imports run could feel a bit random. When you would start multiple background imports at once, these imports are kinda run in parallel. This is namely how that would work:

  1. Import feed 1 planned.
  2. Import feed 2 planned.
  3. First chunk of feed 1 gets imported.
  4. First chunk of feed 2 gets imported.
  5. Second chunk of feed 1 gets imported.
  6. Second chunk of feed 2 gets imported.

and so forth. So this is not pure in "parallel", but imports for multiple feeds alternate.

The chunks can also differ in size. So maybe the import for feed 1 takes more time to process, so a single chunck for that could be 50 items on average, while for feed 2 it could be 150 items on average per chunk.

But of course we could "fix" all this with a message "Background imports run in parallel" or something similar.

Do you want to create a new issue for this, @kopeboy?