Config entries for DoctrineExtensions SoftDeleteable: gedmo/doctrine

I'm trying to use softdelete option of gedmo/doctrine-extensions but for some reason when I call romove() , the record in database gets removed instead of updating deletedAt field.

In here, doc tells us to update config with:

$config->addFilter('soft-deleteable', 'GedmoSoftDeleteableFilterSoftDeleteableFilter');

This is just one of the examples I tried:

# app/config/config.yml
doctrine:
    orm:
        entity_managers:
            default:
                filters:
                    softdeleteable:
                        class: GedmoSoftDeleteableFilterSoftDeleteableFilter
                        enabled: true

References (just a few of them):

  • DoctrineExtensions SoftDeleteable
  • http://knplabs.com/en/blog/gedmo-doctrine-extensions-on-symfony2
  • Can't enable SoftDeleteable in Symfony2 - Unrecognized options "filters"
  • So the question in simple terms, how do I configure it in config.yml?

    CONTROLLER

    public function delete($id)
    {
        $profile = $this->profileRepository->findOneBy(['id' => $id]);
    
        if (!$profile instanceof Profile) {
            throw new ........
        }
    
        $this->entityManager->remove($profile);
        $this->entityManager->flush();
    
        return true;
    }
    

    ENTITY

    use GedmoMappingAnnotation as Gedmo;
    
    /**
     * @ORMEntity()
     * @ORMTable(name="profile")
     * @GedmoSoftDeleteable(fieldName="deletedAt")
     */
    class Profile
    {
        /**
         * @ORMColumn(name="deletedAt", type="datetime", nullable=true)
         */
        private $deletedAt;
        ......
    }
    

    COMPOSER.JSON

    "require": {
        "symfony/symfony": "2.6.*",
        "doctrine/orm": "~2.2,>=2.2.3",
        "doctrine/doctrine-bundle": "~1.2",
        "gedmo/doctrine-extensions": "2.3.*@dev",
        ......
    },
    

    CONFIG.YML

    doctrine:
        dbal:
          default_connection: front
          connections:
            front:
              driver:   %database_driver%
              host:     %database_host%
              ........
            back:
              driver:   %database_driver%
              host:     %database_host%
              ........
    
    
        orm:
            auto_generate_proxy_classes: %kernel.debug%
            default_entity_manager:      front
    
            entity_managers:
                front:
                    connection:       front
                    mappings:
                        MyWebsiteBundle:
                            dir:      Entity
                        FOSUserBundle: ~
    
                back:
                    connection:       back
    

    MAPPING INFO:

    inanzzz@inanzzz:/var/www/html/local$ php app/console doctrine:mapping:info
    Found 8 mapped entities:
    [OK]   MyBundleEntityAbstractMerchantProfile
    [OK]   MyBundleEntityAbstractIntegration
    [OK]   MyBundleEntityAPIConsumer
    [OK]   MyBundleWebsiteBundleEntityUser
    [OK]   MyBundleWebsiteBundleEntityProfile
    [OK]   MyBundleWebsiteBundleEntityIntegration
    [OK]   FOSUserBundleModelGroup
    [OK]   FOSUserBundleModelUser
    

    Solution:

    Included stof/doctrine-extensions-bundle in composer.json

    "stof/doctrine-extensions-bundle": "1.2.*@dev",

    Package is here. Documentation is here.

    Enable bundle in AppKernel: new StofDoctrineExtensionsBundleStofDoctrineExtensionsBundle()

    Since I have more than one entity managers in config.yml I did:

    stof_doctrine_extensions:
        orm:
            em1:
                softdeleteable: true
    
    
    doctrine:
        dbal:
          default_connection: em1
          connections:
            em1:
              driver:   %database_driver%
              host:     %database_host%
              .......
    
            em2:
              driver:   %database_driver%
              host:     %database_host%
              .......
    
            em3:
              driver:   %mws_database_driver%
              host:     %mws_database_host%
              .......
    
        orm:
            auto_generate_proxy_classes: %kernel.debug%
            default_entity_manager:      em1
    
            entity_managers:
                em1:
                    connection:       em1
                    mappings:
                        MyWebsiteBundle:
                            dir:      Entity
                        FOSUserBundle: ~
                    filters:
                        softdeleteable:
                            class: GedmoSoftDeleteableFilterSoftDeleteableFilter
                            enabled: true
    
                em2:
                    connection:       em2
    
                em3:
                    connection:       em3
    

    这是我配置它的方式

    doctrine:
        dbal:
            driver:   "%database_driver%"
            host:     "%database_host%"
            port:     "%database_port%"
            dbname:   "%database_name%"
            user:     "%database_user%"
            password: "%database_password%"
            charset:  UTF8
    
        orm:
            auto_generate_proxy_classes: "%kernel.debug%"
            auto_mapping: true
            filters:
                softdeleteable:
                    class: GedmoSoftDeleteableFilterSoftDeleteableFilter
                    enabled: true
    
    链接地址: http://www.djcxy.com/p/65032.html

    上一篇: 如何禁用参数转换器中的原则过滤器

    下一篇: DoctrineExtensions SoftDeleteable的配置条目:gedmo / doctrine