3

Some migrated content needs the "updated" timestamp set to the original timestamp, instead of the time the node was saved duration migration.

Setting the "changed" field in the database appears to have no affect for the node updated time?

Here's a sample query:

update node_field_data set changed = 1535805325 where nid = 2148716;
Query OK, 1 row affected (0.01 sec)
...
select nid,changed,from_unixtime(changed) from node_field_data where nid = 2148716;
+---------+------------+------------------------+
| nid     | changed    | from_unixtime(changed) |
+---------+------------+------------------------+
| 2148716 | 1535805325 | 2018-09-01 12:35:25    |
+---------+------------+------------------------+
1 row in set (0.02 sec)

When loading the node, the original changed timestamp is returned:

[changed] => Array
(
    [x-default] => 1532090833
)

I've tried clearing all caches, including clearing the cache tag and fully restarting the cache services (redis+varnish), but to no avail, the previous changed timestamp is always returned!

Any suggestions on how to set the updated/changed timestamp for this case?

  • 1
    try loading the node and then doing $node->setChangedTime(1535805325)->save(); – No Sssweat Oct 29 '18 at 23:32
  • @NoSssweat thanks for the suggestion and yes that works. However we have a large number of nodes and it's not practical to load and save them all for this case. Looking for an SQL based solution to set the timestamp and the related cache clear if needed for that – David Thomas Oct 29 '18 at 23:51
2

OK, for this approach, the solution was to ensure another table was also updated with the changed timestamp: node_field_revision

e.g:

update node_field_revision set changed = 1535805325 where nid = 2148716 and vid = 2803575;

After that, a normal cache clear showed the new updated timestamp for the node.

  • 1
    Revision crossed my mind, I was also wondering about that. Wanted to make sure $node->setChangedTime() worked before suggesting it. – No Sssweat Oct 30 '18 at 0:39
  • 2
    Thanks yes $node->setChangedTime() does work, but in this case, the SQL update + cache clear took care quickly of the large bulk update. I was also checking node_revision but missed node_field_revision at first, now sorted! – David Thomas Oct 30 '18 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.