I'm trying to create an extra processor for the feedapi. I want to do some changes to how the unique operation is being handled. I've had a look at this example: http://groups.drupal.org/node/19719 but it doesn't say how to register the processor so it is being run.

When looking at the feedapi_node.module file it is implementing hook_feedapi_settings_form(). I don't understand how this should be implemented in my module to allow it to make the changes I'm trying to do.

This is my module code thus far:

/**
 * Implementation of hook_feedapi_item()
 *
 */
function prevent_dupe_feedapi_item($op) {
  dsm("in dupe hook"); // This never shows up so that means this is never being called
  switch ($op) {
    case 'type':
      return array("XML feed");
    case 'save':
      break;
    case 'expire':
      break;
    case 'update':
      break;
    case 'delete':
      break;
    case 'purge':
      break;
    case 'unique':
      watchdog('prevent_dupe', 'In unique');
      $args = array_slice(func_get_args(), 1);
      return call_user_func_array('_prevent_dupe_unique', $args);
    default:
      if (function_exists('_feedapi_node_'. $op)) {
        $args = array_slice(func_get_args(), 1);
        return call_user_func_array('_feedapi_node_'. $op, $args);
      }
  }
}

/**
 * Tell if the feed item was seen before or not at the feed
 *
 * @param $feed_item
 *  Feed item object
 * @param $feed_nid
 *  Feed ID
 * @return
 *  TRUE if the item is new, FALSE if the item is a duplicated one
 */
function _prevent_dupe_unique($feed_item, $feed_nid, $settings) {
  $cleartext = $feed_item->title;
  $cleartext .= $feed_nid;
  
  $hash = md5($cleartext);
      
  $result = db_result(db_query("SELECT id FROM {prevent_dupe} WHERE hash='%s' LIMIT 1", $hash));
  // There was already an existing hash, prevent saving
  if($result > 0) {
    watchdog('prevent_dupe', 'Tried to create a node but was denied because a duplicate with the title ('.$feed_item->title.') from the feed with feed id: '.$feed_nid.' has already been created');
    return FALSE;
  }
  // No hash found, go along and save the node and the hash
  else {
    watchdog('prevent_dupe', 'Successfully created a node with the title: '.$feed_item->title.'');
    $insert = db_query("INSERT INTO {prevent_dupe} (hash) VALUES ('%s')", $hash);
    // return TRUE;
  }
}

Very grateful for any assistance, thanks.
Daniel

Comments

span’s picture

Status: Active » Closed (works as designed)

Nevermind, I'm stupid and can't read... "Enable it on the content type"