From e1ea9ca11d2a0d74fd8fb6ae1aaeb3258f5a3f1d Mon Sep 17 00:00:00 2001
From: Gordon Heydon <gordon@heydon.com.au>
Date: Sun, 31 Mar 2013 19:49:03 +1100
Subject: [PATCH 1/5] Add new hook hook_feeds_before_update()

---
 feeds.api.php              | 24 ++++++++++++++++++++++++
 plugins/FeedsProcessor.inc |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/feeds.api.php b/feeds.api.php
index 62b22a3..065c7ea 100644
--- a/feeds.api.php
+++ b/feeds.api.php
@@ -307,5 +307,29 @@ function my_module_form_callback($mapping, $target, $form, $form_state) {
 }
 
 /**
+ * Example of the Before Process hook_feeds_before_process().
+ *
+ * This is called every time a feed item is processed no matter if the item gets updated or not.
+ *
+ * @param FeedsSource $source
+ *  The source for the current feed.
+ * @param FeedsProcessor $processor
+ *  The current FeedsProcessor object
+ * @param FeedsParserResult $parser_result
+ *  All the current results from the feed.
+ * @param $entity_id
+ *  The id of the current item which is going to be updated. If this is a new item then NULL is past.
+ */
+function hook_feeds_before_update($source, $processor, $parser_results, $entity_id) {
+  if ($entity_id) {
+    db_update('foo_bar')
+      ->fields('entity_type' => $processor->entityType(), 'entity_id' => $entity_id, 'last_seen' => REQUEST_TIME)
+      ->condition('entity_type', $processor->entityType())
+      ->condition('entity_id', $entity_id)
+      ->execute();
+  }
+}
+
+/**
  * @}
  */
diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc
index aea7df6..cec73a2 100755
--- a/plugins/FeedsProcessor.inc
+++ b/plugins/FeedsProcessor.inc
@@ -183,6 +183,8 @@ abstract class FeedsProcessor extends FeedsPlugin {
       $entity_id = $this->existingEntityId($source, $parser_result);
       $skip_existing = $this->config['update_existing'] == FEEDS_SKIP_EXISTING;
 
+      module_invoke_all('feeds_before_update', $source, $this, $parser_result, $entity_id);
+
       // If it exists, and we are not updating, pass onto the next item.
       if ($entity_id && $skip_existing) {
         continue;
-- 
1.7.11.3

