From 020ceb3ad9f35ab890697e4a906c7b70ec53fe61 Mon Sep 17 00:00:00 2001
From: Henrique Recidive <recidive@gmail.com>
Date: Fri, 6 Apr 2012 03:16:08 -0300
Subject: [PATCH] Issue #1517348: Add UUID/Deploy support to redirect module.

---
 redirect_uuid/redirect_uuid.info    |    6 +++++
 redirect_uuid/redirect_uuid.install |   38 +++++++++++++++++++++++++++++++++++
 redirect_uuid/redirect_uuid.module  |   33 ++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100644 redirect_uuid/redirect_uuid.info
 create mode 100644 redirect_uuid/redirect_uuid.install
 create mode 100644 redirect_uuid/redirect_uuid.module

diff --git a/redirect_uuid/redirect_uuid.info b/redirect_uuid/redirect_uuid.info
new file mode 100644
index 0000000..c6a9815
--- /dev/null
+++ b/redirect_uuid/redirect_uuid.info
@@ -0,0 +1,6 @@
+name = Redirect UUID
+description = Allow deploying redirects through Deploy and UUID modules. 
+core = 7.x
+
+dependencies[] = redirect
+dependencies[] = uuid
diff --git a/redirect_uuid/redirect_uuid.install b/redirect_uuid/redirect_uuid.install
new file mode 100644
index 0000000..80b0e35
--- /dev/null
+++ b/redirect_uuid/redirect_uuid.install
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * @file
+ * Redirect UUID installation and schema hooks.
+ */
+
+/**
+ * Implements hook_schema_alter().
+ */
+function redirect_uuid_schema_alter(&$schema = array()) {
+  $field = uuid_schema_field_definition();
+  $schema['redirect']['fields']['uuid'] = $field;
+}
+
+/**
+ * Implements hook_install().
+ */
+function redirect_uuid_install() {
+  $field = uuid_schema_field_definition();
+  db_add_field('redirect', 'uuid', $field);
+  db_add_index('redirect', 'uuid', array('uuid'));
+}
+
+/**
+ * Implements hook_enable().
+ */
+function redirect_uuid_enable() {
+  uuid_sync_all();
+}
+
+/**
+ * Implements hook_uninstall().
+ */
+function redirect_uuid_uninstall() {
+  db_drop_field('redirect', 'uuid');
+  db_drop_index('redirect', 'uuid');
+}
diff --git a/redirect_uuid/redirect_uuid.module b/redirect_uuid/redirect_uuid.module
new file mode 100644
index 0000000..f7079c8
--- /dev/null
+++ b/redirect_uuid/redirect_uuid.module
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * @file
+ * Implement UUID/Entity hooks for integrating with deploy and other modules.
+ */
+
+/**
+ * Implements hook_entity_info_alter().
+ */
+function redirect_uuid_entity_info_alter(&$entity_info) {
+  // Set the properties bellow for redirect entity so UUIDs get created on sync.
+  $entity_info['redirect']['uuid'] = TRUE;
+  $entity_info['redirect']['entity keys']['uuid'] = 'uuid';
+}
+
+/**
+ * Implements hook_entity_uuid_load().
+ */
+function redirect_uuid_entity_uuid_load(&$entities, $entity_type) {
+  if ($entity_type == 'redirect') {
+    entity_property_id_to_uuid($entities, 'redirect', 'bid');
+  }
+}
+
+/**
+ * Implements hook_entity_uuid_presave().
+ */
+function redirect_uuid_entity_uuid_presave(&$entity, $entity_type) {
+  if ($entity_type == 'redirect') {
+    entity_property_uuid_to_id($entity, 'redirect', 'bid');
+  }
+}
-- 
1.7.9.1

