? uc_node_access6.patch
Index: uc_node_access.ca.inc
===================================================================
RCS file: uc_node_access.ca.inc
diff -N uc_node_access.ca.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ uc_node_access.ca.inc	2 Jan 2009 05:56:10 -0000
@@ -0,0 +1,100 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * This file contains the Conditional Actions hooks and functions necessary to
+ * grant node access upon purchase.
+ */
+
+/**
+ * Implementation of hook_ca_predicate().
+ */
+function uc_node_access_ca_predicate() {
+  $configurations['uc_node_access_grant_on_payment'] = array(
+    '#title' => t('Grant appropriate node access on full payment'),
+    '#description' => t('Only happens when a payment is entered and the balance is <= $0.00.'),
+    '#class' => 'node_access',
+    '#status' => 1,
+    '#trigger' => 'uc_payment_entered',
+    '#conditions' => array(
+      '#operator' => 'AND',
+      '#conditions' => array(
+        array(
+          '#name' => 'uc_payment_condition_order_balance',
+          '#title' => t('If the balance is less than or equal to $0.00.'),
+          '#argument_map' => array(
+            'order' => 'order',
+          ),
+          '#settings' => array(
+            'negate' => FALSE,
+            'balance_comparison' => 'less_equal',
+          ),
+        ),
+        array(
+          '#name' => 'uc_order_status_condition',
+          '#title' => t('If the order status is not already Payment Received.'),
+          '#argument_map' => array(
+            'order' => 'order',
+          ),
+          '#settings' => array(
+            'negate' => TRUE,
+            'order_status' => 'payment_received',
+          ),
+        ),
+      ),
+    ),
+    '#actions' => array(
+      array(
+        '#name' => 'uc_node_access_grant_access',
+        '#title' => t('Grant access to the user'),
+        '#argument_map' => array(
+          'order' => 'order',
+        ),
+        '#settings' => array(
+        ),
+      ),
+    ),
+  );
+
+  return $configurations;
+}
+
+/**
+ * Implementation of hook_ca_action().
+ */
+function uc_node_access_ca_action() {
+	$order_arg = array(
+    '#entity' => 'uc_order',
+    '#title' => t('Order'),
+  );
+  $actions['uc_node_access_grant_access'] = array(
+    '#title' => t('Grant access to a node'),
+    '#category' => t('Order'),
+    '#callback' => 'uc_node_access_action_grant_access',
+    '#arguments' => array(
+      'order' => $order_arg,
+    ),
+  );
+  
+  return $actions;
+}
+
+
+function uc_node_access_action_grant_access($order, $settings = array()) {
+  if (is_array($order->products)) {
+    $nids = array();
+    $models = array();
+
+    foreach ($order->products as $product) {
+      $nids[] = $product->nid;
+      $models[] = $product->model;
+    }
+    $result = db_query("SELECT pf.pfid, nap.model FROM {uc_product_features} AS pf LEFT JOIN {uc_node_access_products} AS nap ON pf.pfid = nap.pfid WHERE pf.nid IN (". implode(", ", $nids) .") AND pf.fid = 'node_access'");
+    while ($row = db_fetch_array($result)) {
+      if (empty($row['model']) || in_array($row['model'], $models)) {
+        uc_node_access_grant_user_access($row['pfid'], $order->uid);
+      }
+    }
+  }
+}
Index: uc_node_access.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_node_access/uc_node_access.info,v
retrieving revision 1.1
diff -u -p -r1.1 uc_node_access.info
--- uc_node_access.info	27 Jun 2008 18:21:27 -0000	1.1
+++ uc_node_access.info	2 Jan 2009 05:56:10 -0000
@@ -1,6 +1,9 @@
-; $Id: uc_node_access.info,v 1.1 2008/06/27 18:21:27 rszrama Exp $
+; $Id$
 name = UC Node Access
 description = Grant customers access to nodes on your site when they purchase specified products.
-dependencies = uc_store uc_order uc_product workflow_ng
+dependencies[] = uc_store
+dependencies[] = uc_order
+dependencies[] = uc_product
 package = Access control
 
+core = 6.x
\ No newline at end of file
Index: uc_node_access.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_node_access/uc_node_access.install,v
retrieving revision 1.1
diff -u -p -r1.1 uc_node_access.install
--- uc_node_access.install	27 Jun 2008 18:21:27 -0000	1.1
+++ uc_node_access.install	2 Jan 2009 05:56:10 -0000
@@ -1,33 +1,92 @@
 <?php
-// $Id: uc_node_access.install,v 1.1 2008/06/27 18:21:27 rszrama Exp $
+// $Id$
+
+/**
+ * Implementation of hook_schema().
+ */
+function uc_node_access_schema() {
+  $schema['uc_node_access_products'] = array(
+    'description' => t('TODO'),
+    'fields' => array(
+      'pfid' => array(
+        'description' => t('TODO'),
+        'type' => 'int',
+        'size' => 'medium',
+        'not null' => TRUE,
+      ),
+      'model' => array(
+        'description' => t('TODO'),
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => FALSE,
+      ),
+      'access_nid' => array(
+        'description' => t('TODO'),
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'access_limit' => array(
+        'description' => t('TODO'),
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE,
+      ),
+      'time_period' => array(
+        'description' => t('TODO'),
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+      ),
+      'end_date' => array(
+        'description' => t('TODO'),
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'model' => array('model'),
+    ),
+    'primary key' => array('pfid'),
+  );
+
+  $schema['uc_node_access_expirations'] = array(
+    'description' => t('TODO'),
+    'fields' => array(
+      'uid' => array(
+        'description' => t('TODO'),
+        'type' => 'int',
+        'size' => 'medium',
+        'not null' => TRUE,
+      ),
+      'access_nid' => array(
+        'description' => t('TODO'),
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'expiration' => array(
+        'description' => t('TODO'),
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'uid' => array('uid'),
+      'access_nid' => array('access_nid'),
+    ),
+  );
+
+  return $schema;
+}
 
 function uc_node_access_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      db_query("CREATE TABLE {uc_node_access_products} (
-        pfid mediumint(9) NOT NULL,
-        model varchar(255) NULL,
-        access_nid int(10) NOT NULL,
-        access_limit varchar(32) NOT NULL,
-        time_period varchar(255) NOT NULL,
-        end_date varchar(255) NOT NULL,
-        PRIMARY KEY pfid (pfid),
-        KEY model (model)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
-      db_query("CREATE TABLE {uc_node_access_expirations} (
-        uid mediumint(11) NOT NULL,
-        access_nid int(10) NOT NULL,
-        expiration int(11) NOT NULL,
-        KEY uid (uid),
-        KEY access_nid (access_nid)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
-      break;
-  }
+  // Create tables.
+  drupal_install_schema('uc_node_access');
 }
 
 function uc_node_access_uninstall() {
-  db_query("DROP TABLE IF EXISTS {uc_node_access_products}");
-  db_query("DROP TABLE IF EXISTS {uc_node_access_expirations}");
+  // Remove tables.
+  drupal_uninstall_schema('uc_node_access');
+
 }
 
Index: uc_node_access.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_node_access/uc_node_access.module,v
retrieving revision 1.1
diff -u -p -r1.1 uc_node_access.module
--- uc_node_access.module	27 Jun 2008 18:21:27 -0000	1.1
+++ uc_node_access.module	2 Jan 2009 05:56:10 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: uc_node_access.module,v 1.1 2008/06/27 18:21:27 rszrama Exp $
+// $Id$
 
 /**
  * @file
@@ -9,22 +9,19 @@
  * Sponsored by Flat World Knowledge - http://www.flatworldknowledge.com
  */
 
+require_once('uc_node_access.ca.inc');
+
 /**
  * Implementation of hook_menu().
  */
-function uc_node_access_menu($may_cache) {
+function uc_node_access_menu() {
   $items = array();
-
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'uc_node_access/autocomplete',
-      'title' => t('UC Node Access autocomplete'),
-      'callback' => 'uc_node_access_autocomplete',
-      'access' => user_access('administer product features'),
-      'type' => MENU_CALLBACK,
-    );
-  }
-
+  $items['uc_node_access/autocomplete'] = array(
+    'title' => 'UC Node Access autocomplete',
+    'page callback' => 'uc_node_access_autocomplete',
+    'access arguments' => array('administer product features'),
+    'type' => MENU_CALLBACK,
+  );
   return $items;
 }
 
@@ -47,7 +44,7 @@ function uc_node_access_cron() {
   }
 
   if (!empty($items)) {
-    watchdog('uc_node_access', t('The following expirations occurred:') . theme('item_list', $items));
+    watchdog('uc_node_access', 'The following expirations occurred:' . theme('item_list', $items));
   }
 }
 
@@ -67,7 +64,7 @@ function uc_node_access_product_feature(
 }
 
 // Display the settings form for the node access product feature.
-function uc_node_access_feature_form($node, $feature) {
+function uc_node_access_feature_form(&$form_state, $node, $feature) {
   $handler = variable_get('ucna_handler', '');
 
   // Throw up a warning if the handler hasn't been selected yet.
@@ -157,25 +154,26 @@ function uc_node_access_feature_form($no
   return uc_product_feature_form($form);
 }
 
-function uc_node_access_feature_form_submit($form_id, $form_values) {
-  if (empty($form_values['pfid'])) {
-    $access['pfid'] = db_next_id('{uc_product_features}_pfid');
+function uc_node_access_feature_form_submit($form, &$form_state) {
+  if ($form_state['values']['pfid']) {
+    $access['pfid'] = $form_state['values']['pfid'];
+    $update = true;
   }
   else {
-    $access['pfid'] = $form_values['pfid'];
+    $access['pfid'] = false;
+    $update = false;
   }
 
   $access = array(
     'pfid' => $access['pfid'],
-    'model' => $form_values['model'],
-    'access_nid' => $form_values['access_nid'],
-    'access_limit' => $form_values['access_limit'],
-    'time_period' => $form_values['time_period_value'] .' '. $form_values['time_period_unit'],
-    'end_date' => $form_values['end_date'],
+    'model' => $form_state['values']['model'],
+    'access_nid' => $form_state['values']['access_nid'],
+    'access_limit' => $form_state['values']['access_limit'],
+    'time_period' => $form_state['values']['time_period_value'] .' '. $form_state['values']['time_period_unit'],
+    'end_date' => $form_state['values']['end_date'],
   );
-  uc_node_access_feature_save($access);
 
-  switch ($form_values['access_limit']) {
+  switch ($form_state['values']['access_limit']) {
     case 'time_period':
       $description = t('Grant access to <a href="!url">node @nid</a> for @period.', array('@nid' => $access['access_nid'], '@period' => $access['time_period'], '!url' => url('node/'. $access['access_nid'])));
       break;
@@ -197,12 +195,17 @@ function uc_node_access_feature_form_sub
 
   $data = array(
     'pfid' => $access['pfid'],
-    'nid' => $form_values['nid'],
+    'nid' => $form_state['values']['nid'],
     'fid' => 'node_access',
     'description' => $description,
   );
 
-  return uc_product_feature_save($data);
+  $form_state['redirect'] = uc_product_feature_save($data, $update);
+  
+  if (empty($data['pfid'])) {
+    $access['pfid'] = db_last_insert_id('uc_product_features', 'pfid');
+  }
+  uc_node_access_feature_save($access);
 }
 
 // Adds the fields for this feature in the product features settings form.
@@ -229,13 +232,12 @@ function uc_node_access_feature_settings
   return $form;
 }
 
-function uc_node_access_feature_save($data) {
-  // First attempt to update an existing row.
-  db_query("UPDATE {uc_node_access_products} SET model = '%s', access_nid = %d, access_limit = '%s', time_period = '%s', end_date = '%s' WHERE pfid = %d",
-    $data['model'], $data['access_nid'], $data['access_limit'], $data['time_period'], serialize($data['end_date']), $data['pfid']);
-
-  // Otherwise insert this feature as a new row.
-  if (db_affected_rows() == 0) {
+function uc_node_access_feature_save($data, $update) {
+  if ($update) {
+    db_query("UPDATE {uc_node_access_products} SET model = '%s', access_nid = %d, access_limit = '%s', time_period = '%s', end_date = '%s' WHERE pfid = %d",
+      $data['model'], $data['access_nid'], $data['access_limit'], $data['time_period'], serialize($data['end_date']), $data['pfid']);
+  }
+  else {
     db_query("INSERT INTO {uc_node_access_products} (pfid, model, access_nid, access_limit, time_period, end_date) VALUES (%d, '%s', %d, '%s', '%s', '%s')",
       $data['pfid'], $data['model'], $data['access_nid'], $data['access_limit'], $data['time_period'], serialize($data['end_date']));
   }
@@ -260,13 +262,13 @@ function uc_node_access_op($op, $nid, $u
 
   // Fail if the handler hasn't been specified or has been uninstalled.
   if (empty($handler) || !function_exists($handler)) {
-    watchdog('uc_node_access', t('The node access handler is either not specified or missing. Node access features cannot be processed until this is resolved.'), WATCHDOG_WARNING);
+    watchdog('uc_node_access', 'The node access handler is either not specified or missing. Node access features cannot be processed until this is resolved.', WATCHDOG_WARNING);
     return;
   }
 
   // Fail if we receive an invalid nid or uid.
   if (intval($nid) <= 0 || intval($uid) <= 0) {
-    watchdog('uc_node_access', t('Invalid arguments passed to UC Node Access for processing.'), WATCHDOG_WARNING);
+    watchdog('uc_node_access', 'Invalid arguments passed to UC Node Access for processing.', WATCHDOG_WARNING);
     return;
   }
 
@@ -275,7 +277,7 @@ function uc_node_access_op($op, $nid, $u
 
   // Log failed node access operations.
   if ($result === FALSE) {
-    watchdog('uc_node_access', t('A node access operation failed! $op = @op, $nid = @nid, $uid = @uid', array('@op' => $op, '@nid' => $nid, '@uid' => $uid)), WATCHDOG_WARNING);
+    watchdog('uc_node_access', 'A node access operation failed! $op = @op, $nid = @nid, $uid = @uid', array('@op' => $op, '@nid' => $nid, '@uid' => $uid), WATCHDOG_WARNING);
   }
 }
 
@@ -315,22 +317,22 @@ function uc_node_access_grant_user_acces
     if (empty($result)) {
       db_query("INSERT INTO {uc_node_access_expirations} (uid, access_nid, expiration) VALUES (%d, %d, %d)",
         $uid, $access['access_nid'], $expiration);
-      watchdog('uc_node_access', t('User @uid granted access to node @nid until @date.', array('@uid' => $uid, '@nid' => $access['access_nid'], '@date' => format_date($expiration, 'custom', 'm/d/Y'))));
+      watchdog('uc_node_access', 'User @uid granted access to node @nid until @date.', array('@uid' => $uid, '@nid' => $access['access_nid'], '@date' => format_date($expiration, 'custom', 'm/d/Y')));
     }
     else if ($result < $expiration) {
       // Otherwise we need to update the expiration to be later.
       db_query("UPDATE {uc_node_access_expirations} SET expiration = %d WHERE uid = %d AND access_nid = %d", $expiration, $uid, $access['access_nid']);
-      watchdog('uc_node_access', t('User @uid extended access for node @nid until @date.', array('@uid' => $uid, '@nid' => $access['access_nid'], '@date' => format_date($expiration, 'custom', 'm/d/Y'))));
+      watchdog('uc_node_access', 'User @uid extended access for node @nid until @date.', array('@uid' => $uid, '@nid' => $access['access_nid'], '@date' => format_date($expiration, 'custom', 'm/d/Y')));
     }
     else {
-      watchdog('uc_node_access', t('User @uid purchased duplicate access for node @nid that expires earlier than their current access.', array('@uid' => $uid, '@nid' => $access['access_nid'], '@date' => format_date($expiration, 'custom', 'm/d/Y'))));
+      watchdog('uc_node_access', 'User @uid purchased duplicate access for node @nid that expires earlier than their current access.', array('@uid' => $uid, '@nid' => $access['access_nid'], '@date' => format_date($expiration, 'custom', 'm/d/Y')));
     }
   }
   else {
     // Delete any prior expiration reference.
     db_query("DELETE FROM {uc_node_access_expirations} WHERE uid = %d AND access_nid = %d", $uid, $access['access_nid']);
 
-    watchdog('uc_node_access', t('User @uid granted indefinite access to node @nid.', array('@uid' => $uid, '@nid' => $access['access_nid'])));
+    watchdog('uc_node_access', 'User @uid granted indefinite access to node @nid.', array('@uid' => $uid, '@nid' => $access['access_nid']));
   }
 }
 
@@ -348,68 +350,3 @@ function uc_node_access_autocomplete($st
   print drupal_to_js($matches);
   exit();
 }
-
-
-/*******************************************************************************
- * Workflow-ng Integration
- ******************************************************************************/
-
-function uc_node_access_configuration() {
-  $configurations['uc_node_access_grant_on_payment'] = array(
-    '#type' => 'configuration',
-    '#label' => t('Grant appropriate node access on full payment'),
-    '#event' => 'payment_entered',
-    '#module' => 'uc_node_access',
-    '#active' => TRUE,
-  );
-  $configurations['uc_node_access_grant_on_payment'][] = array(
-    '#type' => 'condition',
-    '#name' => 'uc_payment_condition_balance',
-    '#argument map' => array(
-      'order' => 'order',
-    ),
-    '#settings' => array(
-      'balance_comparison' => 'less_equal',
-    ),
-  );
-  $configurations['uc_node_access_grant_on_payment'][] = array(
-    '#type' => 'action',
-    '#name' => 'uc_node_access_grant_access',
-    '#argument map' => array(
-      'order' => 'order',
-    ),
-  );
-
-  return $configurations;
-}
-
-function uc_node_access_action_info() {
-  $actions['uc_node_access_grant_access'] = array(
-    '#label' => t('Grant node access to customer'),
-    '#arguments' => array(
-      'order' => array('#entity' => 'order', '#label' => t('Order')),
-    ),
-    '#module' => t('UC Node Access'),
-  );
-
-  return $actions;
-}
-
-function uc_node_access_grant_access($order, $settings) {
-  if (is_array($order->products)) {
-    $nids = array();
-    $models = array();
-
-    foreach ($order->products as $product) {
-      $nids[] = $product->nid;
-      $models[] = $product->model;
-    }
-
-    $result = db_query("SELECT pf.pfid, nap.model FROM {uc_product_features} AS pf LEFT JOIN {uc_node_access_products} AS nap ON pf.pfid = nap.pfid WHERE pf.nid IN (". implode(", ", $nids) .") AND pf.fid = 'node_access'");
-    while ($row = db_fetch_array($result)) {
-      if (empty($row['model']) || in_array($row['model'], $models)) {
-        uc_node_access_grant_user_access($row['pfid'], $order->uid);
-      }
-    }
-  }
-}
Index: handlers/uc_node_access_acl.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_node_access/handlers/uc_node_access_acl.info,v
retrieving revision 1.1
diff -u -p -r1.1 uc_node_access_acl.info
--- handlers/uc_node_access_acl.info	27 Jun 2008 18:21:26 -0000	1.1
+++ handlers/uc_node_access_acl.info	2 Jan 2009 05:56:10 -0000
@@ -1,6 +1,10 @@
-; $Id: uc_node_access_acl.info,v 1.1 2008/06/27 18:21:26 rszrama Exp $
+; $Id$
 name = UC Node Access ACL
 description = Integrates UC Node Access with ACL and Content Access for granting node access on purchase.
-dependencies = uc_node_access acl content_access
+dependencies[] = uc_node_access
+dependencies[] = acl
+dependencies[] = content_access
 package = Access control
 
+
+core = 6.x
\ No newline at end of file
Index: handlers/uc_node_access_acl.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_node_access/handlers/uc_node_access_acl.module,v
retrieving revision 1.1
diff -u -p -r1.1 uc_node_access_acl.module
--- handlers/uc_node_access_acl.module	27 Jun 2008 18:21:26 -0000	1.1
+++ handlers/uc_node_access_acl.module	2 Jan 2009 05:56:10 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: uc_node_access_acl.module,v 1.1 2008/06/27 18:21:26 rszrama Exp $
+// $Id$
 
 /**
  * @file
@@ -59,18 +59,16 @@ function ucna_handler_acl_content_access
 /**
  * Implementation of hook_form_alter().
  */
-function uc_node_access_acl_form_alter($form_id, &$form) {
-  if ($form_id == 'content_access_page') {
-    // Get the list of users from the form.
-    $users = unserialize($form['acl']['view']['user_list']['#default_value']);
-
-    // Load up all the expirations for this node and add them to the names.
-    $result = db_query("SELECT uid, expiration FROM {uc_node_access_expirations} WHERE access_nid = %d", $form['node']['#value']->nid);
-    while ($row = db_fetch_array($result)) {
-      $users[$row['uid']] .= ' - '. t('Expires @date', array('@date' => format_date($row['expiration'], 'small')));
-    }
-
-    // Stuff the data back in the form.
-    $form['acl']['view']['user_list']['#default_value'] = serialize($users);
+function uc_node_access_acl_form_content_access_page_alter(&$form, &$form_state, $form_id) {
+  // Get the list of users from the form.
+  $users = unserialize($form['acl']['view']['user_list']['#default_value']);
+
+  // Load up all the expirations for this node and add them to the names.
+  $result = db_query("SELECT uid, expiration FROM {uc_node_access_expirations} WHERE access_nid = %d", $form['node']['#value']->nid);
+  while ($row = db_fetch_array($result)) {
+    $users[$row['uid']] .= ' - '. t('Expires @date', array('@date' => format_date($row['expiration'], 'small')));
   }
+
+  // Stuff the data back in the form.
+  $form['acl']['view']['user_list']['#default_value'] = serialize($users);
 }
