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
Disable timestampable auto-updating on certain update #1722
Comments
please respect my time and do not open support issues |
Okay. private function disableTimestampable()
{
$listenerInst = null;
$evm = $this->em->getEventManager();
foreach ($evm->getListeners() as $event => $listeners) {
foreach ($listeners as $hash => $listener) {
if ($listener instanceof \Gedmo\Timestampable\TimestampableListener) {
$listenerInst = $listener;
$evm->removeEventListener(array('prePersist','loadClassMetadata','onFlush'), $listenerInst);
}
}
}
} It's really an ugly fix. And I would like to ask if it is possible to create in the Can we discuss about this ? Thank you for your help btw! |
Would be nice to see an exclude property in the /**
* @var \DateTime
*
* @Gedmo\Timestampable(on="update", exclude="inactiveAt")
* @ORM\Column(name="updated_at", type="datetime")
* @Serializer\Expose
*/
private $updatedAt; Exclude could accept single field or array. |
There is also much nicer solution by implementing own listener. Which allow to cancel event by own rules most easily per entity instance. Cancel event listener is really ugly and unpredictable solution. I also like @LoicProust solution something like |
Solution proposed by @zajca works like a charm. Thanks! |
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. |
for those who will always search, the new syntax |
Hi,
I'm really stuck with this and I tried a lots of thing but not successfully. First, I would like to disable the timestampable behavior on certain update. (For example, I want to set inactiveAt if updatedAt is 6-months expire from today, but I don't want to reset the updatedAt by setting inactiveAt).
So I have a my
trait TimestampableEntity
:And I use it in my Entity:
use TimestampableEntity;
It works like a charm and updates the updatedAt field everytime I made change on my entity.
Now, I want to disable this behavior for my scenario with inactiveAt:
So I tried everything I found on the internet:
Here is my last try and I think I am closed to the solution but the updatedAt is still updated...
If someone can help on this.
Thanks in advance!
Regards
The text was updated successfully, but these errors were encountered: