Feeds actions

I've been working with Feeds a lot lately. Pretty much in every project I am involved with. I am starting to consider it as an essential piece of Drupal infrastructure whenever external data of any nature is required to be pulled in.

During development and testing, one of the recurring tasks is to clear a bunch of feeds, and then re-import them. Instead of doing these operations on each feed, I thought it would be handy to use good old Views Bulk Operations to clear and import feeds in bulk. To this effect, I wrote two very simple Feeds actions that can be added to a node-oriented VBO. I submitted these actions as a sub-module to Feeds, so please try them out and leave your feedback on the issue!

For immediate gratification, here's the code:

<?php
// @file feeds_actions.module

function feeds_actions_action_info() {
  return array(
   
'feeds_action_import' => array(
     
'type' => 'node',
     
'description' => t('Import feed items'),
    ),
   
'feeds_action_delete' => array(
     
'type' => 'node',
     
'description' => t('Delete feed items'),
    ),
  );
}

function
feeds_action_import(&$node, $context) {
  if (
$importer_id = feeds_get_importer_id($node->type)) {
   
feeds_batch_set(t('Importing'), 'import', $importer_id, $node->nid);
  }
}

function
feeds_action_delete(&$node, $context) {
  if (
$importer_id = feeds_get_importer_id($node->type)) {
   
feeds_batch_set(t('Deleting'), 'clear', $importer_id, $node->nid);
  }
}
?>

Comments

This module is now included in Feeds Hacks.

Updated to the latest version of Feeds.

We had the same requirements and wrote similar code but didn't post to the project.

Wondering if we should still do that.

If the code is similar you can always enhance or just +1 the patch that I submitted.