From fd2d836d18a7364fb7d6c43b59f4f5cb48c07919 Mon Sep 17 00:00:00 2001
From: Dave Hall <dave.hall@skwashd.com>
Date: Mon, 20 Aug 2012 09:02:05 +0200
Subject: [PATCH] Issue #1517348 by skwashd, recidive: Add UUID submodule.

---
 redirect_uuid/.redirect_uuid.module.swp |  Bin 0 -> 12288 bytes
 redirect_uuid/redirect_uuid.info        |    6 ++++
 redirect_uuid/redirect_uuid.install     |   38 ++++++++++++++++++++++
 redirect_uuid/redirect_uuid.module      |   52 +++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+)
 create mode 100644 redirect_uuid/.redirect_uuid.module.swp
 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.module.swp b/redirect_uuid/.redirect_uuid.module.swp
new file mode 100644
index 0000000000000000000000000000000000000000..924e13c63d8cde680f14cabe0f0a45ca39a10cd6
GIT binary patch
literal 12288
zcmeI2&u`pB6vwAMAbvF<_y-=z3h##Qx@`_rv<XEJiBzJBO2Q=s%kj)+r?EYjJti`t
zaO;1-0S?@d0C9jzPk_`L;%`7g;@1IjKtdeg#COK_b_v;Rg}9*1N}u@Gyf^c{@A<8w
zot<;9ti41}50)4{k23bvkNx#QGRJN|!Wa)<7v}b?PpqOa9;rgl82FZP=&$GMhKO|G
zbCJcW^0|s~rL<p2Eeb!3V?R;6jB%a|E^`bWp9Ezo`QNVw_23yZyT?v}6Rtq1hy9CZ
z*wTgb=Zq2y^H0#@k8PfCQC#>=0jGddz$xGqa0)mDoB~dPlcj*pPO-NU^64h*XPV=w
zL&xUQ9h?GA0jGddz$xGqa0)mDoB~b(r+`zyDc}_NA1V-X#>D-M$p^4_{Qlqm|Nkd`
z|NjI04t@degZIF@AOSHLfh*uLI1N6VW9$~V3K+O^hOsxn8=wLuxCX9*`@nY(Gxj<7
z5J<2DetU?qFTri_Dfk3@3_b!MfCI1(E`T}k&4Y}64c-AESOC8wmY=~-;0N$M_!is&
zUw~U+515!=1byH>P64NYQ@|<U6mSZhR0VD_qFm@QPpPYR%r?aybwsMAt}d}*dCcQu
z9vRCtnmIsAm16RG%cI@t7(}@Uwdgi0INL5I&{ZaSbiioQ2lTuhR!}%Lr+Uo;<}WTX
zW~Mf@f2noUUnx|XM}n4VK2==!2OVA}Nfnrj{z@wO&G}2#kQ$Fcma9zUx~dnbRUmnH
z!ssk{#?~`O$-Q1{Juw86jkOK)JgmBQC@rs0C)ql`-Pp(>b+cUT21%%+QMZ$YT8lg#
zi_oqeH<F$e1Mzhdc(0u{ZdyCs_ZD8WL3TYF(B|ga3&Hwx8yl<Fui?_`brw9cSTk*-
zx0RWeVc2HHGxL~a9+9hB@mdzFyTDf0?vt}Jx0YnFNMKsfNU6QxC?~zCS*&x4u>Vay
z|Cv$A1LV_evAvg!V$!>{a*sK!<(<gtI3=(0r%VQp&+bwA9V!%mG-{J31zv-KTH))u
z_)l^gtB|(|#Vq5M9)1~*OR4oSna{S;WI9w^cgt*h%i|&zw#u-zI^GGRJ#X8Ta9fFi
zeJ*UtPIqF8kft~=&t{n0_G7xz6c?scnjSU7Q(f1zC#u3jaK^BX$DWz@Zh8>o!5h~%
zSIto0r<a8$JrdM(Ba`(V5yxtuP!ET@AQj5K?gj0_tnR6t5LQv8(O|~=Y%&vsF<MWX
z{3<Z_Cfe_mj89m$DX;gc2c`_*B#KKex*kqUyR>1pM>MatxsScu82nZHWn{ZWVS|;a
r7Q1<<Wx7lIQje(KR!?Dy7@<*4&35{M`Kq`wl(DG46)r!UjWYHZ5<!|+

literal 0
HcmV?d00001

diff --git a/redirect_uuid/redirect_uuid.info b/redirect_uuid/redirect_uuid.info
new file mode 100644
index 0000000..1d9b5ae
--- /dev/null
+++ b/redirect_uuid/redirect_uuid.info
@@ -0,0 +1,6 @@
+name = Redirect UUID
+description = Add UUIDs to redirects which makes them deployable via deploy.
+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..24a5f35
--- /dev/null
+++ b/redirect_uuid/redirect_uuid.module
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * @file
+ * Implement UUID/Entity hooks for integrating with deploy and other modules.
+ */
+
+module_load_include('inc', 'uuid', 'uuid');
+
+/**
+ * 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';
+  $entity_info['redirect']['creation callback'] = 'entity_metadata_create_object';
+  $entity_info['redirect']['save callback'] = 'redirect_save';
+  $entity_info['redirect']['deletion callback'] = 'redirect_delete';
+}
+
+/**
+ * Implements hook_entity_uuid_load().
+ */
+function redirect_uuid_entity_uuid_load(&$entities, $entity_type) {
+  if ($entity_type == 'redirect') {
+    foreach ($entities as &$entity) {
+      $m = array();
+      if (preg_match('#^node/(\d+)$#', $entity->source, $m)) {
+        $dummy_node = (object) array('nid' => $m[1]);
+        entity_property_id_to_uuid($dummy_node, 'node', 'nid');
+        $entity->source = "node/{$dummy_node->nid}";
+      }
+    }
+  }
+}
+
+/**
+ * Implements hook_entity_uuid_presave().
+ */
+function redirect_uuid_entity_uuid_presave(&$entity, $entity_type) {
+  if ($entity_type == 'redirect') {
+    $pattern = '#^node/(' . UUID_PATTERN . ')$#';
+    $m = array();
+    if (preg_match($pattern, $entity->source, $m)) {
+      $dummy_node = (object) array('nid' => $m[1]);
+      entity_property_uuid_to_id($dummy_node, 'node', 'nid');
+      $entity->source = "node/{$dummy_node->nid}";
+    }
+  }
+}
+
-- 
1.7.9.5

