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

Check changeset #11

Open
matthewvalimaki opened this issue Jun 2, 2013 · 5 comments
Open

Check changeset #11

matthewvalimaki opened this issue Jun 2, 2013 · 5 comments

Comments

@matthewvalimaki
Copy link

I propose that in DoctrineEncryptSubscriber::preUpdate() we check the entityChangeSet[] for a field before trying to update the field.

    foreach ($properties as $refProperty) {
        $propName = $refProperty->getName();

        if (isset($args->getEntityChangeSet()[$propName])) {
            if ($this->annReader->getPropertyAnnotation($refProperty, self::ENCRYPTED_ANN_NAME)) {

                $args->setNewValue($propName, $this->encryptor->encrypt($args->getNewValue($propName)));
            }
        }
    }
@matthewvalimaki
Copy link
Author

Oops, no that will break stuff.

The issue what I'm having is with FOSUserBundle and its fos_user.registration.completed event. With the following code I will get: Field "email" is not a valid field of the entity ... in PreUpdateEventArgs.

Here's the code:

public function onRegistration(FilterUserResponseEvent $event)
{
    $user = $event->getUser();
}

So the code above will result in the error mentioned above. I believe it's the order of events what cause the issue, but I am not quite sure where the actual issue is. According to the error message DoctrineEncryptSubscriber::preUpdate() tries to update a field that doesn't exist.

Any ideas?

@binarious
Copy link

+1 for a solution to this.
The problem seems to occour when you update a user entity more than once. Calling $this->em->detach($user); after the first update and before the second one works for us.

@vnenrico
Copy link

vnenrico commented Jan 5, 2015

+1

Hi @matthewvalimaki, what's wrong with your solution. I think it could solve the problem here.

@adammwood
Copy link

We've encountered the same problem with multiple updates of an entity within the same request. It can render this bundle unusable on applications with complex requests. This is the same issue as #40.

The resolution proposed here for DoctrineEncryptSubscriber::preUpdate() here: reprovinci#2 ...

if ($args->hasChangedField($propName)) { $args->setNewValue($propName, $this->encryptor->encrypt($args->getNewValue($propName))); }

... appears to resolve the issue.

@archer-developer
Copy link

Maybe we can fix it and create PR ?

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

5 participants