2017 © Pedro Peláez
 

library object-audit-bundle

Audit for Doctrine entities & Sylius resources

image

dreamcommerce/object-audit-bundle

Audit for Doctrine entities & Sylius resources

  • Friday, October 13, 2017
  • by dreamcommerce
  • Repository
  • 11 Watchers
  • 0 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 14 Versions
  • 4 % Grown

The README.md

DreamCommerce Object Audit Bundle

License Version Build status on Linux, (*1)

This is a fork of the SimpleThings EntityAudit project., (*2)

Installation (Standalone)

Installing the lib/bundle

Simply run assuming you have installed composer.phar or composer binary:, (*3)

``` bash $ composer require dreamcommerce/object-audit-bundle, (*4)


## Installation (In Symfony 3 Application) ### Enable the bundle Enable the bundle in the kernel: ``` php // 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; }

Configuration

You can configure the audited tables., (*5)

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      

Creating new tables

Call the command below to see the new tables in the update schema queue., (*6)

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

Usage

Define auditable entities

You need add Auditable annotation for the entities which you want to auditable., (*7)

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

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

You can also ignore fields in an specific entity., (*8)

class Page {

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

}

Or if you prefer XML:, (*9)


<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>

Or YAML:, (*10)

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

The Versions