It'd be great if there was a setting in workflow to have the Drupal published time to match the workflow state change time. The 'scheduler' module has a feature similar to this in the content type setting called "Alter Publishing Time - Check this box to alter the published on time to match the scheduled time ("touch feature").".

I have articles that sit in a workflow state called "submitted" or "reviewed" for several days/weeks before being moved to the "published" state and then they never appear on the homepage because the drupal publishing date/time is the date/time when it was originally created.

CommentFileSizeAuthor
#3 workflow.creation-date-action.patch1.13 KBjhedstrom

Comments

shariharan’s picture

subscribing

mglover’s picture

I ended up doing this (on 6.x) with a custom action. I assigned it to my workflow for all state changes to my Published state and it updates the creation date to match the scheduled timestamp. At first I was was just changing creation date to now(), but that ends up setting most posts to match my cron timing.

Here's my code. This is my first custom action, so please feel free to improve on it.

function myaction_action_info() {
  return array(
    'node_update_date_action' => array(
      'description' => t('Update node creation date to match scheduled workflow state change'),
      'type' => 'node',
      'configurable' => FALSE,
      'hooks' => array('nodeapi' => array('presave', 'insert', 'update')),
      )
  );
}

function node_update_date_action(&$node, $context = array()) {
  $node->created = $node->_workflow_scheduled_timestamp;
   node_save($node);
  watchdog('action', 'Update @type %title creation datestamp to scheduled publication time.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
}
jhedstrom’s picture

Version: 5.x-2.3 » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.13 KB

I've added slightly modified code from #2 as an attached patch to 6.x.

stattler’s picture

This patch has no effect on node creation date, i.e., it does not change the creation date to the "published" date. Does it mean that the file was not patched correctly? I followed the correct way of patching and it confirmed that the patch was done.

Went to drupal root/sites/all/modules/workflow

and then did:

patch < patch.file.name

fivehimself’s picture

This is exactly what I'm looking for! I've added this code to my template.php, but couldn't find the action in my actions or trigger page...

Could you tell me where to put this code?

vood002’s picture

Thanks for the code, works great for me.

I changed it a little bit since I don't publish all my content from workflow date:

<?php
function my_module_node_update_date_action(&$node, $context = array()) {
	$node->created = now();
	if (isset($node->_workflow_scheduled_timestamp) && $node->_workflow_scheduled_timestamp != '')
	{
	$node->created = $node->_workflow_scheduled_timestamp;
	}
	node_save($node);
	watchdog('action', 'Update @type %title creation datestamp.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
}
?>

fivehimself: i dont think this will work out of template.php, i added it to a custom module that I just throw all my random functions into.

finex’s picture

The modified patch by vood002 looks fine... and why not add an explicit checkbox to use that date (like the scheduler module) ?

hillaryneaf’s picture

Using vood002's code, I get:
Fatal error: Call to undefined function now()

hillaryneaf’s picture

I couldn't get vood002's code to work, the if statements always returned false.

In the custom module I made, I just checked if the node has a workflow state assigned to it like this:

/**
* Implementation of hook_action_info().
*/
function my_module_action_info() {
  return array(
    'my_module_node_update_date_action' => array(
      'description' => t('Update node creation date to match scheduled workflow state change'),
      'type' => 'node',
      'configurable' => FALSE,
      'hooks' => array('nodeapi' => array('presave', 'insert', 'update')),
      )
  );
}

function my_module_node_update_date_action(&$node, $context = array()) {
    if ($node->_workflow != ''){
		$node->created = $node->_workflow_scheduled_timestamp;
	}
    node_save($node);
    watchdog('action', 'Update @type %title creation datestamp to scheduled publication time.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
}

Hope this helps someone!

jrstmartin’s picture

@nektir and @mglover

Thank you! Works great with Workflow 1.5 and Rules.

johnv’s picture

Component: Code » Rules
Issue summary: View changes

re-classifying as a Rules/Actions & Triggers issue.

johnv’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Category: Feature request » Support request

Moving all remaining D6 issues to D7.
In general, Workflow only changes its own state. Changing other fields/properties should be done using hooks/Rules/Actions.
We might add default actions, but ATM, reclassifying this as a Support Request as a help for other users.

johnv’s picture

Title: Drupal post date becomes workflow state change date » Let node's 'published' date become Workflow state change date
Status: Needs review » Active

Renaming title. The patch is outdated. A new attempt is welcome.

johnv’s picture

Version: 7.x-2.x-dev » 8.x-1.x-dev
arun.mytimez’s picture

I am not an expert, but for a similar scenario I had used the Publication Date (publication_date) module along with the Rules module.

The Publication Date module adds a datetime field to the publish section of the form which can be set manually or use the Rules module to define rule to set the publication field to the date when the required state is set. I had created a rule to set this date to the systems current datetime value and set the drupal default publish checkbox to true when the workflow field has got the publish state when the form is saved.

The export of the rules definition is as below.

{ "rules_publish_content_on_workflow" : {
    "LABEL" : "Publish Connections Article",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "publish" ],
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave--ship_news" : { "bundle" : "ship_news" } },
    "IF" : [
      { "data_is" : { "data" : [ "node:field-employee-sub-workflow" ], "value" : "28" } }
    ],
    "DO" : [
      { "node_publish" : { "node" : [ "node" ] } },
      { "data_set" : { "data" : [ "node:published-at" ], "value" : [ "site:current-date" ] } }
    ]
  }
}

Maybe you can work on similar lines to get your requirements met.

johnv’s picture

Title: Let node's 'published' date become Workflow state change date » Set node's 'published' date to Workflow state change date
Related issues: +#294000: Set node's 'published' date to Workflow state change date

In D8 the contrib module Workflow State Configuration is a good candidate to include this feature.
See #294000: Set node's 'published' date to Workflow state change date.

socialnicheguru’s picture

also there is the scheduler module

johnv’s picture

Category: Support request » Feature request
Status: Active » Fixed

I am not sure where/when it was introduced, but ITMT we have implemented a Workflow Option "Always update the entity last updated timestamp".

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.