From ee1bc2411f4f4ec026fd57846c5c7290f389f9e1 Mon Sep 17 00:00:00 2001 From: RobinDev Date: Thu, 21 Mar 2024 09:11:18 +0100 Subject: [PATCH] new configuration for orm 3 --- composer.json | 2 +- docs/reference/installation.rst | 1 + src/Entity/BaseUser3.php | 30 +++++++++++++++++++ .../config/doctrine/BaseUser.orm.xml | 2 +- .../config/doctrine/BaseUser3.orm.xml | 22 ++++++++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/Entity/BaseUser3.php create mode 100644 src/Resources/config/doctrine/BaseUser3.orm.xml diff --git a/composer.json b/composer.json index bcb54ef38..b6b5ea66c 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "dama/doctrine-test-bundle": "^7.0", "doctrine/doctrine-bundle": "^2.7", "doctrine/mongodb-odm": "^2.3", - "doctrine/orm": "^2.13 || ^3.0", + "doctrine/orm": "^2.14 || ^3.0", "egulias/email-validator": "^3.1 || ^4.0", "friendsofphp/php-cs-fixer": "^3.4", "matthiasnoback/symfony-config-test": "^4.2", diff --git a/docs/reference/installation.rst b/docs/reference/installation.rst index f43353c4c..f318a65a8 100644 --- a/docs/reference/installation.rst +++ b/docs/reference/installation.rst @@ -82,6 +82,7 @@ And then create the corresponding entity, ``src/Entity/SonataUserUser``:: use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Sonata\UserBundle\Entity\BaseUser; + // or `Sonata\UserBundle\Entity\BaseUser3` as BaseUser if you upgrade to doctrine/orm ^3 #[ORM\Entity] #[ORM\Table(name: 'user__user')] diff --git a/src/Entity/BaseUser3.php b/src/Entity/BaseUser3.php new file mode 100644 index 000000000..1969326b4 --- /dev/null +++ b/src/Entity/BaseUser3.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\UserBundle\Entity; + +use Sonata\UserBundle\Model\User as AbstractedUser; + +class BaseUser3 extends AbstractedUser +{ + public function prePersist(): void + { + $this->createdAt = new \DateTime(); + $this->updatedAt = new \DateTime(); + } + + public function preUpdate(): void + { + $this->updatedAt = new \DateTime(); + } +} diff --git a/src/Resources/config/doctrine/BaseUser.orm.xml b/src/Resources/config/doctrine/BaseUser.orm.xml index 11d5ec41f..92ae3d230 100644 --- a/src/Resources/config/doctrine/BaseUser.orm.xml +++ b/src/Resources/config/doctrine/BaseUser.orm.xml @@ -11,7 +11,7 @@ - + diff --git a/src/Resources/config/doctrine/BaseUser3.orm.xml b/src/Resources/config/doctrine/BaseUser3.orm.xml new file mode 100644 index 000000000..6ebf323c6 --- /dev/null +++ b/src/Resources/config/doctrine/BaseUser3.orm.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +