Doctrine 2 proxy classes breaking Symfony2 ACL
Asked Answered
H

1

8

When attempting to run findAcl() on an entity with an existing entry in the acl_classes table generated by init:acl I get an AclNotFoundException.

Testing with createAcl() on the object in question before calling findAcl() shows a new record in acl_classes for a proxy class of the same type and the operation completes successfully.

This seems wrong, proxies should be transparent right, or am I missing something?

Hatty answered 19/9, 2011 at 19:56 Comment(2)
Looks like I'm not the only one having this problem: forum.symfony-project.org/…Hatty
Also related: groups.google.com/group/symfony2/browse_thread/thread/…Hatty
H
9

I'm am just answering this because i had a hard time to find a solution and this was the first result in google for me.

Yes, it's wrong and it's a known bug for symfony2.

Jonathan Ingram solved this, and wrote a post about it a while ago: http://jonathaningram.com.au/2012/01/13/overriding-the-objectidentityretrievalstrategy-to-check-if-a-domain-object-is-a-doctrine-proxy/

He created his own object identity retrieval strategy to override the default, and registered it in the services.xml (see the post above). Actually it's a pretty simple and straightforward solution, i am a bit ashamed i didn't figured it out on my own :)

In symfony2.1 it's not a problem any more, see: https://github.com/symfony/symfony/pull/3826

Handedness answered 8/6, 2012 at 15:28 Comment(1)
Just to complete the post, I had the same problem but with the $idFranquicia = UserSecurityIdentity::fromAccount($franquicia) that was inserting proxies and entities in the ACL tables. The solution was to use directly the constructor with the Fully Qualified Name (FQN) of the class like $idFranquicia = new UserSecurityIdentity($franquicia->getUsername(), 'MiAlarma\SuperuserBundle\Entity\Franquicia')Nomi

© 2022 - 2024 — McMap. All rights reserved.