FOSUserBundle and FOSFacebookBundle: userManager-> updateUser (): "unknown error" (this is a doctrine error)

FOSUserBundle works well for the project I'm working on. But I'm trying to implement FOSFacebookBundle and work with FOSUserBundle .

As part of this goal, I created my own Acme\MyBundle\Entity\User.php to add some fields that I would like to keep on Facebook, in addition to what UserBundle provides. the code of this class has been debugged and works (well ... what I thought! see below).

Which does not work (in my Acme\MyBundle\Security\User\Provider\FacebookProvider.php , inside loadUserByUsername ()):

  $this->userManager->updateUser($user); 

Acme\MyBundle\Security\User\Provider\FacebookProvider.php matches the documentation ( read here )

The next element is the output of print_r($user); just before executing $this->userManager->updateUser($user); :

  Acme \ MyBundle \ Entity \ User Object
 (
     [id: protected] =>
     [facebookID: protected] => 847000001
     [first_name: protected] => Peter
     [middle_name: protected] =>
     [last_name: protected] => Parker
     [fullname: protected] => Peter Parker
     [locale: protected] => en_US
     [timezone: protected] => 2
     [updated_time: protected] => 2011-10-27T17: 13: 24 + 0000
     [birthday: protected] => DateTime Object
         (
             [date] => 1961-07-01 10:31:53
             [timezone_type] => 3
             [timezone] => Europe / Berlin
         )
     [languages: protected] => Doctrine \ Common \ Collections \ ArrayCollection Object
         (
         [_elements: Doctrine \ Common \ Collections \ ArrayCollection: private] => Array
             (
         [0] => Acme \ MyBundle \ Entity \ SpokenLanguage Object
             (
             [facebookID: Acme \ MyBundle \ Entity \ SpokenLanguage: private] => 113051505375958
             [name: Acme \ MyBundle \ Entity \ SpokenLanguage: private] => Italien
             )
         [1] => Acme \ MyBundle \ Entity \ SpokenLanguage Object
             (
             [facebookID: Acme \ MyBundle \ Entity \ SpokenLanguage: private] => 112264595467201
             [name: Acme \ MyBundle \ Entity \ SpokenLanguage: private] => Français
             )
         [2] => Acme \ MyBundle \ Entity \ SpokenLanguage Object
             (
             [facebookID: Acme \ MyBundle \ Entity \ SpokenLanguage: private] => 103803232991647
             [name: Acme \ MyBundle \ Entity \ SpokenLanguage: private] => English
             )
         )
     )
     [usernameFB: protected] => spiderman
     [username: protected] => Peter Parker
     [usernameCanonical: protected] =>
     [email: protected] => peterparker@marvel.com
     [emailCanonical: protected] =>
     [enabled: protected] => 1
     [algorithm: protected] =>
     [salt: protected] =>
     [password: protected] =>
     [plainPassword: protected] =>
     [lastLogin: protected] =>
     [confirmationToken: protected] => 540grdgfg343004g8g0skg0wg408k
     [passwordRequestedAt: protected] =>
     [groups: protected] =>
     [locked: protected] =>
     [expired: protected] =>
     [expiresAt: protected] =>
     [roles: protected] => Array
         (
             [0] => ROLE_FACEBOOK
         )

     [credentialsExpired: protected] =>
     [credentialsExpireAt: protected] =>
 )

Error message "UNKNOWN ERROR" . So I decided to see where this message was sent to the Bundle. And I found that it was set to Exception. I decided to throw an Exception Message.

So below are the exception messages:

The new object was found through the relationship 'Acme \ MyBundle \ Entity \ User # languages', which was not configured for the cascade operation for the object: Acme \ MyBundle \ Entity \ SpokenLanguage @ 000000004a9e2dfa0000000001482b74. Explicitly save the new object or configure cascading saving operations on relations. If you cannot find out which object is causing the problem. 'Acme \ MyBundle \ Entity \ SpokenLanguage #__ toString ()' to get a hint.

So, I think I did not correctly encode the Doctrine annotations of my User class, and the problem is associating ManyToMany () associations.

Here are the annotations of the $ languages ​​fields in my Acme\MyBundle\Entity\User.php :

 /** * @var \Doctrine\Common\Collections\ArrayCollection * @ORM\ManyToMany(targetEntity="SpokenLanguage") * @ORM\JoinTable(name="users_spokenlanguage", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="spokenlanguage_id", referencedColumnName="facebookID")} * ) */ protected $languages; 

Do you have something in mind how to solve the problem? I think about the problem of CASCADING.

Thanks to everyone.

+4
source share
1 answer

WELL! I finally decided it!

You must add the cascade={'persist','remove','merge'} parameter to Annotation ManyToMany.

Like this:

 @ORM\ManyToMany(targetEntity="SpokenLanguage", cascade={"persist", "remove", "merge"}) 
+2
source

All Articles