From 7cfb10fe1224a6d5467fb96ffaa6ca5a96249ab4 Mon Sep 17 00:00:00 2001
From: Kristiaan Van den Eynde <magentix@gmail.com>
Date: Tue, 22 Apr 2014 16:36:39 +0200
Subject: [PATCH] Issue #1789494 by kristiaanvandeneynde, awm | joachim:
 Hook_entity_delete() should be invoked before entities are
 deleted, not after.

---
 includes/entity.controller.inc |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/includes/entity.controller.inc b/includes/entity.controller.inc
index f675a63..a175eab 100644
--- a/includes/entity.controller.inc
+++ b/includes/entity.controller.inc
@@ -375,6 +375,11 @@ class EntityAPIController extends DrupalDefaultEntityController implements Entit
     }
     $transaction = isset($transaction) ? $transaction : db_transaction();
 
+    // Invoke delete hooks before the deletion takes place.
+    foreach ($entities as $id => $entity) {
+      $this->invoke('delete', $entity);
+    }
+
     try {
       $ids = array_keys($entities);
 
@@ -390,9 +395,6 @@ class EntityAPIController extends DrupalDefaultEntityController implements Entit
       // Reset the cache as soon as the changes have been applied.
       $this->resetCache($ids);
 
-      foreach ($entities as $id => $entity) {
-        $this->invoke('delete', $entity);
-      }
       // Ignore slave server temporarily.
       db_ignore_slave();
     }
-- 
1.7.9.4

