I want to send an email to a user when the user's earlier unpublished content is published by somebody else (site administrator, moderator, etc).
I tried doing it with Rules but could not figure out how.
Any help?
I want to send an email to a user when the user's earlier unpublished content is published by somebody else (site administrator, moderator, etc).
I tried doing it with Rules but could not figure out how.
Any help?
Programmatically it is easy to do:
On a custom module create a custom table: entity_notifications
https://api.drupal.org/api/drupal/includes%21database%21schema.inc/group/schemaapi/7
Entity_id: Integer Entity_type: varchar | SENT: Boolean
/**
* Implements hook_schema().
*/
function custommodule_schema() {
$schema = array();
$schema['entity_notifications'] = array(
'description' => 'The base table for entity notifications.',
'fields' => array(
'entity_id' => array(
'description' => 'The primary identifier for the entity.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'entity_type' => array(
'description' => 'Bundle',
'type' => 'varchar',
),
'sent' => array(
'description' => 'Boolean indicating whether a email has been sent.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
),
)
'primary key' => array('entity_id', 'entity_type'),
);
return $schema;
}
Control node status on hook_node_save or presave:
https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_presave/7
function custommodule_node_save($node){
// @TODO: compare $node->status vs $node->original->status (Check first than $node->original exists
// @TODO: if current status is == "1" and original "0" check that in the DB is not checked
// @TODO: send email and write to DB that this has been sent (db_query)!
https://stackoverflow.com/questions/11986683/how-to-send-email-in-drupal-7 }
Another approach could be using module flag: https://drupal.org/project/flag
The Workflow module can do it exactly what you want. By using this module you can trigger different action at each flow of content.
Workflows are made up of workflow states. Transitions between states can be allowed per role. For example, a workflow with the states Draft, Review, and Published could be assigned to the Story node type. Only users with role 'chief editor' can set Stories to the published state. You can set up the Workflow to alter states from form, page, comment and a special workflow tab.
Use two Data Comparison conditions.
One should compare node:unchanged with a status of unpublished. The other should compare node:updated wit ha status of published.
Then fire your action.
The prior answer from filmoreha is close, but a bit incomplete. It does not take into account the "by somebody else" part of your question, and does not mention any Rules Event(s) or Rules Action(s).
Here is a rule (in Rules export format) that can be used to send an email to the node author after the node is published:
{ "rules_send_email_after_node_is_published" : {
"LABEL" : "Send email after node is published",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "node_update" : [] },
"IF" : [
{ "data_is" : { "data" : [ "node-unchanged:status" ], "value" : "0" } },
{ "data_is" : { "data" : [ "node:status" ], "value" : "1" } },
{ "NOT data_is" : {
"data" : [ "node-unchanged:author:uid" ],
"value" : [ "site:current-user:uid" ]
}
}
],
"DO" : [
{ "mail" : {
"to" : [ "node-unchanged:author:mail" ],
"subject" : "Your content is published ...",
"message" : "This is to inform you that your node (with node id = [node-unchanged:nid] and node title = [node-unchanged:title]) has been plublished ...",
"language" : [ "" ]
}
}
]
}
}
If you have the Rules UI enabled, you should be able to import the above rule in your own site.
Some more details about this rule:
Obviously, you could add other Rules Conditions (eg to check the role of the user performing the update), but at its core this rule will get the job done.