There is a small bug in node.module

When a node is being created, if it is previewed before being submitted, $node->created and $node->changed are DIFFERENT. ($node->created is set to the time when Preview was clicked; $node->changed is set to the time when Submit was clicked.) In this case, they should be the same.

My patch sets $node->changed to $node->created if the node has never been changed (meaning that it is in the process of being created).

Please view the patch file... it will make all of this more clear.

I originally ran across this bug while working on another patch, which I would really like to see make it into 4.7. It is a simple change... it gives the user an option of adding a "last revised" tag to the submission line. Please check it out and consider it for 4.7.

Thanks!
-Steve

CommentFileSizeAuthor
#5 node_preview_2.patch857 bytesshouchen
node_preview_1.patch1.01 KBshouchen

Comments

shouchen’s picture

Sorry... the problem exists in 4.7.0-beta2, but the patch is valid for the current node.module in HEAD.

morbus iff’s picture

I'd turn this into a ternary:

$node->changed = !$node->changed ? $node->created : time();

Lot smaller.

morbus iff’s picture

Actually, flip 'em:

$node->changed = $node->changed ? time() : $node->created;

shouchen’s picture

Status: Active » Needs review
shouchen’s picture

StatusFileSize
new857 bytes

Great idea... thanks!

Steven’s picture

Status: Needs review » Fixed

Committed to HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)
shouchen’s picture

Version: » 4.6.6
Status: Closed (fixed) » Active

This bug was reintroduced by http://drupal.org/node/52710

Steven’s picture

Status: Active » Closed (works as designed)

Node->changed is an internal variable used for bookkeeping around revisions and search indexes. If you use it for display, that's your problem.

However, if you don't enter anything in the "authored on" field on node creation, the changed date should be the same as created though (function node_save())

  // Set some required fields:
  if (empty($node->created)) {
    $node->created = time();
  }
  // The changed timestamp is always updated for bookkeeping purposes (revisions, searching, ...)
  $node->changed = time();