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

[References] Adding the ReferencesListener breaks all other Doctrine extensions. #821

Closed
borovan-zz opened this issue Sep 4, 2013 · 14 comments

Comments

@borovan-zz
Copy link

Hi - so I've been using Tree, Blameable and Timestampable with no problems at all. I've recently had a need for the ORM/ODM cross-relational functionality, so added in the ReferencesListener, and although it works fine none of the other extensions work at the same time.

Blame and Timestamp both just insert null values now, and Tree gives me the error "Tree listener was not found on your entity manager, it must be hooked into the event manager".

I've done a var_dump in the Gedmo\Tree\Entity\Repository\AbstractTreeRepository code and it seems that whenever this line (from my services.yml) is called

        - [ registerManager, [ 'entity', "@doctrine.orm.entity_manager" ] ]

then $em->getListeners() returns an empty array. No exceptions are thrown, just the other extensions fail to work. If I comment out that one line, the situation is reversed (Everything works apart from references).

I've tried with and without Stof, nothing changes. I've tried injecting the entity managers in the constructor, that doesn't work either. I've also tried with just one listener where I pass in 2 entity managers. I've included the relevant bit of services.yml below.

Thanks,
Adam

# Gedmo
gedmo.listener.reference.mysql:
    class: Gedmo\References\ReferencesListener
    tags:
        - { name: doctrine.event_subscriber, connection: game }
    calls:
        - [ setAnnotationReader, [ "@annotation_reader" ] ]
        - [ registerManager, [ 'document', "@doctrine_mongodb.odm.document_manager" ] ]

gedmo.listener.reference.mongodb:
     class: Gedmo\References\ReferencesListener
     tags:
        - { name: doctrine_mongodb.odm.event_subscriber }
     calls:
       - [ setAnnotationReader, [ "@annotation_reader" ] ]
        - [ registerManager, [ 'entity', "@doctrine.orm.entity_manager" ] ]

gedmo.listener.tree:
    class: Gedmo\Tree\TreeListener
    tags:
        - { name: doctrine.event_subscriber, connection: game }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

gedmo.listener.timestampable:
    class: Gedmo\Timestampable\TimestampableListener
    tags:
        - { name: doctrine.event_subscriber, connection: game }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]

gedmo.listener.blameable:
    class: Gedmo\Blameable\BlameableListener
    tags:
        - { name: doctrine.event_subscriber, connection: game }
    calls:
        - [ setAnnotationReader, [ @annotation_reader ] ]
@stof
Copy link
Contributor

stof commented Sep 4, 2013

I think it could be related to the circular reference between the ORM and the MongoDB managers (through the 2 listeners). If it is, it would be fixed by refactoring the extensions to use manager registries instead of managers directly, as I suggested when implementing the extension at first.

@borovan-zz
Copy link
Author

Ok thank you. That's probably what's going on. I tried searching for examples where people had both References and something else working at the same time but didn't find anything that wasn't a custom fork. It's beyond my skill level to fix unfortunately.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Sep 6, 2013

@stof what do you mean by manager registries? Are they supported in 2.2 or starting from 2.3 orm?

@stof
Copy link
Contributor

stof commented Sep 12, 2013

@l3pp4rd https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Persistence/ManagerRegistry.php
This interface (added in Common 2.2) is based on a feature implemented in Symfony 2.0 DoctrineBundle. As of Symfony 2.1, the Symfony class implements the Doctrine interface and the ODM bundle is using it too.
The Doctrine ZF2 modules are also using it IIRC.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Sep 13, 2013

@stof thanks, that is the way it should be done in general. Will need to schedule an update

@l3pp4rd l3pp4rd mentioned this issue Nov 3, 2013
44 tasks
l3pp4rd added a commit that referenced this issue Nov 3, 2013
l3pp4rd added a commit that referenced this issue Nov 3, 2013
l3pp4rd added a commit that referenced this issue Nov 3, 2013
l3pp4rd added a commit that referenced this issue Nov 3, 2013
l3pp4rd added a commit that referenced this issue Nov 3, 2013
xif6 added a commit to xif6/DoctrineExtensions that referenced this issue Mar 23, 2014
@webdevilopers
Copy link

I think the ServiceCircularReferenceException issue is related to this question too:
http://stackoverflow.com/questions/17296659/sharing-objects-between-doctrine2-odm-and-orm-in-symfony2-with-doctrine-extensio

I tried the configs provided as solution by @nifr and @borovan but still I get the error.

@stof
Copy link
Contributor

stof commented Sep 10, 2014

@webdevilopers the circular reference is the main reason why I asked to use the ManagerRegistry instead

@webdevilopers
Copy link

Thanks @stof . Where can I get the fix - in dev-master then? At the moment I still use 2.3.9.

@gonzalovilaseca
Copy link
Contributor

@stof Is this issue still open? Might have time to work on it if needed.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Mar 3, 2015

well it is still open, maybe there is something related to that in #764 should be copied if applicable. That branch has too many changes, decided to keep BC since I do not have that much time.. cheers

@gonzalovilaseca
Copy link
Contributor

In fact I refactored it so that it now uses registries instead of managers, but I was also going to add phpcr to References, though I don't know if it's better to add it to 3.0.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Mar 3, 2015

please do it in master if you are in need of such behavior the 3.0 is hardly going into master any time soon.. cheers

@diimpp
Copy link
Contributor

diimpp commented Apr 9, 2015

@gonzalovilaseca would you mind to share you work before PR? This issue causing so much pain for years.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Jun 18, 2015

will try to manage it for next minor release version..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants