0
votes

I'm developing web site with Symfony 4.4, using SonataAdmin (^3.56), Doctrine ORM Admin (^3.12), Sonata Media (^3.22) and SonataClassification (^3.9) bundles. My web site works perfectly in dev mode. Problem is when I change it to prod mode.

.env

APP_ENV=prod
APP_DEBUG=0

When I access routes with SonataMedia gallery then I get error 500. Log file (prod.log) contains the following content:

request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMException: "Unrecognized field: gallery" at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 101 {"exception":"[object] (Doctrine\\ORM\\ORMException(code: 0): Unrecognized field: gallery at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:101)"} []

In Controller I have:

...
$medias = $this->getDoctrine()->getRepository("ApplicationSonataMediaBundle:GalleryHasMedia")->findBy(array('gallery' => $article->getGallery()));
...

If i dump $medias in dev mode, it looks OK, with all images in gallery, but in production mode it doesn't work.

A similar thing happens in SonataAdmin Admin->Classification

request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\Query\QueryException: "[Semantical Error] line 0, col 84 near 'parent IS NU': Error: Class App\Application\Sonata\ClassificationBundle\Entity\Category has no field or association named parent" at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 65 {"exception":"[object] (Doctrine\\ORM\\Query\\QueryException(code: 0): [Semantical Error] line 0, col 84 near 'parent IS NU': Error: Class App\\Application\\Sonata\\ClassificationBundle\\Entity\\Category has no field or association named parent at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:65, Doctrine\\ORM\\Query\\QueryException(code: 0): SELECT c FROM App\\Application\\Sonata\\ClassificationBundle\\Entity\\Category c WHERE c.parent IS NULL at /home/repincln/dev/site/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:43)"} []

and Tags, Collections, Media. Only Contexts is working normal. Gallery for example looks like:

enter image description here

config/packages/prod/doctrine.yaml

doctrine:
    orm:
        auto_generate_proxy_classes: false
        metadata_cache_driver:
            type: service
            id: doctrine.system_cache_provider
        query_cache_driver:
            type: service
            id: doctrine.system_cache_provider
        result_cache_driver:
            type: service
            id: doctrine.result_cache_provider

services:
    doctrine.result_cache_provider:
        class: Symfony\Component\Cache\DoctrineProvider
        public: false
        arguments:
            - '@doctrine.result_cache_pool'
    doctrine.system_cache_provider:
        class: Symfony\Component\Cache\DoctrineProvider
        public: false
        arguments:
            - '@doctrine.system_cache_pool'

framework:
    cache:
        pools:
            doctrine.result_cache_pool:
                adapter: cache.app
            doctrine.system_cache_pool:
                adapter: cache.system

config/packages/doctrine.yaml

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        types:
            json: Sonata\Doctrine\Types\JsonType

    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

Article.php

...
    /**
    * @ORM\ManyToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Gallery");
    */
    private $gallery;
...

As i wrote in development mode everything is working fine.

The problem persists even though I did (many times):

Any ideas what else can I do? I think there is a problem with cache ... somewhere.

1
What about the db ? is the prod schema up to date?msg
already tried php bin/console make:migration and there are no changes.repincln
Looks like a doctrine mapping problem for prod mode. Do you have the same doctrine configs for dev and prod?Hast
The entitles mapping is defined in annotation or yaml ? Because some yaml files are loaded by env, it depends on configuration and directory.Smaïne
@Hast: I updated my question with doctrine.yaml filesrepincln

1 Answers

0
votes

I finally found a solution.

I had in the config/bundles.php

Sonata\EasyExtendsBundle\SonataEasyExtendsBundle::class => ['dev' => true, 'test' => true],

It must be:

Sonata\EasyExtendsBundle\SonataEasyExtendsBundle::class => ['all' => true],