Skip to content
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

[Blameable][Timestampable] Inconsistent behaviour of 'on="change"' and 'on="update"' #2023

Open
senaria opened this issue Jun 6, 2019 · 5 comments
Labels
Blameable Still Relevant Mark PRs that might've been auto-closed that are still relevant. Timestampable

Comments

@senaria
Copy link

senaria commented Jun 6, 2019

There seems to be inconsistent behaviour between on="change" and on="update". When persisting a new entity with change the field is left as null. With 'update` it is filled. Since they are interchangeable i would expect them to function the same.

Let's assume we have the following setup:

class A {
	private $name;

    /**
     * @Gedmo\Blameable(on="update")
     */
	private $updatedAt;

    [... some other properties]
}

class B {
	private $name;

    /**
     * @Gedmo\Blameable(on="change", fields={"name"})
     */
	private $updatedAt;

    [... some other properties]
}

I want to use on="update" for class A because I do not want to define a list of every property of class A. On the other hand I need to use on="change" for class B to be able to exclude some properties.

This results in a new record of A setting the updatedAt but a new record of B won't.

I discovered #1920 which will make change also set the value. This would be ok as it is then at least consistent. It would however be preferable to change update so that it does not set the variable because technically it is not updated but created. Then it would be useful to allow 2 annotations (create and update) if you want to also set it on creation.

Can we make them consistent? I would be happy to contribute if you like.

@AkenRoberts
Copy link
Member

I agree that there is an opportunity for a better solution, since this is a pretty common scenario.

TL;DR: I don't think we can make this work without breaking changes and a new major release, which is unlikely given the current efforts to maintain this library. Try giving $updatedAt a value in your entity's constructor when using change.


Unfortunately the only way I see it happening is by making breaking changes, either to the functionality of the change config, or to annotations / configuration to allow multiple events to be configured (which I think is the better solution). For example:

class B {
    /**
     * @var string
     */
    private $name;

    /**
     * @Gedmo\Blameable(onCreate=true)
     *
     * @var \DateTimeInterface
     */
    private $createdAt;

    /**
     * @Gedmo\Blameable(onCreate=true, onChange={"name"})
     *
     * @var \DateTimeInterface
     */
    private $modifiedAt;
}

The problem with breaking changes comes down to people resources and maintenance. The original authors of Doctrine Extensions have all moved on, and the couple of us here trying to keep up with issues and occasional bugs can only do so much with the existing library. A new major release just doesn't seem likely.

Giving $updatedAt a default value in your entity's constructor should give it a value when using on="change", while retaining the other on-change event functionality. If that doesn't work, let me know.

Otherwise, a couple of us are trying to make some headway on a brand new modern version over at https://github.com/doctrine-extensions/doctrine-extensions, if you're interested in contributing your thoughts or code!

@yakobe
Copy link

yakobe commented Jul 18, 2019

I agree that breaking changes are needed. That's not a bad thing... things move forward and old things get retired. 👍

I find it a shame that a new repo is needed to achieve it. With semver this should be possible here. Even if it starts to rapidly increase major version numbers; people can always use an older version until they are able to upgrade. In the long run people will be happier.

@AkenRoberts
Copy link
Member

It could definitely be done here still, there just isn't anyone willing to put the time in.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@AkenRoberts
Copy link
Member

@franmomu This might be worth revisiting whenever there's focus on significant updates 👍🏼

@franmomu franmomu added Timestampable Blameable Still Relevant Mark PRs that might've been auto-closed that are still relevant. and removed Stale labels Mar 26, 2022
@franmomu franmomu reopened this Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blameable Still Relevant Mark PRs that might've been auto-closed that are still relevant. Timestampable
Projects
None yet
Development

No branches or pull requests

4 participants