I've wrote a small patch which adds some workflow-ng actions to revision moderation.

I want to be able to schedule the publishing of revisions, however my problem was that revisions are "published" by default. Then I discovered this module, which fixes that :)
So I thought the action "publish a revision" might also suit well to this module. I've also ported the already available actions so that they can be used with workflow-ng too.

Furthermore I've added support for two node token values: revision_moderation and "create new revision" - which are useful together with workflow-ng. E.g. they can be used with the condition "token enabled textual comparison" to get a condition, which checks for newly created content, similar as demanded in this issue: http://drupal.org/node/97802

Comments

fago’s picture

Status: Active » Needs review
StatusFileSize
new3.89 KB

and the patch...

brenda003’s picture

Awesome addition, works as advertised. It took me a while to figure it out being unfamiliar with workflow-ng, but I managed to setup several actions that triggered the publishing of revisions, putting content into moderation, as well as actions triggered by the moderation event themselves, such as emailing a user when a node goes into moderation.

Looks good, though I am curious about having both workflow-ng and the actions module supported since in the end they can achieve similar results.

Some quick instructions since I know others are in need of this functionality and may want to test/use this now - creating a workflow to email specified people when a revision enters moderation:

Create new workflow invoked on event "Content is going to be saved". For the conditions, add a "Textual comparison" with [node:revision_moderation] as the first text, and "on" in the second box. Add action "Send a mail to an arbitrary mail address" and enter the email address(es) there.

+1

fago’s picture

Status: Needs review » Reviewed & tested by the community

thanks for the review and the short usage instructions! I plan to also write an tutorial to show how this can be used to schedule the publishing of revisions.

As there is a positive review now, I set it to RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Code style (all minor things):

- PHP Doc needs to start with /**, not /*
- + * Implementation of hook_action_info() < need periods at the end of each of your PHP Doc descriptions (told you these were minor ;))
- 'node' => array('#entity' => 'node', '#label' => t('Content')), < need formatting as normal arrays, with newlines/indentation rather than storing all in the same row.

This patch is also duplicating code from revision_moderation_actions.inc and possibly from revision_moderation.module as well. What we should do is in cases where exactly the same code is used in more than one place (which appears to be all of the "Implementation of a worklfow-ng action" functions) is move them to generic API functions in the revision_moderation.module and call them from both places.

For example:


// In revision_moderation.module:
/**
 * Enables the revision moderation flag on a node.
 */
function revision_moderation_enable(&$node) {
  $node->revision_moderation = 1;
  // Also enable "Create new revisions" option, in case it isn't yet.
  $node->revision = 1;
}

// In revision_moderation_workflow_ng.inc:
function revision_moderation_action_info() {
  return array(
    'revision_moderation_action_enable' => array( 

...
}

/**
 * Implementation of a worklfow-ng action: enables revision moderation.
 */
revision_moderation_action_enable($node) {
  revision_moderation_enable($node);
  return array('node' => $node);   
}

// in revision_moderation_actions.inc:
function action_revision_moderation_enable($op, $edit = array(), &$node) {
 ...
    case 'do':
      revision_moderation_enable($node);
      node_save($node);
      break;
}

I'd also really prefer if the helper functios for workflow NG were name-spaced workflow NG rather than revision_moderation. If this is the standard, I guess it's ok, but if I committed the patch as-is, for example, it would prevent me from ever adding a function to revision_moderation called revision_moderation_enable, which is kind of silly.

Finally, I'm concerned about how this will work in the 6.x translation when actions is in core. Seems like hook_actions_info is "kind of almost the same but not quite" as hook_hook_info. Is the plan for 6.x for workflow NG to integrate cleanly with 6.x actions, or am I going to need to maintain this separate file again next release?

webchick’s picture

Also, if the token support stuff makes sense outside of Workflow NG's context, that ought to be moved to revision_moderation.module as well.

fago’s picture

thanks for the review. I'll update the patch.

The plan is to rename workflow-ng to trigger2 and to support drupal 6 actions in 6.x. So we don't need to support both in 6.x any more.

@namespace:
Function names like workflow_ng_foo() would tell me that the functions belong to the worklfow-ng module, but these functions belong to revision moderation. So I suggest that we use revision_moderation_workflow_ng_foo(), which is rather long but correct.

fago’s picture

ah I forgot, the patch already adds token support to the module file itself.

webchick’s picture

revision_moderation_workflow_ng_foo() is rather long, but that sounds like a good plan.

And d'oh! sorry, I wasn't reading the patch as closely as I should've. Thanks for pointing out that token support is already in the module file. :)

fago’s picture

Status: Needs work » Needs review
StatusFileSize
new5.25 KB

ok, here is an updated patch.

I've fixed the coding style issues and changed the namespace as discussed. Then I introduced the API functions as you suggested and made use of them in the actions and workflow-ng integration. However I've chosen different names for the API functions to avoid problems with hook_enable() / hook_disable(), which was also a problem with my first patch. Sry for that.

webchick’s picture

StatusFileSize
new5.42 KB

This patch contains some formatting corrections so minor they don't bear mention really.. Just some missing periods at the end of PHPDoc, and stuff like that.

From a visual inspection, this looks good. But I'm going to need a lot more time than I have for the next few weeks in order to test this properly, as the changes require testing token support, making sure the existing actions integration still works, and also testing the new workflow NG integration. Can anyone else lend a hand?

fago’s picture

hm I would do it, but I assume you would prefer a review from another person? :/

webchick’s picture

Indeed. :(

I asked brenda to review this on IRC awhile ago and she seemed interested, but likely just got busy with things. Are there any folks active in the workflow_ng queue who might have an interest?

brenda003’s picture

Status: Needs review » Needs work

I got a chance to do a little testing... I'm getting a duplicate entry error.

user warning: Duplicate entry '9' for key 1 query: INSERT INTO revision_moderation (nid, revision_moderation) VALUES (9, 1) in /home/brenda/web/drupal-5.5-testbed/includes/database.mysql.inc on line 172.

Create a workflow w/ "Content has been created" w/ the action "Enable revision moderation for a content". Then create content and this error occurs. Seems to occur no matter what the settings on the content are (ie, create new revision, revisions into moderation, tested all ways).

No time to really track it down any further at the moment...

fago’s picture

Status: Needs work » Needs review
StatusFileSize
new5.28 KB

hm. I believe, that this error can only occur through a not clean revision_moderation table. I tried your configuration - it worked.

However previously workflow-ng suffered one point: It created a new revision, when something changed (as it uses node_save()). So with your configuration, after node creation, there were already two revisions! I've changed that now, sow that workflow-ng doesn't create new revisions when it applies it changes, even if $node->revision is set. -> Use the latest workflow-ng module to get this behaviour.

Anyway, I looked over the patch again and found an issue with the token integration: It listet its tokens for all entities, as a check for the entity was missing in hook_token_list() -> fixed that, new patch attached.

Here is a simple configuration, which can be used for testing. It just activates each revision that is edited - regardless if it's under moderation.

array (
  'cfg_36' => 
  array (
    '#type' => 'configuration',
    '#altered' => false,
    '#event' => 'node_update',
    '#label' => 'Activate revision',
    '#active' => 1,
    '#module' => 'workflow-ng',
    0 => 
    array (
      '#type' => 'action',
      '#name' => 'revision_moderation_workflow_ng_publish',
      '#argument map' => 
      array (
        'node' => 'node',
      ),
    ),
    '#name' => 'cfg_36',
  ),
)
</pre>

A more useful example follows once this is committed (schedule revision publishing).

fago’s picture

fago’s picture

StatusFileSize
new5.36 KB

I've added another token to the patch: The node's revision id -> updated patch attached

And here is a use case: redirect to a newly created moderated revision.

jbjaaz’s picture

fago,

I'm trying out your latest patch and finding that the "nodes revision id" token does not return the revision id of the latest revision. Instead it is returning the vid of the second to last revision.

After much investigating, I'm pretty sure what is happening is the node:vid token is being cached. So, when you want to access node:vid, for example, in your use case above, the token does not get the newly created revisions' vid because the token is cached with the old vid value.

I added the line

token_get_values('global', NULL, TRUE);

to the function revision_moderation_nodeapi and that seemed to do the trick.

(snippet)

  // Only do this logic for non-admin users on nodes with revision moderation
  // turned on.
  if ($node->nid && $node->revision_moderation == 1 && (!user_access('administer nodes') || !variable_get('revision_moderation_exempt', 1))) {
    switch ($op) {
      case 'prepare':
        ...
      case 'submit':
        ...
      case 'update':
        if (isset($node->original_node)) {
          // Update node table's vid to the original value.
          db_query("UPDATE {node} SET vid = %d, title = '%s', status = %d, moderate = %d WHERE nid = %d", $node->original_node->vid, $node->original_node->title, $node->original_node->status, $node->original_node->moderate, $node->nid);
          drupal_set_message(t('Your changes have been submitted for moderation.'));
        }
        //update token list so the vid token has the latest vid value
        token_get_values('global', NULL, TRUE);      
        break;
    }
  }

Should my added line actually go under the first case "update" in function revision_moderation_nodeapi?

Is there a way to just update the vid token instead of calling token_get_values()?

fago’s picture

thanks, jbaaz. Token caching is not an issue of this patch, but of workflow-ng in general.
but no, afaik you have to clear the whole token cache. Workflow-ng clears the token cache, but only if it detects multiple token use of the e.g. the same node. If another module using token is active, the cached values may result from it. But please create another issue for further discussing this.

Have you else experienced any problems with this patch?

jbjaaz’s picture

Nope, the "vid" token not updating was the only problem I encountered.

I've used everything except the "publish a content revision" and "disable revision moderation for a content" actions.

If I can, I'd like to amend your patch. I desperately needed a way to send an email to the author when their revision was published. So, I created a workflow_ng event called "revision has been published". This event is triggered within the revision_moderation_publish function.

I'm trying to create a patch and can't get it to include revision_moderation_workflow_ng.inc. I'm using tortoisecvs on winxp. I'm working off the HEAD of revision_moderation. I've tried command line too, diff and cvs and can't seem to build a patch similar to yours. Any ideas?

webchick’s picture

you're going to want to patch against DRUPAL-5, not HEAD. HEAD is 6.x-compatible stuff.

webchick’s picture

Also, on Windows, I'd recommend TortoiseCVS. Checkout revision moderation, make your changes, right-click, TortoiseCVS > Create Patch.

jbjaaz’s picture

Thanks for the quick reply. I goofed in my previous comment. I'm actually using tortoiseCVS.

When I create the patch, the following appears at the top
? revision_moderation_workflow_ng.inc

I've tried adding the file to CVS/Entries, but that only made the ? revision_moderation_workflow_ng.inc disappear but not actually include the files contents.

jbjaaz’s picture

Ok, disregard my previous comment (#22). After much hunting, I figured out how to create the patch.

The patch includes the fix I mentioned in comment #17 as well as the workflow_ng event I mentioned in comment #19.

fago’s picture

jbjaaz, thanks for your effort in improving this, but I'd prefer to first get the patch in! If we start to add even more features now, this won't have an end. So let's stop now and concentrate on getting the patch from #16 in!

There are some issues with your code, but let's discuss this later. Let's get it in and then we can go ahead and add more features like this event.

This issue is now about 4 months open and there is even a tutorial based on this work. So what do you think webchick?

jbjaaz’s picture

ok, that's a good plan fago. Do you want me to provide a smaller patch with the fix for comment #17?

fago’s picture

hm no, I'm not sure if it's the right way to fix this. Let's move the token cache discussion over to http://drupal.org/node/208112

jbjaaz’s picture

Sounds good. I reposted my issue to that thread.

webchick’s picture

@fago, as I've said to you before (repeatedly ;)), I'm waiting for reviews on this to bring this to a ready to be committed status. If jbjazz feels the patch in #16 is RTBC, then please set the status accordingly.

jbjaaz’s picture

Status: Needs review » Reviewed & tested by the community

oh, sorry, I'm still learning how the whole drupal collaborative process works.

I've tried out the patch and it's working well for the project I'm working on. But, because of the "vid" token issue, I'm not sure #16 should be committed.

I am very comfortable marking #14 as RTBC.

webchick’s picture

@fago: Does that work for you? If so I can commit this within the next couple days (we're currently in Portland teaching workshops so my availability is a bit spotty)

fago’s picture

yes, it works. I'd recommenced committing #16 - as the vid token works too.

The caching issue isn't resulting from a bad token integration code - jbjaaz just got a cached token. I'll improve workflow-ng's token cache clearing code, but that's another issue.

jconkey’s picture

I found a solution to the vid token issue (#17) that works for me, with minimal testing. I'm just learning the drupal system, so I welcome feedback on this. In my Drupal site, I have a cclinks link "Publish newest revision" which activates the "Publish a content revision" action in workflow-wg. This link shows at the bottom of "page" nodes.

The problem as I see it is that the vid used to create the cclinks URL is taken from the current node version, not the latest revision, since it's called from the cclinks_link hook. I modified revision_moderation_workflow_ng_publish() in revision_moderation_workflow_ng.inc to find the latest revision for the given node:

function revision_moderation_workflow_ng_publish($node) {
  // Get the most recent revision for this node.
  $revisions = revision_moderation_get_node_pending_revisions($node->nid);
  if (!empty($revisions)) {
    reset($revisions);
    $newest_vid = key($revisions);
    db_query("UPDATE {node} SET vid = %d WHERE nid = %d", $newest_vid, $node->nid);
  }
}

An improvement might be to allow choosing which revision to apply, but it seems the latest is a good default.

webchick’s picture

Status: Reviewed & tested by the community » Needs review

Ah, crap. I totally forgot about applying this patch. Really sorry, fago. :(

However, could you look over jconkey's suggested changes and see if they make sense? It'd be neat to get this feature in bug-free. :D

fago’s picture

Status: Needs review » Reviewed & tested by the community

:(

@jconkey:
the action is intended to publish the given revision of the node, and not another one (like the labes describe). So you have to care that you publish the right revision yourself! - What you suggest is an action like "Publish the latest pending revision of content", but that would be a different action.

So again, let's get it in, then we can improve it, by e.g. adding the suggested action. The patch of #16 is still bug free and works as expected.

webchick’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Ok, committed #16 to DRUPAL-5. Needs a port to DRUPAL-6.

toemaz’s picture

Status: Patch (to be ported) » Needs work

The patch from #23 is not applied correctly to D5 dev branch. It didn't include the new revision_moderation_workflow_ng.inc file.
Can we re-roll?

Problem reported in http://drupal.org/node/217475 by Deciphered

webchick’s picture

Status: Needs work » Patch (to be ported)

OMG. Very very sorry. Remind me not to commit things when I'm about to jump on a plane anymore. :P

Anyway, that was just added, so hopefully you'll have better results next time the tarballs are packaged.

actdigital’s picture

Hi everyone. Thank you so much for adding these features, it makes the module really great.
I'm confused about the status of these patches and if/when they are incorporated into the dev or 1.0 versions.
I notice 16 is reviewed and accepted, but is it in 1.0? 23 I know isn't because the workflow-ng.inc isn't included. It is in dev but 1.0 is dated one month later.

I'm a bit confused ;)
If you can help me understand which of these patches have made it into which versions, I would be very grateful.

Thanks for your help!
-Michael

Leeteq’s picture

Subscribing.
(to follow further discussion on this,
PS. for newcomers focused on Drupal v5 - this patch is part of the 1.0 release from 2007-Mar-23, so no need to subscribe to wait for it to be implemented, get the latest main release for Drupal 5x)

Fago: Is the wording on the workflow-ng main page correct or outdated?:

"Modules known to integrate with workflow-ng:
- Revision moderation (in the latest dev snapshot)"

(ref. http://drupal.org/project/workflow_ng)

- If this patch is now in 1.0, is the situation still that people should use the dev snapshot rather than the 1.0 version?

realityloop’s picture

subscribing

Fayna’s picture

Subscribing also. This seems neat!

actdigital’s picture

Hello,
This was working until recently. After a Workflow-ng update, this now gives the error:
"Unable to find action of name revision_moderation_workflow_ng_publish."

I am running a patched version of Revision Moderation that was working until this. I am running Drupal 5.8 and workflow-ng 5.x-2.1.2.

Thank you,
-Michael

add1sun’s picture

Status: Patch (to be ported) » Fixed

workgflow-ng is now rules in D6. I'd rather open a new issue on that altogether.

Both the views.inc and workflow-ng.inc were *not* in the 1.0 release for whatever reason. I have added them to the 5.x-1.1 release now.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

xstaticdev’s picture

Status: Closed (fixed) » Active

Which patch (from which comment #) should I apply to Revision Moderation 5.x-1.2?? I am having problems with the "patch" command successfully applying any of the patches listed to the 5.x-1.2 version of Revision Moderation.

When I try to apply these manually by editing the code, the publishing function seems to work somewhat randomly. When I first make a new revision and schedule it for some date in the future, it publishes the revision IMMEDIATELY. When i edit the newly published revision, and schedule it for another time in the future, it works correctly and waits for cron to run berfore publishing. It's basically flip-flopping between publishing immediately (not waiting for cron to run) and waiting for cron to run.

I am simply trying to schedule the publishing of a revision to a simple page, by the administrator. I do
Can someone supply a correctly patched version or at least point me in the right direction? I've tried the tutorial 5-7 times without success.

Thanks,

Kevin

add1sun’s picture

Status: Active » Closed (fixed)

Er, you shouldn't be applying any patch at all - it is already in the module, which is why it won't apply properly. If 5.x-1.2 isn't working properly with workflow-ng for you, then please open a new issue.