Reputation: 238
FOSUserBundle works good for the project I'm working on. But I'm trying to embed FOSFacebookBundle and make it work with FOSUserBundle.
Within this purpose I've built my own Acme\MyBundle\Entity\User.php
to add some fields that I'd like to store from Facebook in addition to what provides the UserBundle. The
code of this class has been debugged and works (well... that's what I thought ! see below).
What doesn't work is (in my Acme\MyBundle\Security\User\Provider\FacebookProvider.php
, inside the loadUserByUsername()) this line :
$this->userManager->updateUser($user);
The Acme\MyBundle\Security\User\Provider\FacebookProvider.php
is the same as the documentation (read it here)
The following element is the output of print_r($user);
just before the
execution of $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] => [email protected] [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] => )
The message error is "UNKNOWN ERROR". So I decided to go to look Where this message is sent in the Bundle. And I've found that it was set in an Exception. I decided to output the Exception Message.
So below the Exception message:
A new entity was found through the relationship 'Acme\MyBundle\Entity\User#languages' that was not configured to cascade persist operations for entity: Acme\MyBundle\Entity\SpokenLanguage@000000004a9e2dfa0000000001482b74. Explicitly persist the new entity or configure cascading persist operations on the relationship. If you cannot find out which entity causes the problem implement 'Acme\MyBundle\Entity\SpokenLanguage#__toString()' to get a clue.
So I guess I have not well-coded the Doctrine Annotations of my User class and the problem is the ManyToMany() association mapping.
Here the Annotations of the field $languages 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 guys have anything in mind how to solve the problem? I'm thinking about a CASCADING Problem.
Thank you everyone.
Upvotes: 4
Views: 1606
Reputation: 238
OKAY! I've solved this finally!
You have to add the parameter cascade={'persist','remove','merge'}
to the Annotation ManyToMany.
Like this:
@ORM\ManyToMany(targetEntity="SpokenLanguage", cascade={"persist", "remove", "merge"})
Upvotes: 2