Skip to content

Commit d646f09

Browse files
authoredApr 18, 2024
Compatibility with doctrine dbal 4 (#1677)
1 parent 1fe5aa8 commit d646f09

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed
 

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"dama/doctrine-test-bundle": "^7.0",
5252
"doctrine/doctrine-bundle": "^2.7",
5353
"doctrine/mongodb-odm": "^2.3",
54-
"doctrine/orm": "^2.14",
54+
"doctrine/orm": "^2.14 || ^3.0",
5555
"egulias/email-validator": "^3.1 || ^4.0",
5656
"friendsofphp/php-cs-fixer": "^3.4",
5757
"matthiasnoback/symfony-config-test": "^4.2",

‎docs/reference/installation.rst

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ And then create the corresponding entity, ``src/Entity/SonataUserUser``::
8282
use Doctrine\DBAL\Types\Types;
8383
use Doctrine\ORM\Mapping as ORM;
8484
use Sonata\UserBundle\Entity\BaseUser;
85+
// or `Sonata\UserBundle\Entity\BaseUser3` as BaseUser if you upgrade to doctrine/orm ^3
8586

8687
#[ORM\Entity]
8788
#[ORM\Table(name: 'user__user')]

‎src/Entity/BaseUser3.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Sonata Project package.
7+
*
8+
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Sonata\UserBundle\Entity;
15+
16+
use Sonata\UserBundle\Model\User as AbstractedUser;
17+
18+
class BaseUser3 extends AbstractedUser
19+
{
20+
public function prePersist(): void
21+
{
22+
$this->createdAt = new \DateTime();
23+
$this->updatedAt = new \DateTime();
24+
}
25+
26+
public function preUpdate(): void
27+
{
28+
$this->updatedAt = new \DateTime();
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
3+
<mapped-superclass name="Sonata\UserBundle\Entity\BaseUser3">
4+
<field name="username" column="username" type="string" length="180"/>
5+
<field name="usernameCanonical" column="username_canonical" type="string" length="180" unique="true"/>
6+
<field name="email" column="email" type="string" length="180"/>
7+
<field name="emailCanonical" column="email_canonical" type="string" length="180" unique="true"/>
8+
<field name="enabled" column="enabled" type="boolean"/>
9+
<field name="salt" column="salt" type="string" nullable="true"/>
10+
<field name="password" column="password" type="string"/>
11+
<field name="lastLogin" column="last_login" type="datetime" nullable="true"/>
12+
<field name="confirmationToken" column="confirmation_token" type="string" length="180" unique="true" nullable="true"/>
13+
<field name="passwordRequestedAt" column="password_requested_at" type="datetime" nullable="true"/>
14+
<field name="roles" column="roles" type="json"/>
15+
<field name="createdAt" type="datetime" column="created_at"/>
16+
<field name="updatedAt" type="datetime" column="updated_at"/>
17+
<lifecycle-callbacks>
18+
<lifecycle-callback type="prePersist" method="prePersist"/>
19+
<lifecycle-callback type="preUpdate" method="preUpdate"/>
20+
</lifecycle-callbacks>
21+
</mapped-superclass>
22+
</doctrine-mapping>

0 commit comments

Comments
 (0)