HasLifecycleCallbacks doesn't work on User class #5741

Open
opened 2026-01-22 15:16:08 +01:00 by admin · 2 comments
Owner

Originally created by @CharpentierAlexandre on GitHub (Oct 13, 2017).

My lifecycle callbacks doesn't work at all... Please anyone can help me? hereunder my class User (part of it which is relevant):

<?php

namespace XXX\UserBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface as AUI;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder as pwd;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @ORM\Table(name="epnak_App_User")
* @ORM\Entity(repositoryClass="epnak\UserBundle\Repository\UserRepository")
* @ORM\HasLifecycleCallbacks()
*/
class User extends BaseUser implements UserInterface, AUI {

   /**
    * @ORM\Column(name="id", type="integer")
    * @ORM\Id
    * @ORM\GeneratedValue(strategy="AUTO")
    */
   protected $id;

   /**
    * @var \DateTime
    * @ORM\Column(name="last_update_at", type="datetime")
    * 
    */
   public $last_update_at;

   /**
    * Set lastUpdateAt
    *
    * @param \DateTime $lastUpdateAt
    * @ORM\PrePersist()
    * @ORM\PreUpdate()
    * @return User
    */
   public function setLastUpdateAt($lastUpdateAt) {
       $this->last_update_at = new \DateTime();

       return $this;
   }

   /**
    * Get lastUpdateAt
    *
    * @return \DateTime
    */
   public function getLastUpdateAt() {
       return $this->last_update_at;
   }

}

Thank to everyone whom could help me going further.

Originally created by @CharpentierAlexandre on GitHub (Oct 13, 2017). My lifecycle callbacks doesn't work at all... Please anyone can help me? hereunder my class User (part of it which is relevant): ```php <?php namespace XXX\UserBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\AdvancedUserInterface as AUI; use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder as pwd; use Doctrine\ORM\Mapping as ORM; use FOS\UserBundle\Model\User as BaseUser; use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Table(name="epnak_App_User") * @ORM\Entity(repositoryClass="epnak\UserBundle\Repository\UserRepository") * @ORM\HasLifecycleCallbacks() */ class User extends BaseUser implements UserInterface, AUI { /** * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @var \DateTime * @ORM\Column(name="last_update_at", type="datetime") * */ public $last_update_at; /** * Set lastUpdateAt * * @param \DateTime $lastUpdateAt * @ORM\PrePersist() * @ORM\PreUpdate() * @return User */ public function setLastUpdateAt($lastUpdateAt) { $this->last_update_at = new \DateTime(); return $this; } /** * Get lastUpdateAt * * @return \DateTime */ public function getLastUpdateAt() { return $this->last_update_at; } } ``` Thank to everyone whom could help me going further.
Author
Owner

@Ocramius commented on GitHub (Oct 13, 2017):

Don't see anything wrong with it, but is it actually being updated? Can you maybe check if the lifecycle event listeners are somewhere in the object that you can dump from $em->getClassMetadata(\XXX\UserBundle\Entity\User::class)?

@Ocramius commented on GitHub (Oct 13, 2017): Don't see anything wrong with it, but is it actually being updated? Can you maybe check if the lifecycle event listeners are somewhere in the object that you can dump from `$em->getClassMetadata(\XXX\UserBundle\Entity\User::class)`?
Author
Owner

@CharpentierAlexandre commented on GitHub (Oct 14, 2017):

@Ocramius I use FosUserBundle then I thought that the event listener were already parameterized for this feature. Should I override the listener to handle the lifecycle?

Do you mean my entity would have not been really updated as understood by FOS (on Flush)?

Thank you a lot!

@CharpentierAlexandre commented on GitHub (Oct 14, 2017): @Ocramius I use FosUserBundle then I thought that the event listener were already parameterized for this feature. Should I override the listener to handle the lifecycle? Do you mean my entity would have not been really updated as understood by FOS (on Flush)? Thank you a lot!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5741