From 907d0631c13d94c808efd57eedab229847597df3 Mon Sep 17 00:00:00 2001
From: Colan Schwartz <colan@58704.no-reply.drupal.org>
Date: Wed, 7 Dec 2011 13:49:18 -0500
Subject: [PATCH] Issue #1362378 by colan: Added hooks before and after the entity is saved.

---
 feeds.api.php              |   40 ++++++++++++++++++++++++++++++++++++++++
 plugins/FeedsProcessor.inc |    7 +++++++
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/feeds.api.php b/feeds.api.php
index 7b81be8..dcf6f13 100644
--- a/feeds.api.php
+++ b/feeds.api.php
@@ -224,3 +224,43 @@ function my_module_set_target($source, $entity, $target, $value) {
 /**
  * @}
  */
+
+/**
+ * @defgroup process Entity processing hooks
+ * @{
+ */
+
+/**
+ * Invoked before an entity has been saved during processing.
+ *
+ * By implenting this hook, your module can do whatever it needs to do before
+ * an entity is saved.
+ *
+ * @param $processor
+ *  The Feeds processor that is currently processing the entity.
+ * @param $entity
+ *  The entity object that is about to be saved.
+ */
+function hook_feeds_process_entity_before_save(FeedsProcessor $processor, $entity) {
+  // See the entity_translation module's implementation for an example.
+}
+
+/**
+ * Invoked after an entity has been saved during processing.
+ *
+ * By implenting this hook, your module can do whatever it needs to do after
+ * an entity is saved.
+ *
+ * @param $processor
+ *  The Feeds processor that is currently processing the entity.
+ * @param $entity
+ *  The entity object that has just been saved.
+ */
+function hook_feeds_process_entity_after_save(FeedsProcessor $processor, $entity) {
+  // See the entity_translation module's implementation for an example.
+}
+
+/**
+ * @}
+ */
+
diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc
index 97b6269..6f140c8 100644
--- a/plugins/FeedsProcessor.inc
+++ b/plugins/FeedsProcessor.inc
@@ -126,8 +126,15 @@ abstract class FeedsProcessor extends FeedsPlugin {
           }
           $this->map($source, $parser_result, $entity);
           $this->entityValidate($entity);
+
+          // Run any pre-save hooks.
+          module_invoke_all('feeds_process_entity_before_save', $this, $entity);
+
           $this->entitySave($entity);
 
+          // Run any post-save hooks.
+          module_invoke_all('feeds_process_entity_after_save', $this, $entity);
+
           // Track progress.
           if (empty($entity_id)) {
             $state->created++;
-- 
1.7.0.4

