4

I got a Symfony2 project with FOSUserBundle and SonataUserBundle. Both bundles are configured to use ORM only.

# FOS User Bundle
fos_user:
    db_driver: orm
    firewall_name: main
    user_class: MyBundle\Entity\User
    group:
        group_class: MyBundle\Entity\Group
    from_email:
        address: foo@bar.com
        sender_name: Foo Bar

# SONATA User Bundle
sonata_user:
    security_acl: false
    manager_type: orm
    class:
        user: MyBundle\Entity\User
        group: MyBundle\Entity\Group
    impersonating:
        route: homepage
    admin:
        user:
            class: MyBundle\Admin\UserAdmin
            controller: SonataAdminBundle:CRUD
            translation: SonataUserBundle

But when I want to use my User class, an error is thrown, telling MongoDB annotations classes cannot be found.

Attempted to load class "Unique" from namespace "\Symfony\Component\Validator\Constraints\Doctrine\Bundle\MongoDBBundle\Validator\Constraints". Did you forget a "use" statement for another namespace?

This message seems to be thrown by

/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/mongodb.xml

As I didn't want to use MongoDB drivers, why is FOSUser using MongoDB validator ?

Nicolas Janel
  • 3,025
  • 1
  • 28
  • 31

2 Answers2

4

this seems to be a bug in the FOSUserBudle.

As a dirty workaround, I copied the lines <constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity"> from the orm.xml to mongodb.xml and couchdb.xml (all in /friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/).

Obviously, those files are in fact loaded, but should not.

Edit: In fact this was a bug in FOSUserBundle and was fixed in version 1.3.6, see https://github.com/FriendsOfSymfony/FOSUserBundle/issues/1851#issuecomment-108411883

spackmat
  • 892
  • 9
  • 23
0

This is an old question, but for those who may get this error yet:

Check your own user bundle which you made for rewrite and customize fosUserBundle.

Too much time and lots of searches and no way to resolve, before checking my own user bundle!

Just remove this folder which is not needed in new versions of fos:

/Resources/config/validation

Good luck.

Milad Safaei
  • 492
  • 1
  • 5
  • 16