Skip to content

Commit

Permalink
wip : multiple configuration for orm 3 or ORM 2
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Mar 21, 2024
1 parent f8c5fba commit d157a05
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/reference/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down
30 changes: 30 additions & 0 deletions src/Entity/BaseUser3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* 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();
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/doctrine/BaseUser.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<field name="lastLogin" column="last_login" type="datetime" nullable="true"/>
<field name="confirmationToken" column="confirmation_token" type="string" length="180" unique="true" nullable="true"/>
<field name="passwordRequestedAt" column="password_requested_at" type="datetime" nullable="true"/>
<field name="roles" column="roles" type="json"/>
<field name="roles" column="roles" type="array"/>
<field name="createdAt" type="datetime" column="created_at"/>
<field name="updatedAt" type="datetime" column="updated_at"/>
<lifecycle-callbacks>
Expand Down
22 changes: 22 additions & 0 deletions src/Resources/config/doctrine/BaseUser.orm3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<mapped-superclass name="Sonata\UserBundle\Entity\BaseUser3">
<field name="username" column="username" type="string" length="180"/>
<field name="usernameCanonical" column="username_canonical" type="string" length="180" unique="true"/>
<field name="email" column="email" type="string" length="180"/>
<field name="emailCanonical" column="email_canonical" type="string" length="180" unique="true"/>
<field name="enabled" column="enabled" type="boolean"/>
<field name="salt" column="salt" type="string" nullable="true"/>
<field name="password" column="password" type="string"/>
<field name="lastLogin" column="last_login" type="datetime" nullable="true"/>
<field name="confirmationToken" column="confirmation_token" type="string" length="180" unique="true" nullable="true"/>
<field name="passwordRequestedAt" column="password_requested_at" type="datetime" nullable="true"/>
<field name="roles" column="roles" type="json"/>
<field name="createdAt" type="datetime" column="created_at"/>
<field name="updatedAt" type="datetime" column="updated_at"/>
<lifecycle-callbacks>
<lifecycle-callback type="prePersist" method="prePersist"/>
<lifecycle-callback type="preUpdate" method="preUpdate"/>
</lifecycle-callbacks>
</mapped-superclass>
</doctrine-mapping>

0 comments on commit d157a05

Please sign in to comment.