How can I make "on publish" be a trigger?

Events happening in the community are now at Drupal community events on www.drupal.org.
blogook's picture

Hi there,

I was reading and almost happy to find http://groups.drupal.org/node/97454 but it seems to be for drupal 6.

I am trying to accomplish the same but then for drupal 7

I am using module scheduler to publish content .. and i cannot figure out how i can have rules detect that when the scheduled content is published to take certain actions (email members that want to be notified when new content is published)

My work around is that when content is changed members are notified, but then everytime i change the content .. all subscribers are notified agiain, and again .. and again

thanks in advance :)

Comments

"Save" event

itangalo's picture

Use the "content is being updated" event, and use conditions to check that (1) the unsaved content was not published and that (2) the updated content is. Tadaa!

Some pretty good guidance to learning Rules can be found here: http://dev.nodeone.se/node/984

Good luck!
//Johan Falk

User roles

blogook's picture

Hi Johan,

Thanks for the info :)

I've got another one for you :)

Some blog postings all users are allowed to read .. and some blog postings a few users are allowed to read .. depending on their user role.

Now ALL users receive an email informing them that new content has been posted, but ofcourse not all users are allowed to read the blog posting.

How do I make it so rules will only sent notifications to those users who are allowed to read that blog?

Looking forward to your reply

W.

after re-reading

blogook's picture

After re-reading your comment

Use the "content is being updated" event, and use conditions to check that (1) the unsaved content was not published and that (2) the updated content is. Tadaa!

how do I check for, unsaved content was not published? .. mainly that word, "unsaved content" .. is nowhere to be found in rules->conditions

I also have to admit that I do not get what you mean .. unsaved content was not published .. when do you not publish unsaved content?

thanks in advance,
W/

Two "data objects" provided to the rule

itangalo's picture

If you are using the "existing content is being updated" event (or something like that), Rules should have two node objects available for running conditions and things – the node as it was before updating it (unsaved), and the node as it is with the updates.

To run these checks, you will need the "data comparison" condition.

The second episode in this screencast series explains this much better than I can do in text: http://dev.nodeone.se/node/984

Good luck!
//Johan Falk, Sweden

About e-mailing

itangalo's picture

When it comes to e-mailing, I think you might want to reconsider how to send e-mails. Rules is not a very good option for sending e-mails to lots of users – you risk having your server blacklisted if you do these kinds of things without knowing a lot about how to send mass e-mails.

However.

If you do want to use Rules to send notifications, you need to find a way to distinguish all the users who are allowed to read the post from those who aren't. If you can do this with Views, for example, then you can use Views Bulk Operations to load all these users into Rules and then e-mail them. (See episode 21 in the series linked above – http://dev.nodeone.se/en/using-vbo-to-load-list-of-objects-into-rules.) This is pretty advanced stuff, though, so I recommend getting really comfortable with using Rules in more basic scenarios first.

I hope this doesn't frighten you too much. :-)

Good luck,
//Johan Falk

My Solution for D7

Beltanin's picture

Just import this...

{ "rules_on_content_publish" : {
    "LABEL" : "On Content Publish",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "NOT data_is" : { "data" : [ "node-unchanged:status" ], "value" : "1" } },
      { "node_is_published" : { "node" : [ "node" ] } }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "This will only show up when content goes from unpublished to published.",
          "repeat" : 0
        }
      }
    ]
  }
}

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: