Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestampable is not working with embeddables #2729

Open
Perf opened this issue Nov 29, 2023 · 1 comment
Open

Timestampable is not working with embeddables #2729

Perf opened this issue Nov 29, 2023 · 1 comment
Labels

Comments

@Perf
Copy link

Perf commented Nov 29, 2023

Environment

Linux 6.2.0-37-generic 22.04.1
Docker version 24.0.5, build 24.0.5-0ubuntu1 22.04.1
Symfony 6.3.8

Package

show

$ composer show --latest gedmo/doctrine-extensions
name     : gedmo/doctrine-extensions
descrip. : Doctrine behavioral extensions
versions : * v3.13.0
latest   : v3.13.0

Doctrine packages

show

$ composer show --latest 'doctrine/*'
Direct dependencies required in composer.json:
doctrine/doctrine-bundle            2.11.1 2.11.1 Symfony DoctrineBundle
doctrine/doctrine-fixtures-bundle   3.5.1  3.5.1  Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle 3.3.0  3.3.0  Symfony DoctrineMigrationsBundle
doctrine/orm                        2.17.1 2.17.1 Object-Relational-Mapper for PHP

Transitive dependencies not required in composer.json:
doctrine/annotations                2.0.1  2.0.1  Docblock Annotations Parser
doctrine/cache                      2.2.0  2.2.0  PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections                2.1.4  2.1.4  PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                     3.4.3  3.4.3  PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, proxies and much more.
doctrine/data-fixtures              1.7.0  1.7.0  Data Fixtures for all Doctrine Object Managers
doctrine/dbal                       3.7.2  3.7.2  Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations               1.1.2  1.1.2  A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.
doctrine/event-manager              2.0.0  2.0.0  The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                  2.0.8  2.0.8  PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator               2.0.0  2.0.0  A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                      2.1.0  3.0.0  PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                 3.7.1  3.7.1  PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very ea...
doctrine/persistence                3.2.0  3.2.0  The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/sql-formatter              1.1.3  1.1.3  a PHP SQL highlighting library

PHP version

$ php -v
PHP 8.2.12 (cli) (built: Oct 28 2023 02:13:45) (ZTS)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies
with Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethans

Subject

When adding Timestampable mapping into embeddables - it's not working.
For example:
User.orm.xml

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="App\Xyz\Domain\Entity\User" table="`user`" repository-class="App\Xyz\Infrastructure\Doctrine\Repository\UserRepository">
        <embedded name="id" class="App\Xyz\Domain\Entity\ValueObject\UserId" use-column-prefix="false"/>
        <embedded name="email" class="App\Shared\Domain\Entity\ValueObject\Email" use-column-prefix="false"/>
        <embedded name="password" class="App\Xyz\Domain\Entity\ValueObject\HashedPassword" use-column-prefix="false"/>
        <embedded name="roles" class="App\Xyz\Domain\Entity\ValueObject\UserRoles" use-column-prefix="false"/>
        <embedded name="createdAt" class="App\Shared\Domain\Entity\ValueObject\CreatedAt" use-column-prefix="false"/>
        <embedded name="updatedAt" class="App\Shared\Domain\Entity\ValueObject\UpdatedAt" use-column-prefix="false"/>
        <embedded name="deletedAt" class="App\Shared\Domain\Entity\ValueObject\DeletedAt" use-column-prefix="false"/>
    </entity>

</doctrine-mapping>

ValueObject.CreatedAt.orm.xml

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
                  xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <embeddable name="App\Shared\Domain\Entity\ValueObject\CreatedAt">
        <field name="value" type="datetime" column="created_at">
            <gedmo:timestampable on="create"/>
        </field>
    </embeddable>

</doctrine-mapping>

I do expect that prePersist will update entity's fields via embedded value objects, to which Timestampable is listening to, however nothing happens.

It seems the issue happens in \Gedmo\AbstractTrackingListener::prePersist at line171.
$config = $this->getConfiguration($om, $meta->getName())
$config variable is empty, because $meta->getName() return the class name of an entity, but the configuration exists for ValueObject class. So, nothing happens.

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant