From c3bfd7bf2aa75e16c9d709cf9d3f03fb6175f55b Mon Sep 17 00:00:00 2001
From: Eric Rasmussen <eric@unl.edu>
Date: Thu, 12 Jan 2012 21:48:36 +0000
Subject: [PATCH] [gh-281] Merging test into staging -c1401

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@1402 20a16fea-79d4-4915-8869-1ea9d5ebf173
---
 README-UNL.txt                                |  8 ++
 .../workbench_moderation/README-UNL.txt       | 12 ---
 .../workbench_moderation.module               | 79 +++++++++++++++++++
 3 files changed, 87 insertions(+), 12 deletions(-)
 delete mode 100644 sites/all/modules/workbench_moderation/README-UNL.txt

diff --git a/README-UNL.txt b/README-UNL.txt
index 3ad89868..5f998973 100644
--- a/README-UNL.txt
+++ b/README-UNL.txt
@@ -60,3 +60,11 @@ sites/sites.php
 sites/example.sites.php
  * Added an example of the $default_domains array.
  * Added the stub record needed for creating site aliases.
+ 
+------------------------------------
+
+Add Trigger Support Patch to Workbench Moderation
+ * Trigger support not in 7.x-1.1
+ * http://drupal.org/files/issues/trigger_support_for_wb_moderation-1079134-23.patch
+ *   from http://drupal.org/node/1079134
+ * Don't upgrade WB Moderation without first applying this patch unless the new version supports Triggers
diff --git a/sites/all/modules/workbench_moderation/README-UNL.txt b/sites/all/modules/workbench_moderation/README-UNL.txt
deleted file mode 100644
index 976bbc1e..00000000
--- a/sites/all/modules/workbench_moderation/README-UNL.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-[#897] Upgrade Workbench Moderation to 2011-07-15 7.x-1.x-dev version
- * r857
- * This was done to address broken Unpublishing in 7.x-1.0-beta7
- * If future releases don't include the fix (not likely) patches will be needed from http://drupal.org/node/1206694
-
------------------------------------
-
-[#911] Upgrade Workbench Moderation to 7.x-1.0-beta8 + trigger support
- * Trigger support not in beta8
- * http://drupal.org/files/issues/trigger_support_for_wb_moderation-1079134-10.patch
- *   from http://drupal.org/node/1079134
- * Don't upgrade WB Moderation without first applying this patch unless the new version supports Triggers
\ No newline at end of file
diff --git a/sites/all/modules/workbench_moderation/workbench_moderation.module b/sites/all/modules/workbench_moderation/workbench_moderation.module
index 1d3846d0..63fdbc38 100644
--- a/sites/all/modules/workbench_moderation/workbench_moderation.module
+++ b/sites/all/modules/workbench_moderation/workbench_moderation.module
@@ -1473,6 +1473,10 @@ function workbench_moderation_moderate($node, $state) {
   if (!empty($node->workbench_moderation['published'])) {
     drupal_register_shutdown_function('workbench_moderation_store', $node);
   }
+  /** UNL CHANGE/ADDITION BELOW- SEE /README-UNL.txt **/
+  if (module_exists('trigger')) {
+    workbench_moderation_trigger_transition($node, $old_revision->state, $state);
+  }
 }
 
 /**
@@ -1880,3 +1884,78 @@ function workbench_moderation_ctools_plugin_api($module, $api) {
     return array('version' => 1);
   }
 }
+
+/** UNL CHANGE/ADDITION BELOW- SEE /README-UNL.txt **/
+
+/**
+ * Implements hook_trigger_info().
+ *
+ * Creates a trigger for each transition.
+ */
+function workbench_moderation_trigger_info() {
+
+  $output = array(
+    'workbench_moderation' => array(
+      'workbench_moderation_transition' => array(
+        'label' => t('After any transition between states occurs.'),
+      ),
+    ),
+  );
+
+  // Get all transitions.
+  $transitions = workbench_moderation_transitions();
+
+  // Add a trigger for each trasnistion.
+  foreach ($transitions as $transition_definition) {
+    $transition_string = 'wmt_' . $transition_definition->from_name . '__' . $transition_definition->to_name;
+    // Hash this string if it's longer than the db field size
+    if (strlen($transition_string) > 32) {
+      $transition_string = md5($transition_string);
+    }
+
+    $output['workbench_moderation'][$transition_string] = array(
+      'label' => t('Transition from the state %from_name to %to_name occurs.', array('%from_name' => $transition_definition->from_name, '%to_name' => $transition_definition->to_name)),
+    );
+  }
+
+  return $output;
+}
+
+/**
+ * transition trigger: Run actions associated with an arbitrary event.
+ *
+ * This function is executed after a transition takes place.
+ *
+ * @param $node
+ *   The node undergoing the transition.
+ * @param $from_state
+ *   The previous workbench moderation state.
+ * @param $state
+ *   The new workbench moderation state.
+ */
+function workbench_moderation_trigger_transition($node, $from_state, $state, $a3 = NULL, $a4 = NULL) {
+  // Ask the trigger module for all actions enqueued for the 'transition' trigger.
+  $aids = trigger_get_assigned_actions('workbench_moderation_transition');
+  // prepare a basic context, indicating group and "hook", and call all the
+  // actions with this context as arguments.
+  $context = array(
+    'group' => 'workbench_moderation',
+    'hook' => 'transition',
+    'from_state' => $from_state,
+    'state' => $state,
+  );
+  actions_do(array_keys($aids), $node, $context, $a3, $a4);
+
+
+  // Ask the trigger module for all actions enqueued for this specific transition.
+  $transition_string = 'wmt_' . $from_state . '__' . $state;
+  // Hash this string if it's longer than the db field size
+  if (strlen($transition_string) > 32) {
+    $transition_string = md5($transition_string);
+  }
+  $aids = trigger_get_assigned_actions($transition_string);
+  $context['hook'] = $transition_string;
+
+  actions_do(array_keys($aids), $node, $context, $a3, $a4);
+}
+
-- 
GitLab