由于 Doctrine 存储库错误而无法恢复 Loggable 实体

问题描述 投票:0回答:1

我想恢复一个实体:

// use Gedmo\Loggable\Entity\LogEntry;
//...
$repo = $this->entityManager->getRepository(LogEntry::class);
$repo->revert($pizza, 1);
// ...

但是我收到错误:

在链配置的命名空间 App\Entity 中找不到类“Gedmo\Loggable\Entity\LogEntry”

我认为这是一个教义问题,这是我的

config/packages/doctrine.yaml
文件:

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'

        # IMPORTANT: You MUST configure your server version,
        # either here or in the DATABASE_URL env var (see .env file)
        #server_version: '16'

        profiling_collect_backtrace: '%kernel.debug%'
        use_savepoints: true
    orm:
        auto_generate_proxy_classes: true
        enable_lazy_ghost_objects: true
        report_fields_where_declared: true
        validate_xml_mapping: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                type: attribute
                is_bundle: false
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
        filters:
            # soft deletion
            softdeleteable:
                class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
                enabled: true
        controller_resolver:
            auto_mapping: false

when@test:
    doctrine:
        dbal:
            # "TEST_TOKEN" is typically set by ParaTest
            dbname_suffix: '_test%env(default::TEST_TOKEN)%'

when@prod:
    doctrine:
        orm:
            auto_generate_proxy_classes: false
            proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
            query_cache_driver:
                type: pool
                pool: doctrine.system_cache_pool
            result_cache_driver:
                type: pool
                pool: doctrine.result_cache_pool

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

版本:

  • 交响乐6.4
  • 教义2.19.3
  • 教义束2.12
  • 学说扩展包 1.11.0

有我必须更改的配置吗?

php symfony doctrine gedmo-loggable
1个回答
0
投票

好吧,这确实是一个 Doctrine 映射问题,但我没有编辑 Doctrine.yaml 文件,而是创建了一个自定义日志记录类:

<?php

namespace App\Entity;

use App\Repository\LogActivityRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Loggable\Entity\MappedSuperclass\AbstractLogEntry;

#[ORM\Entity(repositoryClass: LogActivityRepository::class)]
#[ORM\Index(columns: ['username'], name: 'log_activity_user_index')]
#[ORM\Index(columns: ['object_class'], name: 'log_activity_class_index')]
#[ORM\Index(columns: ['logged_at'], name: 'log_activity_date_index')]
#[ORM\Index(columns: ['object_id', 'object_class', 'version'], name: 'log_activity_version_index')]
class LogActivity extends AbstractLogEntry
{
    /**
     * @return string|null
     */
    public function getModelName(): ?string
    {
        $modelName = '';
        foreach (explode('\\', $this->getObjectClass()) as $key => $part) {
            if ($key > 1) {
                if ($key > 2) {
                    $modelName .= '\\';
                }
                $modelName .= $part;
            }
        }
        return $modelName;
    }

    /**
     * Format data in an associative array of form [column => data]
     * @return array
     */
    public function getDataAsArray(): array
    {
        $record = [];
        foreach ($this->getData() ?? [] as $column => $data) {
            $record[$column] = $data;
        }
        return $record;
    }
}

并像这样使用它:

// use App\Entity\LogActivity;
//...
$repo = $this->entityManager->getRepository(LogActivity::class);
$repo->revert($pizza, 1);
// ...

© www.soinside.com 2019 - 2024. All rights reserved.