1

We are using workflow moderation for some content types and sent out emails to the author once a node has been published.

Sometimes we have the case that an author changes a node after he has been published. When this revision gets published we want to send out a different email.

I have tried many different things but I haven't been able to find a way how to determine if this was the first time the node is published or a subsequent publish. Can someone please point me in the right direction how this can be achieved?

Thanks

3

This is how I would try doing it:

  • create a field for the content type named first_publish, boolean, hidden, default value 0
  • create a Rule that when that content type is published, as a condition if first_publish is 0, first_publish becomes 1, add email output to user
  • create a second Rule that when the content type is published, as a condition if first_publish is 1, send out a different email

This will use a data field as a variable that follows the node - the rules will trigger appropriately depending on the conditions of whether or not the variable is set, giving different outcomes.

| improve this answer | |
  • Thanks Geoff, this is one of the things I tried, however I am unable to see this field in the rules - maybe I am missing something. The field is called field_publish and I try to access it node:field_publish via Data Comparison in the rule. I can't see any fields that I have created? – borntosucceed Aug 11 '14 at 10:33
  • if you havent already, clear the cache. if you type in node and select the 'node:...' does anything come up in the list? – Geoff Aug 11 '14 at 13:35
  • Ok thanks Geoff, worked it out. Basically I had the rule fire when saving all node types. When I restrict the node type only the one in question than all custom fields come up. Was hoping I can handle two or three content types in one go, well just need to write a different rule for each of them. – borntosucceed Aug 13 '14 at 11:56
0

I found another way to do this if you don't want to add an extra field to the node.

In Rules add a condition of type "Execute custom PHP code".

Then in the PHP code field add the following:

$times_published = db_query('select count(nid) from node_revision where status = 1 and nid = ' . $node->nid)->fetchField();
return ($times_published < 2);

This checks for the number of published revision entries for that node.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.