Similar Issues (?):

I've followed the steps outlined in the second video (part 15). Since there's no fast-forward for videos, I added a summary of the steps to the stub, as well as adding the export of my component + rule to the stub.

Note that this rule first unpublishes the node if it has a future date, then schedules the component to republish it on that future date.

These are the steps I've taken to examine the problem, but I cannot figure out why the scheduled event (which seems to run, as it's deleted after cron) doesn't DO anything...

  1. Create content
  2. Set status to "published"
  3. Set `Authored on` field to 2011-12-08 10:41:00 -0500
  4. Save - node appears unpublished, output of echo date('r') in body content is Thu, 08 Dec 2011 10:40:29 -0500
  5. Rules evaluation log:
    Reacting on event Before saving content.
    
        0 ms Reacting on event Before saving content.
        3.187 ms Evaluating conditions of rule Restrict - Publishing - Deny+Notify. [edit]
        3.806 ms The condition user_has_role evaluated to TRUE [edit]
        3.821 ms AND evaluated to FALSE.
        3.858 ms Evaluating conditions of rule Schedule Publishing. [edit]
        4.726 ms The condition data_is evaluated to TRUE [edit]
        4.741 ms AND evaluated to TRUE.
        " Rule Schedule Publishing fires. [edit]
            0 ms Rule Schedule Publishing fires.
            0.09 ms Evaluating the action node_unpublish. [edit]
            2.72 ms Evaluating the action schedule. [edit]
            3.634 ms Rule Schedule Publishing has fired.
        8.424 ms Finished reacting on event Before saving content.
    
  6. Viewing Rules >> Schedule tab (/admin/config/workflow/rules/schedule) shows 1 task - rules_publish_for_schedule Thu, 12/08/2011 - 10:41 Scheduled publish for node 102
  7. Viewing again at 10:45, body content shows Thu, 08 Dec 2011 10:45:00 -0500, but content is still unpublished.
  8. Running cron manually, rules evaluation log:
    "Scheduled evaluation of action set Publish for Schedule, task Schedule publish for node 102".
        0 ms Scheduled evaluation of action set Publish for Schedule, task Scheduled publish for node 102.
        83.963 ms Evaluating the action data_set. [edit]
        84.105 ms Finished evaluation of action set Publish for Schedule, task Scheduled publish for node 102.
    
  9. Viewing Rules >> Schedule tab (/admin/config/workflow/rules/schedule) shows no tasks scheduled.
  10. Viewing content again, still unpublished, body content is Thu, 08 Dec 2011 10:48:03 -0500, still shows "Submitted by XYZ on Thu, 12/08/2011 - 10:41"

I'm reposting the steps + rule export here, just in case they're not on the source.

Learn the Rules framework part 15: Using fields for setting evaluation time

The following steps are a 'transcript' of the video; attempting to use node:created field to determine publishing

  1. Rules Scheduler >> Component >> Action set
  2. Configure
    • give name like "Publish for Schedule"
    • Datatype: Node, Label: node, Machine name: node, Usage: parameter
    • weight: 10, so it gets run after any other rules
  3. Select the action to add:
    • set a data value
    • node:status
    • value = choose from dropdown
  4. Rules >> create new rule
    • "Publish on Schedule"
    • React on "after saving new content", or "Before saving content" (if you want to edit something later)
    • Add condition
      • data comparison
      • node:created
      • is greater than; now
    • Add Action >> Unpublish
    • Add Action >> Rules scheduler >> "Schedule component evaluation"
    • Pick your component "Publish for Schedule"
    • Scheduled Evaluation Date - enter `node:created` (OR choose offset or enter offset like +X days)
    • Identifier: MUST BE UNIQUE, like "schedule publish for node [node:nid]" - using token for unique action per node
    • Data selector = `node`

EXPORT // -----------------

/****** COMPONENT ******/

{ "rules_publish_for_schedule" : {
    "LABEL" : "Publish for Schedule",
    "PLUGIN" : "action set",
    "TAGS" : [ "publish", "scheduling" ],
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "node" : { "label" : "Node", "type" : "node" } },
    "ACTION SET" : [ { "data_set" : { "data" : [ "node:status" ], "value" : "0" } } ]
  }
}

/****** RULE ******/

{ "rules_schedule_publishing" : {
    "LABEL" : "Schedule Publishing",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "10",
    "TAGS" : [ "publish", "scheduling" ],
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : [ "node_presave" ],
    "IF" : [
      { "OR" : [
          { "data_is" : { "data" : [ "node:changed" ], "op" : "\u003e", "value" : "now" } },
          { "data_is" : { "data" : [ "node:created" ], "op" : "\u003e", "value" : "now" } }
        ]
      }
    ],
    "DO" : [
      { "node_unpublish" : { "node" : [ "node" ] } },
      { "schedule" : {
          "component" : "rules_publish_for_schedule",
          "date" : [ "node:created" ],
          "identifier" : "Scheduled publish for node [node:nid]",
          "param_node" : [ "node" ]
        }
      }
    ]
  }
}

------------------- // EXPORT

Review scheduled tasks (if Views module enabled) from Rules >> Schedule

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dzaus’s picture

As a followup, disabled every rule except for the component scheduler, then manually ran cron with an email as part of the action set. I've confirmed that cron is firing the scheduled component, because I get the email (and see dblog, attached).

But the node is still not getting published!

I'm wondering if this could have anything to do with permission restrictions? Seeing as how the user shown for the Cron job is "Anonymous", where would I look to see if this is the case?

I tried using the Scheduler module, which wasn't working either until I disabled the rules scheduler, then it worked like a charm. So I'm lost here...

tema’s picture

Same here. Does this tutorial work for everyone else?

torgosPizza’s picture

Confirming what you mentioned in the tutorial also - my issue was that I had the "schedule rule component" being triggered by the event "Before saving an order." Deleting it and instead reacting to the events "Updating existing content" and "Saving new content", After updating, the Rules Component works as expected, and my unpublished content becomes published as expected. I wonder if this is a bug or if it's by the design of the node_presave hook?

thomasmurphy’s picture

I haven't found this functionality to work at all. It schedules a task, and then claims in the logs and rules debug output to have completed the action (unpublish in my case) but doesn't actually make the change to the node. The email goes out fine. I've ended up using the scheduler module for this instead.

TR’s picture

Status: Active » Closed (cannot reproduce)
Issue tags: -unpublish, -rules, -publish

To summarize this old issue:

@dzaus says: "Scheduled task doesn't publish content when run"

But the export of the rule that is being used to publish the node, 'rules_publish_for_schedule', shows it is using the data_set action to set node:status = 0. That's UNpublish, not publish, so it makes sense that this rule never publishes the node and apparently does nothing.

@torgosPizza points out correctly that the event you trigger on makes a difference - an incompletely constructed entity in Drupal sometimes can't be modified in the way you want. https://api.drupal.org/api/drupal/modules%21node%21node.api.php/group/no... is the best source of information that I know about what entity hooks get called when. In my experience it is best to use a hook that is called late in the process if you want to set data values.

@thomasmurphy says "I haven't found this functionality to work at all", but that's not actionable information - it tells me nothing about how to reproduce the situation. The counter-evidence is that hundreds of thousands of people use Rules yet there are only a few people who mention problems with the scheduler. While problems certainly exist, it's highly unlikely that scheduler doesn't work at all. That is not my experience either; I use it all the time so it does work for some people.

Likewise, remember that other Rules and other modules also have a say in how an entity is saved. So if you have e.g. some kind of content workflow module on your site, that may be affecting the node:status value after your Rule has run. This is why it's very important to export your Rule and post it so we can try to reproduce it on a clean site - this helps to figure out whether it's a Rules problem or a problem with your site configuration.

Note also the two cited issues: #923776: how do you publish a content type based on a rule with a cck date field that won't keep the time? says publishing works but unpublishing doesn't, which is the exact OPPOSITE of this issue, and #1217328: How to publish content at a certain time after creation says publishing works but has a question about scheduling the time properly.

I am closing this because it is an old issue and all the posts seem to be talking about different things. If you still have problems with the scheduler performing actions, export your rule (simplified so we can use it and reproduce the error with out a ton of other contributed modules) and describe what you're seeing and what you expect. The only one who did that so far is the original poster, and that Rule has the obvious error of setting the node:status to the wrong value.