From 4ba4e64eeb0ad2b188f73f7a901b458417159c6e Mon Sep 17 00:00:00 2001
From: Gordon Heydon <gordon@heydon.com.au>
Date: Sun, 31 Mar 2013 19:52:01 +1100
Subject: [PATCH 2/5] Add hook hook_feeds_postsave().

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

diff --git a/feeds.api.php b/feeds.api.php
index 065c7ea..025f08a 100644
--- a/feeds.api.php
+++ b/feeds.api.php
@@ -331,5 +331,30 @@ function hook_feeds_before_update($source, $processor, $parser_results, $entity_
 }
 
 /**
+ * Example of the Post save hook_feeds_postsave().
+ *
+ * This is called directly after the entity has been saved.
+ *
+ * @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_postsave(FeedsSource $source, FeedsProcessor $processor, FeedsParserResult $parser_results, $entity, $entity_id) {
+  $config = $processor->getConfig();
+
+  if ($config['purge_unseen_items'] && !$entity_id && isset($entity->feeds_item)) {
+    $feeds_item = $entity->feeds_item;
+    $feeds_item->batch_id = feeds_delete_get_current_batch($feeds_item->feed_nid);
+
+    drupal_write_record('feeds_delete_item', $feeds_item);
+  }
+}
+
+/**
  * @}
  */
diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc
index cec73a2..cb4d546 100755
--- a/plugins/FeedsProcessor.inc
+++ b/plugins/FeedsProcessor.inc
@@ -237,6 +237,8 @@ abstract class FeedsProcessor extends FeedsPlugin {
         $this->entitySaveAccess($entity);
         $this->entitySave($entity);
 
+        module_invoke_all('feeds_postsave', $source, $this, $parser_result, $entity, $entity_id);
+
         // Track progress.
         if (empty($entity_id)) {
           $state->created++;
-- 
1.7.11.3

