? d.patch
? workflow_ng_log.patch
Index: workflow_ng_log/workflow_ng_log.info
===================================================================
RCS file: workflow_ng_log/workflow_ng_log.info
diff -N workflow_ng_log/workflow_ng_log.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ workflow_ng_log/workflow_ng_log.info	18 Jan 2008 16:08:40 -0000
@@ -0,0 +1,4 @@
+; $Id$
+name = Per-Entity Logs
+description = Provides per-user and per-node logs which can be written to by actions and presented using views.
+package = Workflow-ng
Index: workflow_ng_log/workflow_ng_log.install
===================================================================
RCS file: workflow_ng_log/workflow_ng_log.install
diff -N workflow_ng_log/workflow_ng_log.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ workflow_ng_log/workflow_ng_log.install	18 Jan 2008 16:08:40 -0000
@@ -0,0 +1,62 @@
+<?php
+// $Id$
+
+/*
+ * Implementation of hook_install()
+ */
+function workflow_ng_log_install() {
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysqli':
+    case 'mysql':
+      db_query("CREATE TABLE if not exists {workflow_ng_log_user} (
+        mid int unsigned NOT NULL auto_increment,
+        uid int unsigned NOT NULL default '0',
+        type varchar(255),
+        category varchar(255),
+        message longtext NOT NULL,
+        time int NOT NULL default '0',
+        PRIMARY KEY (mid)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      db_query("CREATE TABLE if not exists {workflow_ng_log_node} (
+        mid int unsigned NOT NULL auto_increment,
+        nid int unsigned NOT NULL default '0',
+        type varchar(255),
+        category varchar(255),
+        message longtext NOT NULL,
+        time int NOT NULL default '0',
+        PRIMARY KEY (mid)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      break;
+    case 'pgsql':
+      db_query("CREATE TABLE {workflow_ng_log_user} (
+        mid serial CHECK (mid >= 0),
+        uid int_unsigned NOT NULL default '0',
+        type varchar(255),
+        category varchar(255),
+        message text NOT NULL,
+        time integer,
+        PRIMARY KEY (mid)
+      )");
+      db_query("CREATE TABLE {workflow_ng_log_node} (
+        mid serial CHECK (mid >= 0),
+        nid int_unsigned NOT NULL default '0',
+        type varchar(255),
+        category varchar(255),
+        message text NOT NULL,
+        time integer,
+        PRIMARY KEY (mid)
+      )");
+      break;
+    default:
+      break;
+  }
+}
+
+/*
+ * Implementation of hook_uninstall()
+ */
+function workflow_ng_log_uninstall() {
+  db_query("DROP TABLE {workflow_ng_log_user}");
+  db_query("DROP TABLE {workflow_ng_log_node}");
+}
Index: workflow_ng_log/workflow_ng_log.module
===================================================================
RCS file: workflow_ng_log/workflow_ng_log.module
diff -N workflow_ng_log/workflow_ng_log.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ workflow_ng_log/workflow_ng_log.module	18 Jan 2008 16:08:40 -0000
@@ -0,0 +1,76 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_action_info()
+ */
+function workflow_ng_log_action_info() {
+  return array(
+    'workflow_ng_log_action_message' => array(
+      '#label' => t('Write a message to the log'),
+      '#arguments' => array(
+        'subject' => array('#entity' => array('node', 'user'), '#label' => t('Entity whose log to write to')),
+      ),
+      '#module' => t('Per-Entity Logging'),
+    ),
+  );
+}
+
+/**
+ * Writes a message to the per-user or per-entity log
+ */
+function workflow_ng_log_action_message($subject, $settings, &$arguments, &$log) {
+  if (isset($subject->nid)) {
+    $subject_id = $subject->nid;
+    $query = 'workflow_ng_log_node} (nid';
+  }
+  else {
+    $subject_id = $subject->uid;
+    $query = 'workflow_ng_log_user} (uid';
+  }
+  $query = 'INSERT INTO {'. $query .", type, category, message, time) VALUES (%d, '%s', '%s', '%s', %d)";
+
+  extract(workflow_ng_token_replace_all(array('type', 'category', 'message'), $settings, $arguments, $log));
+  db_query($query, $subject_id, substr($type, 0, 255), substr($category, 0, 255), $message, time());
+}
+
+/*
+ * Action "Write a message to the user / node log" configuration form
+ */
+function workflow_ng_log_action_message_form($settings = array(), $argument_info) {
+  $form = array();
+  $form['type'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Message type'),
+    '#default_value' => $settings['type'],
+    '#description' => t('Enter the message type.'),
+    '#required' => FALSE,
+    // No maximum length specified, even though the database field has a limited
+    // length (255), as the tokens may expand or contract.
+  );
+  $form['category'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Message category'),
+    '#default_value' => $settings['category'],
+    '#description' => t('Enter the message category.'),
+    '#required' => FALSE,
+    // No maximum length specified, even though the database field has a limited
+    // length (255), as the tokens may expand or contract.
+  );
+  $form['message'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Message'),
+    '#default_value' => $settings['message'],
+    '#description' => t('Enter the message to log.'),
+    '#required' => TRUE,
+  );
+  workflow_ng_token_replacement_help($form, $argument_info);
+  return $form;
+}
+
+/*
+ * Action "Write a message to the user / node log" configuration form submission handler
+ */
+function workflow_ng_log_action_message_submit($form_id, $form_values) {
+  return workflow_ng_token_get_settings(array('type', 'category', 'message'), $form_values);
+}
