Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We allow callers of node_save() to set own created date and even nid but not changed date (i.e. last modified). There is no justification for this inflexibility. Its needed when migrating content to drupal.
Comment | File | Size | Author |
---|---|---|---|
#23 | 722688-23.patch | 3.18 KB | jpmckinney |
#8 | 722688-8.patch | 2.71 KB | jpmckinney |
changed.diff | 866 bytes | moshe weitzman | |
Comments
Comment #1
catchI think I remember adding a patch to do this elsewhere, but I don't think I'd be able to find it. It's a tiny change, doesn't break any APIs, RTBC pending test bot.
Comment #2
webchickThis makes sense to me, and is consistent with us doing the same thing to $node->created this release. I've hit this before, too, I believe.
Committed to HEAD.
Comment #3
coltrane$node->changed was the goal of #322759: Allow hook_node_presave() to alter other node fields but maybe this route is better and that one can be set to duplicate (and it didn't need a test which stalled my patch ;)
Comment #4
webchickBAD core maintainer. NO banana!
Actually, moshe, what do you think? Coltrane's patch does indeed seem to be a more holistic way to deal with this, rather than one-offing certain properties.
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedI'm fine with coltrane's patch. I don't think it is a big deal either way.
Comment #6
mikeryanThe original approach in this issue (plus the equivalent change to preserve $node->uid) seems preferable to me. It's simpler (at least in our use case) just to pass the desired changed/uid in the node object rather than implement a presave hook to stuff them in later. Also, what if a prepare hook is keying off these values? Well, I guess the answer there is to implement the prepare hook rather than the presave hook....
Comment #7
catchI think if anything we should eventually moved the REQUEST_TIME hunks out of node_save() - so you'd do something like node_add_defaults($node); node_save($node); if you want those values added.
Comment #8
jpmckinney CreditAttribution: jpmckinney commentedWhile reviewing #761482: Incorrect sorting in admin/content/node, I noticed that this patch introduced a serious error. Consider these lines:
If saving a new node, $node->changed will be set to REQUEST_TIME (assuming no contrib code is programatically setting it).
If saving an existing node, $node->changed will not be updated to REQUEST_TIME, because $node->changed is not empty (although it should be updated, as documented in the code comment!).
I wrote one failing test for all to witness.
This is why tests are good!
Comment #9
jpmckinney CreditAttribution: jpmckinney commentedComment #10
jpmckinney CreditAttribution: jpmckinney commentedAs for actually fixing this problem, it looks like we need a different way of programmatically setting $node->changed. Perhaps:
So, if you want to programmatically set $node->changed, you set $node->changed_new (or pick your own attribute name, I don't care what we call it).
Comment #11
rfaysubscribe
Comment #13
andypostMarked as duplicate #761482: Incorrect sorting in admin/content/node
Comment #14
catchPretty sure this is only needed on insert so why not check ->is_new there?
Comment #15
jpmckinney CreditAttribution: jpmckinney commentedIf the people behind the first patch just want to set changed on insert, then that would be an elegant solution.
Comment #16
andypost@catch Take a look to #761482: Incorrect sorting in admin/content/node
Setting on insert make no sense because changed == created on insert and could be only used in contrib.
But trouble when user updates node - The only possible way to query "real change timestamp" is query {node_revision}.timestamp
So right now we have broken admin/content/node
Comment #17
jpmckinney CreditAttribution: jpmckinney commentedI think catch meant that the ability to programmatically set $node->changed is only needed on insert. So, I can imagine the code working like this:
Comment #18
mikeryanThe ability to explicitly set the changed value on update is useful when migrating nodes from external data.
Comment #19
andypostWhen node is edited then "Authored on" always populated with value
EDIT: not sure about "Authored on" because it's name is "date" so "changed" should be empty... but it's not
Comment #20
coltraneIn #322759: Allow hook_node_presave() to alter other node fields the implementation was just to move the invocation of the presave hook lower, so changed could be altered by modules implementing the presave hook. This would solve mikeryan's specific use case.
Comment #21
jpmckinney CreditAttribution: jpmckinney commentedAs per #20, I think it may be best to revert the patch in the OP and explore #322759: Allow hook_node_presave() to alter other node fields as a way to address people's migration issues. (We should also commit some of my tests in #8 :).
Comment #22
moshe weitzman CreditAttribution: moshe weitzman commentedi'm ok with #20
Comment #23
jpmckinney CreditAttribution: jpmckinney commentedAlright, I'm backing the original patch out and providing the functionality requested in the OP in #322759: Allow hook_node_presave() to alter other node fields.
A problem in the tests is that I can't assert that the "changed" timestamp has changed, because REQUEST_TIME is constant between tests. But that is not a commit-blocking problem.
Comment #24
jpmckinney CreditAttribution: jpmckinney commentedComment #25
jpmckinney CreditAttribution: jpmckinney commentedMarking duplicate of #322759: Allow hook_node_presave() to alter other node fields, where I back out the original patch in this issue, and provide the functionality requested in this issue's OP.
Comment #26
catchSince this conflicts with #322759: Allow hook_node_presave() to alter other node fields and that other issue is RTBC apart from a comment nitpick, I'm marking this as duplicate.
Comment #27
andypostSo I reopen #761482-5: Incorrect sorting in admin/content/node