From dc87c3ca8ea50d0599cc369dce027a3073447f94 Mon Sep 17 00:00:00 2001
From: Jan Buelens <jan.buelens@desk02.be>
Date: Tue, 15 May 2012 13:52:21 +0200
Subject: [PATCH] Implementation hook_entity_delete"

---
 pathauto_paths.module |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/pathauto_paths.module b/pathauto_paths.module
index 987df67..e58702c 100644
--- a/pathauto_paths.module
+++ b/pathauto_paths.module
@@ -128,3 +128,29 @@ function pathauto_paths_load($id) {
     ->fetchAssoc();
   return $record;
 }
+
+/**
+ * Implements hook_entity_delete().
+ */
+function pathauto_paths_entity_delete($entity, $type) {
+  $info = entity_get_info($type);
+  $entity_id = $entity->{$info['entity keys']['id']};
+  $source = array();
+  
+  $result = db_select('pathauto_paths', 'pp')
+    ->fields('pp')
+    ->condition('entity_type', $type)
+    ->condition('bundle', $entity->{$info['entity keys']['bundle']})
+    ->execute();
+    
+  foreach ($result as $row) {    
+    array_push($source, str_replace('%', $entity_id, $row->router_path));
+  }
+  
+  $num_deleted = db_delete('url_alias')
+      ->condition('source', $source)
+      ->execute();
+  
+  return $num_deleted;
+}
+
-- 
1.7.9.5

