I have this code that updates a node in a queue worker:
$changed = $entity->getChangedTime(); // Don't update the changed time by $entity->setChangedTime($changed); $entity->set('my_field', "my_data"); $entity->setNewRevision(FALSE); $entity->save();
Here is a screenshot of xdebug showing
after_save value with the relevant code:
But no matter what I do, the changed property keeps getting updated to the time of the update.
I tested the functionality in a different contenxt like:
$node = Node::load($nid); $changed_time = new DrupalDateTime('2022-01-01 12:00:00'); $timestamp = $changed_time->getTimestamp(); $node->setChangedTime($timestamp); $node->save();
and this seem to work.
Why does my code in the queue worker fail to do the same thing? is it because it's updating a field value?
$changed = $entity->getChangedTime();?
$node->setChangedTime($timestamp);should do it. but you may be right, if it's changed then it's always updating it.