Using Rules to update content date

Events happening in the community are now at Drupal community events on www.drupal.org.
nocean's picture

I'm looking for information on how to setup Rules to automatically update the "created on" date of a node to the current date and time when that node is changed from "unpublished" to "published".

Basically, the site accepts content from registered users, which is not published until an admin/moderator reviews it. Upon review, the node's status is changed from "unpublished" to "published". At that moment, I'm trying to configure Rules to update the node's creation date to the current date and time (so that its creation date is the time it was published, not actually created).

Anyone know how this can be done?

Comments

scheduler module

esbon's picture

I had the same need, but I could not find a solution so I switched to the scheduler module which has a check box that changes the authored on date to be the same as the published on date. I would still like to do this with the Rules module though.

With the scheduler module it

nocean's picture

With the scheduler module it automates the actual publishing right? Digging through the Rules how-tos and following a few of them, it really feels like this is possible with Rules -- all the elements seem to be there. I just can't seem to connect the proper wires to make it all happen.

It is possible!

fathershawn's picture

It is possible! Here's how:
Use a Custom PHP action. In the action edit screen you should see a collapsible section titled PHP Evaluation. This section will disclose the variable name for your content. In my case it is $publish_content__content. So, in the PHP Code box I put:

$publish_content__content->created = time();
return $publish_content__content;

Which set's the created field to the current time whenever the rule is fired.

Drupaling in NYC since 2009!

This didn't work for me

arrow's picture

This didn't work for me, but I was able to change the variable to $node and then it worked. Thanks for getting me as far as you did though!

I was able to accomplish changing the "Authored on" date/time using the following:

$node->created = time();
return $node;

Explain in detail please

Jean Gionet's picture

Can somebody please explain me in detail how this can be accomplished?

I have a CCK field named field_published_datetime. When this is set I want the creation_date of the node to be updated with field_published_datetime value.

I'm fairly new to using rules and triggers.

thanks!

Going to work on this

mikeytown2's picture

http://drupal.org/node/1175776

Will let ya know when its ready.

New action in Rules Bonus Pack!

itangalo's picture

Inspired by this thread I created a new action in Rules Bonus PackSet node creation time. It allows you to send in a time expression, or defaults to current time, and sets that creation time for a given node. Quick and easy.

Cheers!
//Johan Falk
**
Learn Drupal with Nodeone! Drupal 7 introduction | The Views module | Learn Page manager! | Drupal configuration learning curve | Rules for Drupal 6 | Theming Drupal 6 | 49 Drupal 6 modules you should know

aseabrook's picture

I wasn't able to find them in the actions list for Rules D7.

Itango, any chance you would

liliplanet's picture

Itango, any chance you would kindly include the rule for set node creation time in the rules bonus pack? Most appreciated :)

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week