stof / StofDoctrineExtensionsBundle

Integration bundle for DoctrineExtensions by l3pp4rd in Symfony
https://symfony.com/bundles/StofDoctrineExtensionsBundle/current/index.html
MIT License
1.89k stars 379 forks source link

Tree Event Listiner not triggered #347

Closed jplanginier closed 7 years ago

jplanginier commented 7 years ago

Hi, I'm having a problem, as I'm using the extension to use the tree doctrine extension. I have the Tree working fine in database, yet I can't active the Listener, resulting in the common "Integrity constraint violation: 1048 Column 'lft' cannot be null" error. Problem is, all the answer for that error is to enable the Listener in the config.yml, which I did. For the record, here are the relevant parts of my config.yml

stof_doctrine_extensions:
    default_locale: fr_FR
    orm:
        default:
            tree: true

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/../var/data/data.sqlite"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            gedmo_tree:
                type: annotation
                prefix: Gedmo\Tree\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
                alias: GedmoTree # (optional) it will default to the name set for the mapping
                is_bundle: false

What else could block the listiner from triggering please ? I'm using an entity with materializedpath strategy, on which I did put the MaterializedPathRepository.

The only "exotic" thing that could happen with that Entity is that it is my User class which extends FOSUser, but the updateUser function I use does persist and then flush the entity. So, there is no reason for the event listener not to work on the entity before it goes to the DB ?

Thank you for your time and answers !

jplanginier commented 7 years ago

I was able to find the solution alone in the end. For those who would encounter the same problem :

Most of the official doc use nested strategy as the example, then they add the required fields for that strategy. For MaterializedPath, the only fields which are necessary are $lvl, $title, $path, $parent and $children, Any other like $root, $lft, and so on will only prevent the listener from working, then it will cause error on SQL query.

velkony commented 6 years ago

Hi I saw that you had a similar problem like me with tree doctrine extension. I opened new issue with title: This repository can be attached only to ODM MongoDB tree listener can I ask you to look and give me your opinion?

I found that I have to call the event manager and passed to entity manager constructor.

Regards