Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonata Media Bundle missing entity Category

I try to install the Sonata Media Bundle into the Symfony CMF following this guide: https://sonata-project.org/bundles/media/3-x/doc/reference/installation.html. This command

php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle

makes a whole new bundle ApplicationSonataMediaBundle with a few entities:

  • Gallery
  • GalleryHasMedia
  • Media

But i get the error that the entity Category does not exist when i want to go to the next step:

app/console doctrine:schema:update --force

This is the complete error:

[Doctrine\ORM\Mapping\MappingException]                                                                                                  
  The target-entity Application\Sonata\ClassificationBundle\Entity\Category cannot be found in 'Application\Sonata\MediaBundle\Entity\Med  
  ia#category'.

Is there somebody who can help me to solve this?

Thanks in advance.

Update:

# sonata_classification.yml:

sonata_classification:
    # ...

doctrine:
    orm:
        entity_managers:
            default:
                #metadata_cache_driver: apc
                #query_cache_driver: apc
                #result_cache_driver: apc
                mappings:
                    #ApplicationSonataClassificationBundle: ~
                    SonataClassificationBundle: ~
like image 658
Frank B Avatar asked Jul 25 '16 13:07

Frank B


3 Answers

I had to set this configuration options to get it to work:

sonata_media:
    class:
        media: Application\MediaBundle\Entity\Media
        gallery: Application\MediaBundle\Entity\Gallery
        gallery_has_media: Application\MediaBundle\Entity\GalleryHasMedia
    # ...

And also:

doctrine_phpcr:
    # ...

    odm:
        auto_mapping: true
        mappings:
            SonataMediaBundle:
                prefix: Sonata\MediaBundle\PHPCR
            ApplicationSonataMediaBundle:
                prefix: Application\Sonata\MediaBundle\PHPCR
like image 179
Frank B Avatar answered Oct 22 '22 23:10

Frank B


I had the same problem after installing news bundle (which brings classification and media bundles with it). I configured both media and classification before news and received the same error as OP. After looking into the code I noticed that media bundle allows for another class to be specified for category. This stopped the error for me.

sonata_media:
    class:
        # my own bundle namespaces for media and classification bundles
        media: Application\Sonata\MediaBundle\Entity\Media
        gallery: Application\Sonata\MediaBundle\Entity\Gallery
        gallery_has_media: Application\Sonata\MediaBundle\Entity\GalleryHasMedia
        category: Application\Sonata\ClassificationBundle\Entity\Category
like image 45
John Pancoast Avatar answered Oct 23 '22 00:10

John Pancoast


Looks like you just need to create a sonata_classification.yml file as described in the classification docs

like image 37
greg0ire Avatar answered Oct 22 '22 22:10

greg0ire