1

I currently use Feed-Me to pull data from an API-Endpoint. This API-Endpoint does change from time to time, providing new elements with each change.

I don't want to manually trigger the Feed-Me-Reimport each time I notice a change. I do know that Feed-Me provides actions URLs for each feed-entry but as the amount of different import-feeds will grow rapidly soon, I don't think it's feasable to manually create those feeds, and after creation also manually put the URL into a custom cronjob.

So in the end what I'd like to have is simply a script that is triggered by a single cronjob, then gets all Feed-Me feeds and for each feed run the reimport.

Via PluginFactory I already generated a plugin that provides me an endpoint(/controller) to be called by cron

public function actionAutoImport()
    {
        $result = 'Autoimport engaged';

        return $result;
    }

But now I am wondering: How do I get information from the Feed-Me plugin i.e. get all existing feeds and trigger a run on each?

2

You should be able to use something similar to the following:

use Craft;
use verbb\feedme\FeedMe;
use verbb\feedme\queue\jobs\FeedImport;

$feeds = FeedMe::$plugin->feeds->getFeeds();

foreach ($feeds as $feed) {
    $limit = null;
    $offset = null;
    $processedElementIds = [];

    Craft::$app->getQueue()->delay(0)->push(new FeedImport([
        'feed' => $feed,
        'limit' => $limit,
        'offset' => $offset,
        'processedElementIds' => $processedElementIds,
    ]));
}

The above will add all your feeds to Craft's queue system and start them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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