Update Entity Timestamp if possible

Created on 22 October 2020, about 4 years ago
Updated 2 September 2024, 3 months ago

Problem/Motivation

If the Entity used by an EntityResource implements `EntityChangedInterface` this is not updated when a patch method is used to update the entity via the rest API.

Steps to reproduce

Create an entity that implements EntityChangedInterface and a subclass of EntityResource which uses this Entity. Update the entity via the rest API, the updated timestamp is not modified.

Proposed resolution

This is a fairly simple enhancment

Before the entity is saved in the Patch method

if ($original_entity instanceof EntityChangedInterface) {
      $original_entity->setChangedTime(time());
    }

This is a core interface so it would be nice to see it supported.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Postponed: needs info

Version

11.0 🔥

Component
REST 

Last updated 7 days ago

Created by

🇬🇧United Kingdom JeremyFrench

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    Was previously tagged for tests which still need to happen.

  • 🇮🇳India rksyravi New Delhi, 🇮🇳

    Hi @jernejmramor

    Update the changes and create a MR(Merge Request), because Drupal recommends MR over patch file.

  • last update 10 months ago
    26,067 pass, 1,836 fail
  • First commit to issue fork.
  • Assigned to akshaydalvi212
  • 🇮🇳India akshaydalvi212

    Hey,
    will provide the MR for the updating Entity timestamp.

  • Merge request !6548Added Timestamp for Entity. → (Open) created by akshaydalvi212
  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • 🇮🇳India akshaydalvi212

    hey,
    MR is raised,
    kindly review and test the MR.

  • Pipeline finished with Success
    9 months ago
    Total: 478s
    #92731
  • Status changed to Needs work 9 months ago
  • 🇺🇸United States smustgrave

    Was previously tagged for tests which still need to happen.

  • 🇺🇸United States Farnoosh

    I performed Novice Triage on this issue. I am leaving the Novice tag on this issue because we still need to test the MR.

  • 🇺🇸United States xjm

    To be clear, the task is to add test coverage to the MR (a test that fails before the fix and passes with it). Thanks!

  • Pipeline finished with Failed
    3 months ago
    Total: 219s
    #271534
  • Status changed to Postponed: needs info 3 months ago
  • 🇸🇮Slovenia jernejmramor

    I've tried replicating this issue again by creating a new custom module which adds an Entity that extended EntityChangedInterface, and exposed a rest endpoint with custom rest resource plugin that extended EntityResource. Using postman API I then created a new entity using POST method, and updated the same entity with PATCH method. Every successful update of an entity is also reflected in updated 'changed' value in the database.
    I've also tried replicating this behavior using bundle-able custom entities and even then 'changed' value was always updated in database as expected.

    If this is still an issue, please provide a more detailed set of replication steps so that we can provide tests and solution for this issue. I'm committing an updated patch form what is currently in the open MR so that plugin uses DI for the time service. I'm also changing the status to Postponed (maintainer needs more info) as the issue is 4 years old, and is no longer replicate-able (at least by me).

  • Pipeline finished with Failed
    3 months ago
    Total: 555s
    #271573
Production build 0.71.5 2024