I've been floundering through the documentation and examples, and have tried searches on various relevant terms, but I haven't found anything that seems to equate to what I need to do, which is:

A - Create a scheduleable rule to publish a specific revision of a node. This can be done using "execute custom php code", but it needs to know the revision to publish.

B - Create triggered rules for new and updated content that schedule the publish-revision rule. When these rules are triggered, I need to pass the current revision id for the node through to the scheduled rule.

Note that between create/update time and scheduled publish time, other revisions of the node may be created, so simply publishing the latest (or current) revision at scheduled time is not sufficient. I have to know what the revision id was at save/update time.

A couple of possibilities come to mind:

1 - At first I thought creating a new number variable at trigger time might be the way to go, but it seems that variables created then are not available to the scheduled rule, right?

2 - Can I get the "user-supplied" task identifier from within php code in the scheduled rule? If so, I can store the revision ID there and parse it out at scheduled time.

3 - Or? Is there something I'm missing?

Any advice or pointers to documentation/examples appreciated, thanks.

Comments

johnpitcairn’s picture

Well, I got something working.

I had to create a small module to provide a new Rules event "a new moderated revision was created", and new action "published specified revision".

These supply and require (respectively) an additional "number" argument, the node revision id at the time the revision is created. This can then be passed through the Rules UI as an argument, and stored by the Rules Scheduler.

This avoids the problem of getting node->vid from the "content" variable, which appears to be obtained from node_load(), and therefore returns the "current" (published) revision id, not the specified (unpublished, moderated) revision id.

I'll post sample code on request - I'm using the Revisioning module (D6).

lrichards’s picture

Hi John,

I'm running into a similar problem with Revision Moderation and Scheduler that I think could be solved with something like your custom module with similar Rules/Actions. Would you mind posting your sample code?

Thanks!

johnpitcairn’s picture

This code uses the Revisioning module for the function _revisioning_publish_revision().

It adds a Rules event/action combo with an extra available argument - the new revision vid - and fires the event trigger from the hook_nodeapi() insert and update operations. The argument must be specified in your Rule Set and your Triggered Rule, so it will be stored for later use by the Scheduler.

<?php
/**
 * Implementation of hook_nodeapi().
 */
function mymodule_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {    
    case 'update':
    case 'insert':
      if ($node->revision && $node->revision_moderation) {
        // invoke the rules action
        if (module_exists('rules')) {
          rules_invoke_event('mymodule_rules_event_pending_revision_created', $node, $node->vid); 
        }
      }
    
      break;
  }
}

/**
 * Implementation of hook_rules_event_info().
 */
function mymodule_rules_event_info() {
  return array(
    'mymodule_rules_event_pending_revision_created' => array(
      'label' => t('New pending revision created'),
      'module' => 'My Module',
      'arguments' => array(
        'node' => array('type' => 'node', 'label' => t('Content')),
        'vid' => array('type' => 'number', 'label' => t('Revision ID')),
      ),
    ),
  );
}

/**
 * Implementation of hook_rules_action_info().
 */
function mymodule_rules_action_info() {
   return array(
    'mymodule_rules_action_publish_revision' => array(
      'label' => t('Publish the specified revision'),
      'module' => 'My Module',
      'arguments' => array(
        'node' => array('type' => 'node', 'label' => t('Content')),
        'vid' => array('type' => 'number', 'label' => t('Revision ID')),
      ),
    ),
  );
}

/**
 * Action: publish specified revision.
 *
 * @note, no checks for appropriate Revisioning permissions are performed
 */
function mymodule_rules_action_publish_revision($node, $vid) {
  _revisioning_publish_revision($node->nid, $vid);
}
lrichards’s picture

Thanks John, should be a great start for us!

itangalo’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.