2

I've tried the method described at https://groups.drupal.org/node/240678#comment-782543 , but it is not exactly what I need. So i changed it a little bit :

Create a ruleset

Name it "Unpublish Content"

In the Settings/Variables:

  • Data type = "Node"
  • Label = "node"
  • Machine name = "node"
  • Save

... next screen...Add rule

  • Name = "Unpublish Content Rule"
  • Save

  • Conditions (1):

    • Content is published
    • Data selector = node
    • Save
  • Conditions (2):

    • Content is of type = node
    • Value = your-content type
    • Save
  • Actions:

    • Unpublish content
    • Data selector = node
    • Save

Create a rule

  • using /admin/config/workflow/rules

  • Name = "Unpublish Rule"

  • React on event = After saving new content
  • Save

  • Conditions:

    • Content is of type
    • Data selector = node
    • Value = your-content-type
    • Save
  • Actions:

    • Schedule component evaluation
    • Component Value = Unpublish Content
    • Data selector = site:current-date <-- "This is what I changed, I want the node to be unpublished 50 days after it's creation."
    • Identifier value = unpublish [node:nid] <-- removed this.
    • node Data selector = node
    • Save

But I don't have date field.

I have tried many methods but nothing seems to work, I don't want to use other modules like Auto Expire.

Any suggestions to get this to work?

2

Have you looked into Rules Scheduler? The process is similar in that you create your rule, create a component that unpublished content, then use Rules Scheduler in the original rule as the action to run the component 50 days after "date published". Here is a video of scheduling nodes to be published after X time that you can follow: http://www.youtube.com/watch?v=OgRKLXRbPX8 .

1

Use the Rules module together with Rules Scheduler (a sub-module of it), as explained in the steps below. These steps use content type = article, instead of your-content-type.

Step 1: Create a Rules "Component"

Here is the Rules Component to be created (in Rules export format, just import it in your own environment via copy-paste):

{ "rules_unpublish_a_node" : {
    "LABEL" : "Unpublish a node",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "node" : { "label" : "node", "type" : "node" } },
    "ACTION SET" : [ { "node_unpublish" : { "node" : [ "node" ] } } ]
  }
}

Step 2: Create a "Rule" using the Rules Component

Here is the Rule to be created, in Rules export format (just import it in your own environment via copy-paste):

{ "rules_unpublish_nodes_after_50_days" : {
    "LABEL" : "Unpublish nodes after 50 days",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : { "node_insert" : [] },
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "article" : "article" } } } }
    ],
    "DO" : [
      { "schedule" : {
          "component" : "rules_unpublish_a_node",
          "date" : "+50 days",
          "identifier" : "Unpublish node with node ID [node:nid]",
          "param_node" : [ "node" ]
        }
      }
    ]
  }
}

Note that the above rule refers to the Rules Component from the previous step. It's in Rules export format, just import it in your own environment via copy-paste (after you adapted article in it to fit the machine name of your content type).

Possible refinement

You didn't specify what should happen if at first a node gets created, but as "unpublished" (instead of "published"). And later on such node is updated, and is changed from "unpublished" to "published". Depending on what you'd want to happen in that case, you may have to further refine the Rules Event and/or Rules Condition (eg: add "Content is published").

Conclusion

  • So you only need a (rather basic) Action Set (as in in my Step 1).
  • You don't need some date field (as in your question), you simply use a relative date like "+50 days".

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.