Skip to content

Commit

Permalink
new configuration for orm 3
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Mar 23, 2024
1 parent 17be6e9 commit f5e4577
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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/BaseUser3.orm.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 f5e4577

Please sign in to comment.