3
votes

OK... let me start by saying I know there is a similar post here (How to create a Drupal rule to check (on cron) a date field and if passed set field "status" to "ended"?) but the answer on that post does not work. Step 4 (In the component add the condition 'Data comparison' and select node:type) does not work or even exists as an option.

What I need to do is this:

On Cron > If content type is event and the end date has passed the current date then change the status field from Active to Ended. (select list)

I was able to do this by using the Event: Content is viewed but I really need to to work when cron is ran.

Side note: with the current version I have (Content is viewed) it does change Active to Ended but it also for some reason deletes the title of the node which is strange becuase the title filed is required by Drupal... any idea wht that is happening?

Not sure if it helps but here is an export of what I have done myself:

{ "rules_event_status" : {
    "LABEL" : "Event Status",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "REQUIRES" : [ "rules", "php" ],
    "ON" : [ "node_view" ],
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "event" : "event" } } } },
      { "AND" : [] },
      { "php_eval" : { "code" : "\/\/dpm(strtotime($node-\u003Efield_event_date_time[LANGUAGE_NONE][0][\u0027value2\u0027]));\r\nif (time() \u003E strtotime($node-\u003Efield_event_date_time[LANGUAGE_NONE][0][\u0027value2\u0027]))\r\n{\r\n    return true;\r\n}" } }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "node:field-event-status" ], "value" : "Ended" } }
    ]
  }
}

Any help is very much appreciated.

Thanks

C

2

2 Answers

1
votes

to use any custom fields or fields created by other modules than node, you have to add condition "entity has field" to your rules which will make that field "visible" and accesible for later work

side note: I think you can do the date comparison without php_eval, just add another entity has field condition and create "data comparison" condition. There should be tokens available to your needs

0
votes

Not sure I fully understand the question: rules can be triggered by cron.

You should be able to get it to run when cron executes by picking the "React on event" attribute of the rule to "System > Cron maintenance tasks are executed".

Am I missing something?