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

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

prolix/entity-audit-bundle
==========================

Audit for Doctrine Entities

v1.0.10(6y ago)0487LGPL-2.1PHPPHP ^5.3.9|~7.0

Since Mar 6Pushed 6y agoCompare

[ Source](https://github.com/prolixtechnikos/EntityAuditBundle)[ Packagist](https://packagist.org/packages/prolix/entity-audit-bundle)[ RSS](/packages/prolix-entity-audit-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (29)Used By (0)

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

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

Master1.0 Branch[![Build Status](https://camo.githubusercontent.com/793fde0c3498edcaf15f1dc4a3a0d66806ad6adb0cba696709893a37c285b172/68747470733a2f2f7472617669732d63692e6f72672f73696d706c657468696e67732f456e74697479417564697442756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/simplethings/EntityAuditBundle)[![Build Status](https://camo.githubusercontent.com/f7a14fa3b10b95f9d5091995d3df8bfb017e1e17f644213279aec5bc4cc7ab59/68747470733a2f2f7472617669732d63692e6f72672f73696d706c657468696e67732f456e74697479417564697442756e646c652e7376673f6272616e63683d312e30)](https://travis-ci.org/simplethings/EntityAuditBundle)[documentation](https://github.com/simplethings/EntityAuditBundle/blob/master/README.md)[documentation](https://github.com/simplethings/EntityAudit/blob/1.0/README.md)**WARNING: Master isn't stable yet and it might not be working! Please use version `^1.0` and this documentation: **

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

Is this library still maintained?
---------------------------------

[](#is-this-library-still-maintained)

[Maybe?](https://github.com/simplethings/EntityAudit/issues/203) - please discuss and support us in the linked issue

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 (Standalone)
-------------------------

[](#installation-standalone)

### Installing the lib/bundle

[](#installing-the-libbundle)

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

```
$ composer require simplethings/entity-audit-bundle
```

For standalone usage you have to pass the EntityManager.

```
use Doctrine\ORM\EntityManager;
use SimpleThings\EntityAudit\AuditManager;

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

$auditManager = AuditManager::create($em);
```

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

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

### Enable the bundle

[](#enable-the-bundle)

Enable the bundle in the kernel:

```
// app/AppKernel.php

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

### Configuration

[](#configuration)

You can configure the audited tables.

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

[](#appconfigconfigyml)

```
simple_things_entity_audit:
    entity_manager: default
    table_prefix: ''
    table_suffix: _audit
    revision_field_name: rev
    revision_type_field_name: revtype
    revision_table_name: revisions
    revision_id_field_type: integer
```

### Creating new tables

[](#creating-new-tables)

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

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

Usage
-----

[](#usage)

### Define auditable entities

[](#define-auditable-entities)

You need add `Auditable` annotation for the entities which you want to auditable.

```
use Doctrine\ORM\Mapping as ORM;
use SimpleThings\EntityAudit\Mapping\Annotation as Audit;

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

You can also ignore fields in an specific entity.

```
class Page {

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

}
```

### Use AuditReader

[](#use-auditreader)

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

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

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

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.manager')->createAuditReader();
    }
}
```

### 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, the username must be resolved.

In the Symfony2 web context the username is resolved from the one in the current security context token.

You can override this with your own behaviour by configuring the `username_callable` service in the bundle configuration. Your custom service must be a `callable` and should return a `string` or `null`.

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

[](#appconfigconfigyml-1)

```
simple_things_entity_audit:
    service:
        username_callable: acme.username_callable
```

In a standalone app or Symfony command you can username callable to a specific value using the `AuditConfiguration`.

```
$auditConfig = new \SimpleThings\EntityAudit\AuditConfiguration();
$auditConfig->setUsernameCallable(function () {
	$username = //your customer logic
    return username;
});
```

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

[](#appconfigroutingyml)

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

Supported DB
------------

[](#supported-db)

- MySQL / MariaDB
- PostgesSQL
- SQLite

*We can only really support the databases if we can test them via Travis.*

Contributing
------------

[](#contributing)

Please before commiting, run this command `./vendor/bin/php-cs-fixer fix --verbose` to normalize the coding style.

If you already have the fixer locally you can run `php-cs-fixer fix .`.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity69

Established project with proven stability

 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 ~131 days

Recently: every ~169 days

Total

23

Last Release

2295d ago

Major Versions

v0.9.2 → v1.0.02017-01-05

PHP version history (3 changes)0.9.0PHP ^5.3.9

0.9.1PHP ^5.3.9|~7.0

v1.0.1PHP ^5.6|~7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f7ebbb7fd8d5bed650ff90bfa01d5c9962199a26d76f25439702a1ab92e4caf?d=identicon)[kuldippujara](/maintainers/kuldippujara)

---

Top Contributors

[![DavidBadura](https://avatars.githubusercontent.com/u/470138?v=4)](https://github.com/DavidBadura "DavidBadura (115 commits)")[![beberlei](https://avatars.githubusercontent.com/u/26936?v=4)](https://github.com/beberlei "beberlei (53 commits)")[![andrewtch](https://avatars.githubusercontent.com/u/925330?v=4)](https://github.com/andrewtch "andrewtch (40 commits)")[![bendavies](https://avatars.githubusercontent.com/u/625392?v=4)](https://github.com/bendavies "bendavies (36 commits)")[![smoench](https://avatars.githubusercontent.com/u/183530?v=4)](https://github.com/smoench "smoench (18 commits)")[![merk](https://avatars.githubusercontent.com/u/278097?v=4)](https://github.com/merk "merk (11 commits)")[![tolry](https://avatars.githubusercontent.com/u/259744?v=4)](https://github.com/tolry "tolry (6 commits)")[![Cr8tiveDav](https://avatars.githubusercontent.com/u/114363324?v=4)](https://github.com/Cr8tiveDav "Cr8tiveDav (6 commits)")[![soullivaneuh](https://avatars.githubusercontent.com/u/1698357?v=4)](https://github.com/soullivaneuh "soullivaneuh (5 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (5 commits)")[![tseho](https://avatars.githubusercontent.com/u/1421130?v=4)](https://github.com/tseho "tseho (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)")[![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)")[![c0ntax](https://avatars.githubusercontent.com/u/1075300?v=4)](https://github.com/c0ntax "c0ntax (3 commits)")[![JavierJimenez](https://avatars.githubusercontent.com/u/1233868?v=4)](https://github.com/JavierJimenez "JavierJimenez (3 commits)")[![TheRatG](https://avatars.githubusercontent.com/u/1580318?v=4)](https://github.com/TheRatG "TheRatG (3 commits)")[![rvanlaak](https://avatars.githubusercontent.com/u/2707563?v=4)](https://github.com/rvanlaak "rvanlaak (2 commits)")[![mweimerskirch](https://avatars.githubusercontent.com/u/362092?v=4)](https://github.com/mweimerskirch "mweimerskirch (2 commits)")

---

Tags

persistencedatabaseAudit

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[doctrine/doctrine-bundle

Symfony DoctrineBundle

4.8k241.3M3.3k](/packages/doctrine-doctrine-bundle)[scienta/doctrine-json-functions

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

58523.9M36](/packages/scienta-doctrine-json-functions)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[bartlett/php-compatinfo-db

Reference Database of all functions, constants, classes, interfaces on PHP standard distribution and about 110 extensions

1183.0k1](/packages/bartlett-php-compatinfo-db)[tawfekov/zf2entityaudit

EntityAudit Module for Zend Framework2 , Doctrine2 and web interface

1910.4k](/packages/tawfekov-zf2entityaudit)

PHPackages © 2026

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