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

Decrypt on join or manual select not working #29

Open
LauLaman opened this issue Jul 27, 2014 · 2 comments
Open

Decrypt on join or manual select not working #29

LauLaman opened this issue Jul 27, 2014 · 2 comments

Comments

@LauLaman
Copy link

When accessing decrypted column in a join, or when selecting manually, it will return the raw encrypted data.

i'm using the annotation

/**
 * @var string
 *
 * @ORM\Column(name="iban", type="text")
 * @Encrypted
 */
protected $iban;
queryBuilder = $this->objectManager->getRepository('CoreBundle:iban')->createQueryBuilder('i');
$data = $queryBuilder->getQuery()->getResult();

Works like a charm

queryBuilder = $this->objectManager->getRepository('CoreBundle:user')->createQueryBuilder('u');
$queryBuilder->join('u.ibans', 'i');
$data = $queryBuilder->getQuery()->getResult();

AND

queryBuilder = $this->objectManager->getRepository('CoreBundle:iban')->createQueryBuilder('i');
$queryBuilder->select('i.iban');
$data = $queryBuilder->getQuery()->getResult();

wont work

@dodysw
Copy link

dodysw commented Feb 14, 2015

I've noticed the same issue. The root cause in my case was two folds.

  1. the postLoad() event handler was relying on getEntity() to check if this is the entity that interests it (e.g. containing the Encrypted annotation). But as you've experienced, on associated entity, Doctrine lazy loads it and wrap the entity inside a proxy class, which then fails the getEntity() match.
  2. Second problem is on Doctrine, the postLoad() triggers even before the associated entity is hydrated, thus even if the getEntity() can somehow match it, the entity is still empty.

We need to find a better binding/listener hook implementation different to how it's currently done.

@dev-marcel
Copy link

I have fixed this issue in my fork https://github.com/ambta/DoctrineEncryptBundle. This by checking on relationships in the entity and use the get method to recursively processes that entity as well. I also changed it a little by using postUpdate and preUpdate because there were some issues in different occasions using the prePersist. The proxy classes issue can easily be fixed by using getClass from Doctrine's ClassUtils. Everything works like charm in the setups i used in in so far.

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

3 participants