PHPackages                             staspiv/entity-audit-bundle - 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. staspiv/entity-audit-bundle

ActiveLibrary[Database &amp; ORM](/categories/database)

staspiv/entity-audit-bundle
===========================

Audit for Doctrine Entities forked from simplethings/entity-audit-bundle

0.9.1(10y ago)08LGPL-2.1PHPPHP ^5.3.9|~7.0

Since Mar 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/StasPiv/EntityAudit)[ Packagist](https://packagist.org/packages/staspiv/entity-audit-bundle)[ RSS](/packages/staspiv-entity-audit-bundle/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (7)Versions (11)Used By (0)

EntityAudit Extension for Doctrine2
===================================

[](#entityaudit-extension-for-doctrine2)

[![Build Status](https://camo.githubusercontent.com/deb1c1cf8ea14cb4fcb19a3e193ede0f5f87c4cfffa1115cea091e47585aeb1b/68747470733a2f2f7472617669732d63692e6f72672f73696d706c657468696e67732f456e7469747941756469742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/simplethings/EntityAudit)

This extension for Doctrine 2 is inspired by [Hibernate Envers](http://www.jboss.org/envers) and allows full versioning of entities and their associations.

How does it work?
-----------------

[](#how-does-it-work)

There are a bunch of different approaches to auditing or versioning of database tables. This extension creates a mirroring table for each audited entitys table that is suffixed with "\_audit". Besides all the columns of the audited entity there are two additional fields:

- rev - Contains the global revision number generated from a "revisions" table.
- revtype - Contains one of 'INS', 'UPD' or 'DEL' as an information to which type of database operation caused this revision log entry.

The global revision table contains an id, timestamp, username and change comment field.

With this approach it is possible to version an application with its changes to associations at the particular points in time.

This extension hooks into the SchemaTool generation process so that it will automatically create the necessary DDL statements for your audited entities.

Installation (In Symfony2 Application)
--------------------------------------

[](#installation-in-symfony2-application)

\###Installing the bundle

Simply run assuming you have installed composer.phar or composer binary:

```
$ php composer.phar require simplethings/entity-audit-bundle
```

\###Enable the bundle

Finally, enable the bundle in the kernel:

```
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        //...
        new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
        //...
    );
    return $bundles;
}
```

\###Configuration

Load extension "simple\_things\_entity\_audit" and specify the audited entities (yes, that ugly for now!)

\#####app/config/config.yml

```
simple_things_entity_audit:
    audited_entities:
        - MyBundle\Entity\MyEntity
        - MyBundle\Entity\MyEntity2
```

If you need to exclude some entity properties from triggering a revision use:

\#####app/config/config.yml

```
simple_things_entity_audit:
    global_ignore_columns:
        - created_at
        - updated_at
```

\###Creating new tables

Call the command below to see the new tables in the update schema queue.

```
./app/console doctrine:schema:update --dump-sql
```

**Notice**: EntityAudit currently **only** works with a DBAL Connection and EntityManager named **"default"**.

Installation (Standalone)
-------------------------

[](#installation-standalone)

For standalone usage you have to pass the entity class names to be audited to the MetadataFactory instance and configure the two event listeners.

```
use Doctrine\ORM\EntityManager;
use Doctrine\Common\EventManager;
use SimpleThings\EntityAudit\AuditConfiguration;
use SimpleThings\EntityAudit\AuditManager;

$auditconfig = new AuditConfiguration();
$auditconfig->setAuditedEntityClasses(array(
    'SimpleThings\EntityAudit\Tests\ArticleAudit',
    'SimpleThings\EntityAudit\Tests\UserAudit'
));

$auditconfig->setGlobalIgnoreColumns(array(
    'created_at',
    'updated_at'
));

$evm = new EventManager();
$auditManager = new AuditManager($auditconfig);
$auditManager->registerEvents($evm);

$config = new \Doctrine\ORM\Configuration();
// $config ...
$conn = array();
$em = EntityManager::create($conn, $config, $evm);
```

Usage
-----

[](#usage)

Querying the auditing information is done using a `SimpleThings\EntityAudit\AuditReader` instance.

In Symfony2 the AuditReader is registered as the service "simplethings\_entityaudit.reader":

```
class DefaultController extends Controller
{
    public function indexAction()
    {
        $auditReader = $this->container->get('simplethings_entityaudit.reader');
    }
}
```

In a standalone application you can create the audit reader from the audit manager:

```
$auditReader = $auditManager->createAuditReader($entityManager);
```

### Find entity state at a particular revision

[](#find-entity-state-at-a-particular-revision)

This command also returns the state of the entity at the given revision, even if the last change to that entity was made in a revision before the given one:

```
$articleAudit = $auditReader->find(
    'SimpleThings\EntityAudit\Tests\ArticleAudit',
    $id = 1,
    $rev = 10
);
```

Instances created through `AuditReader#find()` are *NOT* injected into the EntityManagers UnitOfWork, they need to be merged into the EntityManager if it should be reattached to the persistence context in that old version.

### Find Revision History of an audited entity

[](#find-revision-history-of-an-audited-entity)

```
$revisions = $auditReader->findRevisions(
    'SimpleThings\EntityAudit\Tests\ArticleAudit',
    $id = 1
);
```

A revision has the following API:

```
class Revision
{
    public function getRev();
    public function getTimestamp();
    public function getUsername();
}
```

### Find Changed Entities at a specific revision

[](#find-changed-entities-at-a-specific-revision)

```
$changedEntities = $auditReader->findEntitiesChangedAtRevision(10);
```

A changed entity has the API:

```
class ChangedEntity
{
    public function getClassName();
    public function getId();
    public function getRevisionType();
    public function getEntity();
}
```

### Find Current Revision of an audited Entity

[](#find-current-revision-of-an-audited-entity)

```
$revision = $auditReader->getCurrentRevision(
    'SimpleThings\EntityAudit\Tests\ArticleAudit',
    $id = 3
);
```

Setting the Current Username
----------------------------

[](#setting-the-current-username)

Each revision automatically saves the username that changes it. For this to work you have to set the username. In the Symfony2 web context the username is automatically set to the one in the current security token.

In a standalone app or Symfony command you have to set the username to a specific value using the `AuditConfiguration`:

```
// Symfony2 context
$container->get('simplethings_entityaudit.config')->setCurrentUsername('beberlei');

// Standalone app
$auditConfig = new \SimpleThings\EntityAudit\AuditConfiguration();
$auditConfig->setCurrentUsername('beberlei');
```

Viewing auditing
----------------

[](#viewing-auditing)

A default Symfony2 controller is provided that gives basic viewing capabilities of audited data.

To use the controller, import the routing **(don't forget to secure the prefix you set so that only appropriate users can get access)**

\#####app/config/routing.yml

```
simple_things_entity_audit:
    resource: "@SimpleThingsEntityAuditBundle/Resources/config/routing.yml"
    prefix: /audit
```

This provides you with a few different routes:

- `simple_things_entity_audit_home` - Displays a paginated list of revisions, their timestamps and the user who performed the revision
- `simple_things_entity_audit_viewrevision` - Displays the classes that were modified in a specific revision
- `simple_things_entity_audit_viewentity` - Displays the revisions where the specified entity was modified
- `simple_things_entity_audit_viewentity_detail` - Displays the data for the specified entity at the specified revision
- `simple_things_entity_audit_compare` - Allows you to compare the changes of an entity between 2 revisions

TODOS
-----

[](#todos)

- Currently only works with auto-increment databases
- Proper metadata mapping is necessary, allow to disable versioning for fields and associations.
- It does NOT work with Joined-Table-Inheritance (Single Table Inheritance should work, but not tested)
- Many-To-Many associations are NOT versioned

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~161 days

Total

10

Last Release

3770d ago

PHP version history (2 changes)0.9.0PHP ^5.3.9

0.9.1PHP ^5.3.9|~7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/60215ae2b01a27e328be028abaa7104ef59a37a2730ba44f03ed0c11159b4c3d?d=identicon)[StasPiv](/maintainers/StasPiv)

---

Top Contributors

[![beberlei](https://avatars.githubusercontent.com/u/26936?v=4)](https://github.com/beberlei "beberlei (53 commits)")[![DavidBadura](https://avatars.githubusercontent.com/u/470138?v=4)](https://github.com/DavidBadura "DavidBadura (47 commits)")[![andrewtch](https://avatars.githubusercontent.com/u/925330?v=4)](https://github.com/andrewtch "andrewtch (40 commits)")[![merk](https://avatars.githubusercontent.com/u/278097?v=4)](https://github.com/merk "merk (11 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (5 commits)")[![tolry](https://avatars.githubusercontent.com/u/259744?v=4)](https://github.com/tolry "tolry (4 commits)")[![tommygnr](https://avatars.githubusercontent.com/u/929392?v=4)](https://github.com/tommygnr "tommygnr (4 commits)")[![welante](https://avatars.githubusercontent.com/u/547046?v=4)](https://github.com/welante "welante (3 commits)")[![smoench](https://avatars.githubusercontent.com/u/183530?v=4)](https://github.com/smoench "smoench (3 commits)")[![atsiddiqui](https://avatars.githubusercontent.com/u/308345?v=4)](https://github.com/atsiddiqui "atsiddiqui (3 commits)")[![bobvandevijver](https://avatars.githubusercontent.com/u/1835343?v=4)](https://github.com/bobvandevijver "bobvandevijver (3 commits)")[![JavierJimenez](https://avatars.githubusercontent.com/u/1233868?v=4)](https://github.com/JavierJimenez "JavierJimenez (2 commits)")[![iVariable](https://avatars.githubusercontent.com/u/427486?v=4)](https://github.com/iVariable "iVariable (2 commits)")[![mweimerskirch](https://avatars.githubusercontent.com/u/362092?v=4)](https://github.com/mweimerskirch "mweimerskirch (2 commits)")[![OskarStark](https://avatars.githubusercontent.com/u/995707?v=4)](https://github.com/OskarStark "OskarStark (2 commits)")[![dunglas](https://avatars.githubusercontent.com/u/57224?v=4)](https://github.com/dunglas "dunglas (2 commits)")[![TheRatG](https://avatars.githubusercontent.com/u/1580318?v=4)](https://github.com/TheRatG "TheRatG (2 commits)")[![rvanlaak](https://avatars.githubusercontent.com/u/2707563?v=4)](https://github.com/rvanlaak "rvanlaak (2 commits)")[![artursvonda](https://avatars.githubusercontent.com/u/147427?v=4)](https://github.com/artursvonda "artursvonda (2 commits)")[![zodeus](https://avatars.githubusercontent.com/u/238219?v=4)](https://github.com/zodeus "zodeus (1 commits)")

---

Tags

persistencedatabaseAudit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/staspiv-entity-audit-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/staspiv-entity-audit-bundle/health.svg)](https://phpackages.com/packages/staspiv-entity-audit-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M378](/packages/easycorp-easyadmin-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

6421.0M1](/packages/sonata-project-entity-audit-bundle)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58825.2M48](/packages/scienta-doctrine-json-functions)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1175.2k](/packages/rcsofttech-audit-trail-bundle)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4623.0M](/packages/damienharper-auditor-bundle)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1615.6k12](/packages/2lenet-crudit-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
