DDC-3944: [GH-1532] Update ClassMetadataInfo.php #4824

Closed
opened 2026-01-22 14:50:02 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 9, 2015).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of cybermo:

Url: https://github.com/doctrine/doctrine2/pull/1532

Message:

Ability to remove a lifecycle callback.
This is useful in order to disable a callback method on specific cases.
Exemple with TimeStampable and updateTimestamps callback method:
When a user connect to the website, some attributes get updated automatically like last_logged_time...etc.
The object will see it's updated_at changed which is correct from the object point of view.
But it is not correct from the functional point of view, because none updated that user object.

public function updateLoggedInDateTime(User $user)
{
    $user->setLastLoggedAt(new \DateTime());
    ...        
    // remove lifecycle methodes to not update updated_at field
    //         array:2 [▼
    //             "prePersist" => array:1 [▼
    //                 0 => "updateTimestamps"
    //             ]
    //             "preUpdate" => array:1 [▼
    //                 0 => "updateTimestamps"
    //             ]
    //         ]        
    $this->entityManager->getClassMetadata(get_class($user))->removeLifecycleCallback('updateTimestamps', 'prePersist');
    $this->entityManager->getClassMetadata(get_class($user))->removeLifecycleCallback('updateTimestamps', 'preUpdate');  


    $this->entityManager->transactional(function($em) use ($user) {
    $em->persist($user);
    });
}

So in this particular situation, there will be no date time updating in updated_at.

Originally created by @doctrinebot on GitHub (Oct 9, 2015). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user @doctrinebot: This issue is created automatically through a Github pull request on behalf of cybermo: Url: https://github.com/doctrine/doctrine2/pull/1532 Message: Ability to remove a lifecycle callback. This is useful in order to disable a callback method on specific cases. Exemple with TimeStampable and updateTimestamps callback method: When a user connect to the website, some attributes get updated automatically like last_logged_time...etc. The object will see it's updated_at changed which is correct from the object point of view. But it is not correct from the functional point of view, because none updated that user object. ``` public function updateLoggedInDateTime(User $user) { $user->setLastLoggedAt(new \DateTime()); ... // remove lifecycle methodes to not update updated_at field // array:2 [▼ // "prePersist" => array:1 [▼ // 0 => "updateTimestamps" // ] // "preUpdate" => array:1 [▼ // 0 => "updateTimestamps" // ] // ] $this->entityManager->getClassMetadata(get_class($user))->removeLifecycleCallback('updateTimestamps', 'prePersist'); $this->entityManager->getClassMetadata(get_class($user))->removeLifecycleCallback('updateTimestamps', 'preUpdate'); $this->entityManager->transactional(function($em) use ($user) { $em->persist($user); }); } ``` So in this particular situation, there will be no date time updating in updated_at.
admin added the New Feature label 2026-01-22 14:50:02 +01:00
admin closed this issue 2026-01-22 14:50:02 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 25, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1532] was assigned:
https://github.com/doctrine/doctrine2/pull/1532

@doctrinebot commented on GitHub (Oct 25, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1532] was assigned: https://github.com/doctrine/doctrine2/pull/1532
Author
Owner

@doctrinebot commented on GitHub (Oct 25, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1532] was closed:
https://github.com/doctrine/doctrine2/pull/1532

@doctrinebot commented on GitHub (Oct 25, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1532] was closed: https://github.com/doctrine/doctrine2/pull/1532
Author
Owner

@doctrinebot commented on GitHub (Oct 25, 2015):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Oct 25, 2015): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4824