无法部署doctrine discriminator update

时间:2016-05-13 19:01:24

标签: php symfony proxy doctrine

我有一个使用symfony2和doctrine的php应用程序。我需要为不同内容类型的鉴别器映射添加一个类。目前我对鉴别器映射有以下基本抽象类:

/**
 * @ORM\Entity(repositoryClass="PrintSyndicate\HubBundle\EntityRepository\ContentRepository")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 *  * @ORM\DiscriminatorMap({   "site_content"="SiteContent",
                            "site_content_image"="SiteContentImage",
                            "site_content_carousel"="SiteContentCarousel",
                            "site_content_html"="SiteContentHtml",
                            "site_content_static_text"="SiteContentStaticText",
                            "apparel_front"="ApparelFrontContent",
                            "apparel_back"="ApparelBackContent",
                            "blanket"="BlanketContent",
                            "canvas"="CanvasContent",
                            "phone_case"="PhoneCaseContent",
                            "tablet_case"="TabletCaseContent",
                            "pillow"="PillowContent",
                            "tote"="ToteContent",
                            "poster"="PosterContent",
                            "sticker"="StickerContent",
                            "mug"="MugContent",
                            "gift_card"="GiftCardContent",
                            "collection_image"="CollectionImageContent",
                            "greeting_card"="GreetingCardContent",
                            "towel"="TowelContent"
                        })
 * @ORM\Table(name="content", indexes={@Index(name="content_guid_index", columns={"guid"})})
 **/
abstract class Content extends Model 
{

我要添加的新类是TowelContent类,如下所示:

<?php

// src/Acme/UserBundle/Entity/TowelContent.php
namespace PrintSyndicate\HubBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinTable as JoinTable;
use Doctrine\ORM\Mapping\JoinColumn as JoinColumn;
use Symfony\Component\Validator\Constraints as Assert;
use PrintSyndicate\HubBundle\Entity\Content;

/**
 * @ORM\Entity
 */
class TowelContent extends Content
{
    /**
     * Validate that this is a well formated apparel front image
     */
    public function validate($errors = array())
    {
        //do initial validation
        $parentValid = parent::validate($errors);
        //check if png
        //check sizing
        //
        return $parentValid;
    }
}

无论出于何种原因,当我尝试运行php app / console doctrine:cache:clear-metadata --env = prod删除app / cache文件夹中的所有文件后,我收到以下错误

  [Doctrine\ORM\Mapping\MappingException]                                                                                                                                                                                                                                                                                             
  Entity 'PrintSyndicate\HubBundle\Entity\TowelContent' has to be part of the discriminator map of 'PrintSyndicate\HubBundle\Entity\Content' to be properly mapped in the inheritance hierarchy. Alternatively you can make 'PrintSyndicate\HubBundle\Entity\TowelContent' an abstract class to avoid this exception from occurring.  

我不明白的是,它显然是鉴别器地图的一部分,缓存文件夹已被删除,所以我不知道它是如何看待它不是鉴别器的一部分地图...

此外,如果我尝试在不清除缓存的情况下进行部署,则会在每个路由上出现以下错误:

Warning: require(/app/app/cache/prod/doctrine/orm/Proxies/__CG__PrintSyndicateHubBundleEntityStatus.php): failed to open stream: No such file or directory in /app/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 209

Fatal error: require(): Failed opening required '/app/app/cache/prod/doctrine/orm/Proxies/__CG__PrintSyndicateHubBundleEntityStatus.php' (include_path='/app/vendor/phpunit/php-file-iterator:.:/usr/share/php:/usr/share/pear') in /app/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 209

Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Compile Error: require(): Failed opening required '/app/app/cache/prod/doctrine/orm/Proxies/__CG__PrintSyndicateHubBundleEntityStatus.php' (include_path='/app/vendor/phpunit/php-file-iterator:.:/usr/share/php:/usr/share/pear')' in /app/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:209 Stack trace: #0 {main} thrown in /app/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 209

任何帮助都会令人惊叹,我一整天都在靠墙撞击。

1 个答案:

答案 0 :(得分:0)

在我的案例中,对于搜索同一问题的任何人,我都认为这一点。在我们的config_prod.yml文件中,以下行被注释掉了:

doctrine:
    orm:
        metadata_cache_driver: apc
        result_cache_driver: apc
        query_cache_driver: apc

取消注释这些行解决了这个问题。