Skip to content

Immutable datetimes on timestampable #7795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 27, 2025

Conversation

mamazu
Copy link
Contributor

@mamazu mamazu commented Feb 6, 2025

Q A
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? -
Fixed tickets -
Related issues/PRs #7792
License MIT
Documentation PR /

What's in this PR?

Replacing the changed and updated fields to contain immutable datetime objects (see issue).

The interface is now strictly types to only accept DatetimeImmutable as input and return DateTimeInterface as output.

Why?

Technically the created at and updated add should only ever represent "now" and should never be modified.

@mamazu mamazu changed the base branch from 2.6 to 3.0 February 6, 2025 13:50
@mamazu mamazu marked this pull request as draft February 6, 2025 13:50
@mamazu mamazu force-pushed the immutable_datetimes_on_timestampable branch from 2c08acd to 707f59b Compare February 6, 2025 13:59
@mamazu
Copy link
Contributor Author

mamazu commented Feb 6, 2025

Looks like there are a lot of places that use the TimestampableInterface but not the trait. And with Api objects this will not be easily possbile.

@alexander-schranz
Copy link
Member

@mamazu which API entity use the Interface? Most shouldn't as they should be API specific and not extend that interface. The Entities itself should be able to remove current method in the interface as the timestampableinterface already defines the method signature.

@mamazu
Copy link
Contributor Author

mamazu commented Feb 6, 2025

The problem is not the interface its the usage of the trait. Like for example the src/Sulu/Bundle/TagBundle/Entity/Tag.php class does not use the AuditableTrait although the interface extends the AuditableInterface and it can't use the trait because the properties contain meta information in the form of attributes which the trait doesn't have.

@wachterjohannes
Copy link
Member

@alexander-schranz i have rebased the branch, changed the Interface to use \DateTimeImmutable and added a section to the UPGRADE

@mamazu
Copy link
Contributor Author

mamazu commented May 23, 2025

This (#7797) would be a pre-requite for this branch anyways.

@wachterjohannes wachterjohannes force-pushed the immutable_datetimes_on_timestampable branch 4 times, most recently from ca77641 to baa840a Compare May 26, 2025 08:05
@wachterjohannes wachterjohannes force-pushed the immutable_datetimes_on_timestampable branch 3 times, most recently from 44d0934 to 66ef1ed Compare May 26, 2025 17:45
@wachterjohannes wachterjohannes force-pushed the immutable_datetimes_on_timestampable branch from 66ef1ed to d931ae7 Compare May 26, 2025 17:51
@wachterjohannes wachterjohannes marked this pull request as ready for review May 26, 2025 17:51
@alexander-schranz alexander-schranz added the DX Affecting the end developer label May 27, 2025
@wachterjohannes wachterjohannes merged commit b14d772 into sulu:3.0 May 27, 2025
9 checks passed
@mamazu mamazu deleted the immutable_datetimes_on_timestampable branch May 27, 2025 09:10
Comment on lines +656 to +658
> [!WARNING]
> You need to generate a migration for your own project, since this also effects custom entities in your project. For
the Sulu base see migrations below.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wachterjohannes This doesn't only affect the migration in the database. This also means that people need to modify the trash handler for the entity. Maybe we could also handle this in a more general fashion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Affecting the end developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants