makinacorpus / DbToolsBundle

A PHP library to backup, restore and anonymize databases
https://dbtoolsbundle.readthedocs.io
MIT License
182 stars 15 forks source link

Problem with Doctrine Xml configuration and Embed #101

Closed thibaut-algrin closed 8 months ago

thibaut-algrin commented 9 months ago

In a Symfony project, I use Doctrine ORM. I use XML configuration for mapping between entities and the MySQL database.

I have, in particular, a User entity which includes an embed:

<!--src/Authentication/Infrastructure/Doctrine/Mapping/User.orm.xml-->
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping">
    <entity name="App\Authentication\Domain\Model\User" table="users">
        <gedmo:soft-deleteable field-name="dateDeleted" time-aware="false" hard-delete="true" />

        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
            <sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
        </id>
        <field name="familyName" length="255" />
        <field name="firstName" length="255" />
        <field name="username" length="255" unique="true" />
        <field name="uuid" length="255" unique="true" />
        <field name="roles" type="json" />
        <field name="password" length="255" />
        <field name="status" type="json" />
        <embedded name="token" class="App\Authentication\Domain\Model\Embedded\Token" />
        <field name="googleId" length="255" nullable="true" />
        <field name="lastLogin" type="datetime" nullable="true" />

        <!-- SoftDeletableTrait -->
        <field name="dateDeleted" type="datetime" nullable="true" />
        <field name="deletedBy" length="255" nullable="true" />
        <!-- /SoftDeletableTrait -->

        <!-- TimestampableTrait -->
        <field name="dateCreated" type="datetime">
            <gedmo:timestampable on="create"/>
        </field>
        <field name="dateModified" type="datetime">
            <gedmo:timestampable on="update"/>
        </field>
        <!-- /TimestampableTrait -->
    </entity>
</doctrine-mapping>
<!--src/Authentication/Infrastructure/Doctrine/Mapping/Embedded.Token.orm.xml-->
<?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="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <embeddable name="App\Authentication\Domain\Model\Embedded\Token">
        <field name="value" length="255"  nullable="true" />
        <field name="expiredAt" type="datetime" nullable="true" />
    </embeddable>
</doctrine-mapping>

Here is the bundle configuration:

# config/packages/db_tools.yaml
db_tools:
   anonymization:
      yaml:
         default: "%kernel.project_dir%/src/Authentication/Infrastructure/DbTools/user.yaml"
#src/Authentication/Infrastructure/DbTools/user.yaml
users:
   family_name: lastname
   first_name: firstname
   username: email

When I run the command: ./bin/console db-tools:anonymize --local-database --no-restore

I have this error:

In AttributesLoader.php line 53:

  Property App\Authentication\Domain\Model\User::$token.value does not exist

How I can resolved this error?

pounard commented 9 months ago

We never tested this use case, I'll try to reproduce it within the next week, thanks for reporting the issue !

SimonMellerin commented 8 months ago

To help us debugging your issue, can you give us the associated User.php and the Token.php files?

SimonMellerin commented 8 months ago

Forget my comment, we found the bug ;)

The fix will be shipped in the next minor version

SimonMellerin commented 8 months ago

Fix available from version 1.0.5