PHPackages                             soliantconsulting/entity-audit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. soliantconsulting/entity-audit

AbandonedArchivedZf-module[Database &amp; ORM](/categories/database)

soliantconsulting/entity-audit
==============================

Doctrine 2 Entity Auditing

1.0.1(11y ago)22.8k4[1 issues](https://github.com/soliantconsulting/SoliantEntityAudit/issues)[1 PRs](https://github.com/soliantconsulting/SoliantEntityAudit/pulls)MITPHPPHP &gt;=5.3.0

Since Nov 24Pushed 10y ago4 watchersCompare

[ Source](https://github.com/soliantconsulting/SoliantEntityAudit)[ Packagist](https://packagist.org/packages/soliantconsulting/entity-audit)[ RSS](/packages/soliantconsulting-entity-audit/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

SoliantEntityAudit
==================

[](#soliantentityaudit)

[![Build Status](https://camo.githubusercontent.com/b21a742d357cfdedc3e96c8b54dcdb659b7186493766e28b967052d28b97d870/68747470733a2f2f7472617669732d63692e6f72672f546f6d48416e646572736f6e2f536f6c69616e74456e7469747941756469742e706e67)](https://travis-ci.org/TomHAnderson/SoliantEntityAudit)

An auditing module for Doctrine 2. Requires ZfcUser to map revisions to users. This module creates an entity to audit a specified target entity and tracks revisions to that target.

About
=====

[](#about)

This module takes a configuration of entities to audit and creates entities to audit them and revision tracking entities. Included is a view layer to browse the audit records. Routing back to live application data is supported and view helpers allow you to find and browse to the latest audit record from a given audited entity.

Revisions pool all audited entities into revision buckets. Each bucket contains the revision entity for each audited record in a transaction.

Auditing is done in it's own transaction after a flush has been performed. Auditing takes two flushes in one transaction to complete.

Install
=======

[](#install)

Require SoliantEntityAudit with composer

```
php composer.phar require "soliantconsulting/entity-audit": "dev-master"
```

Enable SoliantEntityAudit in `config/application.config.php`:

```
return array(
    'modules' => array(
        'SoliantEntityAudit'
        ...
    ),
```

Copy `config/SoliantEntityAudit.global.php.dist` to `config/autoload/SoliantEntityAudit.global.php` and edit setting as

```
return array(
    'audit' => array(
        'datetimeFormat' => 'r',
        'paginatorLimit' => 20,

        'tableNamePrefix' => '',
        'tableNameSuffix' => '_audit',
        'revisionTableName' => 'Revision',
        'revisionEntityTableName' => 'RevisionEntity',

        'entities' => array(
            'Db\Entity\Song' => array(),
            'Db\Entity\Performer' => array(),
        ),
    ),
);
```

Use the Doctrine command line tool to update the database and create the auditing tables:

```
vendor/bin/doctrine-module orm:schema-tool:update
```

Terminology
-----------

[](#terminology)

AuditEntity - A generated entity which maps to the Target auditable entity. This stores the values for the Target entity at the time a Revision is created.

Revision - An entity which stores the timestap, comment, an user for a single entity manager flush which contains auditable entities.

RevisionEntity - A mapping entity which maps an AuditEntity to a Revision and maps to a Target audited entity. This entity can rehydrate a Target entity and AuditEntity. This also stores the revision type when the Target was audited. INS, UPD, and DEL map to insert, update, and delete. The primary keys of the Target are stored as an array and can be used to rehydrate a Target.

Target entity - An auditable entity specified as string in the audit configuration.

Authentication
--------------

[](#authentication)

You may configure a custom entity to serve as the user entity for mapping revisions to users. You may configure a custom authentication service too. By default these map to ZfcUserDoctrineORM\\Entity\\User and zfcuser\_auth\_service. For example to use a custom entity and service Db\\Entity\\User for an entity and Zend\\Authentication\\AuthenticationService would work.

The user entity must implement getDisplayName, getId, and getEmail. The authentication service must implement hasIdentity and getIdentity which returns an instance of the current user entity.

Interfaces are not used so ZfcUser can be used out of the box.

Routing
-------

[](#routing)

To map a route to an audited entity include route information in the audit =&gt; entities config

```
    'Db\Entity\Song' => array(
        'route' => 'default',
        'defaults' => array(
            'controller' => 'song',
            'action' => 'detail',
        ),
    ),

```

Identifier column values from the audited entity will be added to defaults to generate urls through routing.

```
