DoctrineEncryptBundle icon indicating copy to clipboard operation
DoctrineEncryptBundle copied to clipboard

No Encryption on partial load with QueryBuilder

Open Tanktiger opened this issue 5 years ago • 2 comments

Hi,

i've build a DQL query where i want to select only a partial from my entity and this partial is not encrypted.

$query = $em->createQueryBuilder()
            ->from(Offer::class, 'o')
            ->select('PARTIAL o.{id}')
            ->leftJoin('o.assocEntity', 'ae')
            ->addSelect('PARTIAL ae.{id, encryptedField}')
            ->setMaxResults(1)
        ;

        $result = $query ->getQuery()->getArrayResult();

I'm getting the ids and the assoc entity with the fields but the encrypted field is not decrypted.

[0] => [
    ['id'] => 1
    ['assocEntity'] => [
        ['id'] => 100,
        ['encryptedField'] => "b1B2WTVtZzJZRkRsOGJBSHlXc21BcE5nb ....",
    ]
]

How i can fix this or could this be fixed in this bundle pls?

Tanktiger avatar Jun 25 '20 12:06 Tanktiger

@GiveMeAllYourCats @dbu Do you have any hints or "where to start" to solve this?

I think that I've got the same problem with a OneToMany relation:

class Event
{
    /**
     * @var Contact[]|Collection
     *
     * @ORM\OneToMany(targetEntity="App\Entity\Contact", mappedBy="event", cascade={"remove"})
     */
    private Collection $contacts;

robertfausk avatar Nov 05 '20 18:11 robertfausk

When using the getArrayResult() you do not get Entity objects but just an array of the data selected from the DB. https://www.doctrine-project.org/projects/doctrine-orm/en/2.15/reference/dql-doctrine-query-language.html#query-result-formats

So the DoctrineEncryptBundle's subscriber is never called to decrypt the data. That is why you get the encrypted data as stored in the database when requesting for the array result.

Also note: Please see these comments:

  • https://github.com/absolute-quantum/DoctrineEncryptBundle/pull/65#issuecomment-1476301156
  • https://github.com/absolute-quantum/DoctrineEncryptBundle/pull/65#issuecomment-1638006829

The new package that I hope will be maintained by more than 1 person

r3hp1c avatar Jul 17 '23 12:07 r3hp1c