Hi,
I am working on a new project that heavily relies on feeds. Currently I import using a json parser and create new "Video Asset" Nodes (Works great). I have another Feeds Importer (Asset Social Stats) attached to the "Video Asset" nodes, and the feeds url is dynamically populated using feeds tamper (Also works great!).

Now if I visit each "Video Asset" node I can click the "Import" tab, and then the "Import" button, and it works fine (Using Feeds Node Self Processor). Populating all fields as expected.

My problem is making the import hands free. Ideally I would like to trigger the import on a specific node using rules.
(Example: Event = When Content Is Viewed, Condition = Last Updated More Than 24hrs Ago, Action = Import Feed Attached To %Nid).

However I can't seem to find an action to import anywhere in rules. I have searched high and low through the forums and google.

Any suggestions? THank you!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

2ndChanceTech’s picture

Status: Active » Closed (fixed)

Looks like I'm closer to getting this to work, unfortunately it will be done using PHP in rules (Not my preferred method). If someone has another suggestion not needing php in rules, please advise.

I found this in the Feeds Developers guide, but know nearly nothing about PHP, so not sure how to implement it....

// Using Batch API (user will see a progress bar).
feeds_batch_set(t('Importing'), 'import', 'my_importer_id', $node->nid);
// Not using Batch API (complete import within current page load)
while (FEEDS_BATCH_COMPLETE != feeds_source('my_importer_id', $node->nid)->import());

I replaced "my_importer_id" with the machine name of my importer and "nid" with the rules replacement pattern. but can't seem to get it to trigger.

2ndChanceTech’s picture

Status: Closed (fixed) » Active

Accidentally closed thinking I had figured it out... Re-opening...

MegaChriz’s picture

Category: Support request » Feature request
Status: Active » Needs review
Issue tags: +rules
Related issues: +#713122: Rules Integration / Working with the feeds field
FileSize
1.8 KB

I have been playing with this as well, see the attached patch. The patch adds a Rules action "Execute feeds importer" which will trigger the import of a source. The problem with this solution is that you have to go trough the import form at least once, otherwise Feeds doesn't know from which source you want to import. (I do not remember how I came to the code in feeds_action_import_feed(), I made this more than a year ago.)

There is also a huge patch about Rules integration in the following issue:
#713122: Rules Integration / Working with the feeds field
I haven't tested that one, but it is at least related.

liquidcms’s picture

Works great. Thanks MegaChriz.

g33kg1rl’s picture

This patch applied with offset -3 and none of the options are showing up with I select the execute feeds option. Can chance this can be rerolled for the latest version?

MegaChriz’s picture

This patch uses a different approach for implementing this feature. Compared to the patch in #3, the advantages are the following:

  • It respects the "Process in background" option. This means that when the rules action is executed, the import will be queued instead of that the import happens immediately. Further import will happen on cron runs.
  • It also can work with importers that are attached to a content type.

Also added three automated tests:

  • Test action when importer is attached to a content type.
  • Test action when importer is using the standalone form.
  • Test action when importer has the "Process in background" option enabled.
g33kg1rl’s picture

Thanks for the new patch MegaChriz. It works for me! :D

firfin’s picture

@Megachriz, thanks so much for taking a stab at this!
Still applies to latest dev without issue. And there is an action available to run an importer. Dropdown list to select feeds importer works. Unfortunately feeds_node is also a required field? I am using a standalone importer, so really do not have a clue what to put into this field?

MegaChriz’s picture

I thought I had already committed this one ages ago! I'll schedule to look at this one again. Hopefully I can do that somewhere this month, cause anything Feeds D8 related has first priority.

@firfin
You can use the action for importers using a standalone form as well. For importers *not* attached to a content type, the feed nid is always 0, so I suppose putting in a zero should work. Suggestions (patches) for improvements are welcome. Ideally, you wouldn't see the Feed node field for importers using a standalone form.

MegaChriz’s picture

Coding standards. Also added a description to the "Feed node" parameter that a 0 must be provided if the importer is not attached to a content type.

  • MegaChriz committed 21e3fc5 on 7.x-2.x
    Issue #2446307 by MegaChriz: Added rules feeds import action.
    
MegaChriz’s picture

Status: Needs review » Fixed

Committed #10.

firfin’s picture

Still works. And yes, using a 0 as feed node id works indeed.
Quick pick up on this BTW, seeing as how busy you are with D8.

Status: Fixed » Closed (fixed)

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

tboggia’s picture

Struggling a bit with this. I have the Rule set up to "Execute feeds importer", but I cannot set any of the parameters at all, let alone set them based on what node triggered the rules. What I'm trying to do is:

What works:

  1. Use an importer to regularly import the Object ID and Version of a list of hundreds of courses, but only update the course nodes if the Version field is different.
  2. Use Rules to trigger an action whenever a Course is updated.
  3. Make that action a Feed Import using the getCourse web service that requires an Object Id parameter to pull the full info for the course that needs updating

What doesn't work:

  1. Setting the parameter on the Feed import based on what course was updated

Thoughts on how I can make this work?

kopeboy’s picture

Is any of this supported in Drupal 8/9?