Workbench moderation currently does not have a rules condition to check if a node was previously published. This would suit instances where it is required for an email notification to be sent one time only and that would be when the content is first published.

The only other condition that comes close to this is "Content's current moderation state" but this would cause unnecessary emails being sent to users since it does not check the moderation history.

This patch simply adds the new condition to workbench_moderation.rules.inc and uses the workbench_moderation_node_history table to get the moderation history.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrrfakier’s picture

Status: Needs review » Needs work

The last submitted patch, 1: workbench_moderation-rules-condition-2313071-1.patch, failed testing.

phergo’s picture

Hi tlp027,

Your patch doesn't work for me. Your 'if' sentence always returns TRUE when a node is 'published' at first time. We have modified your patch in order to fix it.

Thanks a lot. Your patch was very helpful ;).

phergo’s picture

Status: Needs work » Needs review
Anybody’s picture

Status: Needs review » Reviewed & tested by the community

Thanks a lot for this patch.
Patch #3 applies cleanly against the latest .dev version and works great!

This is really really helpful and I needed it for example to give points to users and to create an other entity. Please apply this patch to the module.

mstrelan’s picture

That's a bit convoluted. How about this.

<?php
  $count = db_select('workbench_moderation_node_history', 'n')
    ->fields('n', array('nid', 'state'))
    ->condition('n.nid', $node->nid, '=')
    ->condition('n.vid', $node->vid, '!=')
    ->condition('n.state', 'published', '=')
    ->countQuery()
    ->execute()
    ->fetchField();
  return (bool) $count;
?>

The vid condition negates the need for $node->workbench_moderation['current']->state. And the try/catch is not really necessary.

ronaldmulero’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.92 KB

Based on the original description of this issue: that the Action should be triggered "one time only and that would be when the content is first published", none of the above solutions worked for me.

mrrfakier #1 was the closest, but only worked if
if ( $count == 1 && ($node->workbench_moderation['current']->state == 'published') ) { was changed to
if ( $count == 1 && ($node->workbench_moderation['current']->state != 'published') ) { or else it triggered every time the node was republished.

phergo #3 is more coding standards compliant, but didn't work for me.

mstrelan suggested change in #6 is cleaner, but also triggered every time the node was republished.

I rolled a hybrid patch of all 3, updating the condition label and function name along the way. The following Rules workflow only triggers the Action the first time a node is published and never again.

Events: 
  After moderation transition
Conditions: 
  Entity is of type
    Parameter: Entity: [node], Entity type: Content
  Check if node was only published once.
    Parameter: Content: [node]
Actions:
  (whatever)

Needs tests.