Difficulty getting Rules Scheduler in D7 to publish a node in the future I've set up rules to defer publishing on node save to a specified date. The rules component successfully runs at the later date and sends an email alert to the node author to let them know that their node has been published. But the rules component does not succeed in actually publishing the node.

I am pretty confident that the component works OK, because if I execute it directly, providing the node id as the content identifier (using direct input mode), it works as expected, i.e. sends the email alert and publishes the node.

The issue arises only when the component is run by cron. My best guess - drawing on this stackoverflow Q&amp;A - is that this may be connected to cron, on D7, always being run as the anonymous user.

I'm puzzled, however. There are several D7 discussions around of how to use Rules to defer publishing, e.g. this Drupal Answers Q&amp;A or this drupal.org comment (about using this approach on D7 - it is a comment on a D6 page). The fact that neither of these mention any issue with the anonymous user, make me wonder if I'm getting something very basic wrong and/or have an unusual configuration. It would seem odd that Rules Scheduler couldn't, more or less out of the box, achieve deferred publishing.

I've looked at the 'Configure access for using this component with a permission' option for the component and tried out various settings of that without fixing the issue. I'm not clear I understand the function of this option and haven't found any documentation / Q&amp;As so far that have helped.

For reference, the rules component (that works when executed manually using the node id, but send the email without publishing the node when triggered by cron) is (when exported) as follows:

{ "rules_publish_content" : {
    "LABEL" : "Delayed publish action",
    "PLUGIN" : "rule set",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "delayed_node" : { "label" : "Delayed node", "type" : "node" } },
    "RULES" : [
      { "RULE" : {
          "IF" : [
            { "node_is_of_type" : {
                "node" : [ "delayed-node" ],
                "type" : { "value" : { "news" : "news" } }
              }
            },
            { "NOT node_is_published" : { "node" : [ "delayed-node" ] } }
          ],
          "DO" : [
            { "mail" : {
                "to" : [ "delayed-node:author:mail" ],
                "subject" : "Your item, \u0022[delayed-node:title]\u0022, has been published.",
                "message" : "Your item, \u0022[delayed-node:title]\u0022, has been published.\r\n\r\n[delayed-node:url]\r\n\r\nnode id: [delayed-node:nid]\r\n\r\nnode date: [delayed-node:field-date]\r\n\r\nnode status: [delayed-node:status]\r\n",
                "language" : [ "" ]
              }
            },
            { "node_publish" : { "node" : [ "delayed-node" ] } }
          ],
          "LABEL" : "Delayed publishing: publish and alert"
        }
      }
    ]
  }
}
It turns out the concern about cron running under Anonymous user was a red herring. Thanks @Patrick Kenny for encouraging more persistent logging. 

Diagnosis: the reaction rule that was scheduling the component was triggered by a 'Before saving content' event. In my testing - because of my faulty theory about the cause of the problem - I was repeatedly using an already created node. As such, the node nid was successfully passed to the component and so in logging (and in inspecting the list of scheduled rules) everything looked OK. And the alert email was even correctly generated. It turns out, however, that when the component is scheduled from a reaction rule triggered by a 'Before saving content' event, then changes to the node are not saved when the component executes.  So some things works with the parameter passed from a 'Before saving content' triggered reaction rule, but not others. And for the things that don't work no error or issue is flagged in logging. Glad to know that now.

For anyone coming here just wanting some Rules to import to get delayed publishing up and running, here is the exported component and two exported rules that do the job.

Component to publish a node

In my use case, I also had a check for a specific node type. If you need to add that, add an extra condition after importing the component. (Import the component at: admin/config/workflow/rules/components)

{ "rules_publish_content" : {
    "LABEL" : "Delayed publish action",
    "PLUGIN" : "rule set",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "delayed_node" : { "label" : "Delayed node", "type" : "node" } },
    "RULES" : [
      { "RULE" : {
          "IF" : [ { "NOT node_is_published" : { "node" : [ "delayed-node" ] } } ],
          "DO" : [
            { "node_publish" : { "node" : [ "delayed-node" ] } },
            { "mail" : {
                "to" : [ "delayed-node:author:mail" ],
                "subject" : "Your item, \u0022[delayed-node:title]\u0022, has been published.",
                "message" : "Your item, \u0022[delayed-node:title]\u0022, has been published.\r\n\r\n[delayed-node:url]\r\n",
                "language" : [ "" ]
              }
            }
          ],
          "LABEL" : "Delayed publishing: publish and alert"
        }
      }
    ]
  }
}


Rule to trigger delayed publication when authored on date is in the future

In my use case, I also had a check for a specific node type. If you need to add that, add an extra condition after importing the rule. (Import the component at: /admin/config/workflow/rules). In addition, in my use case, I looked at a specific date field on the content type rather than the node:created, i.e. 'Authored on', value. If you want to do that then, after doing the import, add a new condition that checks your added date field and remove the condition that checks the standard Drupal created date field.

{ "rules_publish_node_future" : {
    "LABEL" : "Publish node (in the future)",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : [ "node_insert", "node_update" ],
    "IF" : [
      { "data_is" : { "data" : [ "node:created" ], "op" : "\u003E", "value" : "now" } }
    ],
    "DO" : [
      { "node_unpublish" : { "node" : [ "node" ] } },
      { "schedule" : {
          "component" : "rules_publish_content",
          "date" : [ "node:created" ],
          "identifier" : "Delay publication of node: [node:nid]",
          "param_delayed_node" : [ "node" ]
        }
      },
      { "drupal_message" : {
          "message" : "\u003Cstrong\u003EPublishing will be delayed until (up to 3 hours) after: [node:created:long].\u003C\/strong\u003E This is because the \u0027Authored on\u0027 date you entered for your item is in the future. If you need to publish now then edit the item, change \u0027Authored on\u0027 date to now or earlier, set the item to be \u0027Published\u0027, and save.",
          "type" : "warning"
        }
      },
      { "mail" : {
          "to" : [ "node:author:mail" ],
          "subject" : "\u0022[node:title]\u0022 publication will be delayed until [node:field-date]",
          "message" : "\u0022[node:title]\u0022 publication will be delayed until (up to 3 hours) after: [node:created:long].\r\n\r\n[node:url]\r\n\r\nYou have received this message because the \u0027Authored on\u0027 date you entered for your item is in the future. If you need to publish now then edit the item, change \u0027Authored on\u0027 date to now or earlier, set the item to be \u0027Published\u0027, and save.",
          "language" : [ "" ]
        }
      }
    ]
  }
}


Rule to cancel delayed publication if node is saved with a date in the past

This rule cancels any scheduled publication of the node. It does not set the node to be published. Depending on your setup, you might want to add an action to this rule to publish the node.

{ "rules_publish_node_future_cancel" : {
    "LABEL" : "Publish node (in the future cancellation)",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "NOT data_is" : { "data" : [ "node:created" ], "op" : "\u003E", "value" : "now" } }
    ],
    "DO" : [
      { "schedule_delete" : {
          "component" : "rules_publish_content",
          "task" : "Delay publication of node: [node:nid]"
        }
      }
    ]
  }
}