dreamcommerce/object-audit-bundle

Doctrine 实体与 Sylius 资源审计


README

License Version Build status on Linux

这是一个基于 SimpleThings EntityAudit 项目的分支。

安装(独立版)

安装 lib/bundle

假设你已经安装了 composer.phar 或 composer 二进制文件,只需简单运行即可

$ composer require dreamcommerce/object-audit-bundle

安装(在 Symfony 3 应用中)

启用包

在 kernel 中启用包

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        //...
            new Sylius\Bundle\ResourceBundle\SyliusResourceBundle(),
            new DreamCommerce\Bundle\CommonBundle\DreamCommerceCommonBundle(),
            new DreamCommerce\Bundle\ObjectAuditBundle\DreamCommerceObjectAuditBundle(),
        //...
    );
    return $bundles;
}

配置

你可以配置被审计的表。

app/config/config.yml
dream_commerce_object_audit:
    resources:
        revision:
            classes:
                model: DreamCommerce\Component\ObjectAudit\Model\Revision
         
    configuration:
        base:
            ignored_properties:
                - globalIgnoreMe
            load_audited_collections: true
            load_audited_objects: true
            load_native_collections: true
            load_native_objects: true
        orm:
            table_prefix: ''
            table_suffix: _audit
            revision_id_field_prefix: revision_
            revision_id_field_suffix: ''
            revision_action_field_name: revision_action
            revision_action_field_type: dc_revision_action
            
    default_manager: foo
    managers:
        foo:
            object_manager: foo
            audit_object_manager: foo_audit
            driver: orm
            options:
                table_prefix: ''
                table_suffix: _audit
                revision_id_field_prefix: revision_
                revision_id_field_suffix: ''
                revision_action_field_name: revision_action
                revision_action_field_type: dc_revision_action
                load_audited_collections: true
                load_audited_objects: false
                load_native_collections: true
                load_native_objects: false
                ignored_properties:
                    - globalIgnoreMe2
        bar:
            object_manager: bar
            audit_object_manager: bar_audit
        baz:
            object_manager: baz      

创建新表

调用以下命令以查看更新模式队列中的新表。

./bin/console doctrine:schema:update --dump-sql 

用法

定义可审计实体

你需要为想要可审计的实体添加 Auditable 注解。

use Doctrine\ORM\Mapping as ORM;
use DreamCommerce\Component\ObjectAudit\Mapping\Annotation as Audit;

/**
 * @ORM\Entity()
 * @Audit\Auditable()
 */
class Page {
 //...
}

你还可以忽略特定实体的字段。

class Page {

    /**
     * @ORM\Column(type="string")
     * @Audit\Ignore()
     */
    private $ignoreMe;

}

或者如果你更喜欢 XML 格式

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:dreamcommerce="https://dreamcommerce.com/schemas/orm/doctrine-object-audit-mapping"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="Page">
        <field name="ignoreMe" type="string">
            <dreamcommerce:ignore/>
        </field>
        
        <dreamcommerce:auditable />
    </entity>
</doctrine-mapping>

或者 YAML 格式

Page:
  type: entity
  dreamcommerce:
    auditable: true
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    ignoreMe:
      type: string
      dreamcommerce:
        ignore: true