2

I am using Craft 3 to populate content over a REST api. Now I have a use case, where I want to update an internal field of an entry without changing the dateUpdated. Otherwise the clients would get informed about an update, but it is just for internal/system use.

Can I somehow save an entry without changing the dateUpdated or do I need to find another solution for my use case?

Volker Andres
  • 232
  • 3
  • 13
  • Have you tried updating the field manually in the database via phpMyAdmin or similar? – Chattervast Dec 19 '18 at 12:47
  • @IndigoViking No. The timestamp is saved at at least 3 tables (entries, content and elements). I would like to stay in the Craft Context and would wish for something like ->saveElement($entry, $dontUpdateTimestamp = true). I tried to hook into the save process with "Event::on(Elements::class, Elements::EVENT_BEFORE_SAVE_ELEMENT, function (Event $event)" but there is already the new timestamp and I can not manual overwrite it – Volker Andres Dec 19 '18 at 16:02

1 Answers1

1

Otherwise the clients would get informed about an update, but it is just for internal/system use.

It sounds like you're relying on the dateUpdated column to notify clients of updates, which probably isn't a good idea.

Plugins can update it, migrations can update it, re-saving a section's settings can update it, etc.

Instead, I would add a custom date/time field and have a plugin that listens to the save element event that updates your custom field with that last "date updated" instead and base your notifications off of that.

Brad Bell
  • 67,440
  • 6
  • 73
  • 143
  • Thank you Brad. How can I differentiate then, when a save comes from the CP or let's say from a cronjob? The latter should not update the timestamp – Volker Andres Dec 19 '18 at 18:55
  • Pass in a querystring param from the cron job and have your plugin check for its existence? – Brad Bell Dec 19 '18 at 22:14