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

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

sonata-project/entity-audit-bundle
==================================

Audit for Doctrine Entities

1.23.1(1mo ago)644989.8k↓12.8%260[4 issues](https://github.com/sonata-project/EntityAuditBundle/issues)1MITPHPPHP ^8.2CI passing

Since Mar 6Pushed 4mo ago25 watchersCompare

[ Source](https://github.com/sonata-project/EntityAuditBundle)[ Packagist](https://packagist.org/packages/sonata-project/entity-audit-bundle)[ GitHub Sponsors](https://github.com/VincentLanglet)[ GitHub Sponsors](https://github.com/jordisala1991)[ RSS](/packages/sonata-project-entity-audit-bundle/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (10)Dependencies (64)Versions (59)Used By (1)

EntityAuditBundle
=================

[](#entityauditbundle)

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

[![Latest Stable Version](https://camo.githubusercontent.com/669e2c22ee2d1e4b91be4f2e5238d8e0b2cc24200dbc69d898ad93ccc6f5bb4b/68747470733a2f2f706f7365722e707567782e6f72672f736f6e6174612d70726f6a6563742f656e746974792d61756469742d62756e646c652f762f737461626c65)](https://packagist.org/packages/sonata-project/entity-audit-bundle)[![Latest Unstable Version](https://camo.githubusercontent.com/c54b2653226b0d7e9bbbed7448fddc356d92caf269f25d87e0534895ca70dad4/68747470733a2f2f706f7365722e707567782e6f72672f736f6e6174612d70726f6a6563742f656e746974792d61756469742d62756e646c652f762f756e737461626c65)](https://packagist.org/packages/sonata-project/entity-audit-bundle)[![License](https://camo.githubusercontent.com/97be510f099ec8ad934a686303ac5b3b54bf08ba3c66b2d9eb9aed4f405b46f1/68747470733a2f2f706f7365722e707567782e6f72672f736f6e6174612d70726f6a6563742f656e746974792d61756469742d62756e646c652f6c6963656e7365)](https://packagist.org/packages/sonata-project/entity-audit-bundle)

[![Total Downloads](https://camo.githubusercontent.com/a4f4de05e3d9471ae958e7646c97551334672dc5cf4966db6b3041a62cebe846/68747470733a2f2f706f7365722e707567782e6f72672f736f6e6174612d70726f6a6563742f656e746974792d61756469742d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/sonata-project/entity-audit-bundle)[![Monthly Downloads](https://camo.githubusercontent.com/5ada8014c5ae7b5123ddf5d6885b683c26719906628ae2fe8476b137cf295924/68747470733a2f2f706f7365722e707567782e6f72672f736f6e6174612d70726f6a6563742f656e746974792d61756469742d62756e646c652f642f6d6f6e74686c79)](https://packagist.org/packages/sonata-project/entity-audit-bundle)[![Daily Downloads](https://camo.githubusercontent.com/e56de116bbba081b8cbf591bc2d21950975396f1ea84bb71ec24917401f2fafa/68747470733a2f2f706f7365722e707567782e6f72672f736f6e6174612d70726f6a6563742f656e746974792d61756469742d62756e646c652f642f6461696c79)](https://packagist.org/packages/sonata-project/entity-audit-bundle)

BranchGithub ActionsCode Coverage1.x[![Test](https://github.com/sonata-project/EntityAuditBundle/workflows/Test/badge.svg?branch=1.x)](https://github.com/sonata-project/EntityAuditBundle/actions?query=workflow:test+branch:1.x)[![Coverage Status](https://camo.githubusercontent.com/a25571ff6f3e4b1b7c751b1aba059bbd6ed9593a5c0938d62aa880e42cb88895/68747470733a2f2f636f6465636f762e696f2f67682f736f6e6174612d70726f6a6563742f456e74697479417564697442756e646c652f6272616e63682f312e782f67726170682f62616467652e737667)](https://codecov.io/gh/sonata-project/EntityAuditBundle/branch/1.x)2.x.[![Test](https://github.com/sonata-project/EntityAuditBundle/workflows/Test/badge.svg?branch=2.x)](https://github.com/sonata-project/EntityAuditBundle/actions?query=workflow:test+branch:2.x)[![Coverage Status](https://camo.githubusercontent.com/c1fa1fa532198cc27d4307bdd8efdc9e6adcb8f1969e4feecc109f219484d1c6/68747470733a2f2f636f6465636f762e696f2f67682f736f6e6174612d70726f6a6563742f456e74697479417564697442756e646c652f6272616e63682f322e782f67726170682f62616467652e737667)](https://codecov.io/gh/sonata-project/EntityAuditBundle/branch/2.x)Support
-------

[](#support)

For general support and questions, please use [StackOverflow](http://stackoverflow.com/questions/tagged/sonata).

If you think you found a bug or you have a feature idea to propose, feel free to open an issue **after looking** at the [contributing guide](CONTRIBUTING.md).

License
-------

[](#license)

This package is available under the [LGPL license](LICENSE).

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

[](#installation)

### Installing the bundle

[](#installing-the-bundle)

Simply run assuming you have composer:

```
$ composer require sonata-project/entity-audit-bundle
```

### Enable the bundle

[](#enable-the-bundle)

Finally, enable the bundle in the kernel:

```
// config/bundles.php

return [
    //...
    SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle::class => ['all' => true],
    //...
];
```

### Configuration

[](#configuration)

Load extension "simple\_things\_entity\_audit" and specify the audited entities

```
# config/packages/entity_audit.yaml

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:

```
# config/packages/entity_audit.yaml

simple_things_entity_audit:
    global_ignore_columns:
        - created_at
        - updated_at
```

In order to work with other connection or entity manager than "default", use these settings:

```
# config/packages/entity_audit.yaml

simple_things_entity_audit:
    connection: custom
    entity_manager: custom
```

If you need to explicitly discard the foreign keys inferred from the audited entities, you can use the `disable_foreign_keys` parameter:

```
simple_things_entity_audit:
    disable_foreign_keys: true
```

### Creating new tables

[](#creating-new-tables)

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

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

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\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\EventManager;
use SimpleThings\EntityAudit\AuditConfiguration;
use SimpleThings\EntityAudit\AuditManager;
use SimpleThings\EntityAudit\Tests\ArticleAudit;
use SimpleThings\EntityAudit\Tests\UserAudit;

$auditConfig = new AuditConfiguration();
$auditConfig->setAuditedEntityClasses([ArticleAudit::class, UserAudit::class]);
$auditConfig->setGlobalIgnoreColumns(['created_at', 'updated_at']);

$eventManager = new EventManager();
$auditManager = new AuditManager($auditConfig);
$auditManager->registerEvents($eventManager);

$config = new Configuration();
// $config ...
$connection = [];
$entityManager = EntityManager::create($connection, $config, $eventManager);
```

Usage
-----

[](#usage)

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

```
use SimpleThings\EntityAudit\AuditReader;

class DefaultController extends Controller
{
    public function indexAction(AuditReader $auditReader)
    {
    }
}
```

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::class,
    $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::class,
    $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 Symfony 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`.

```
# config/packages/entity_audit.yaml

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

In a standalone app or Symfony command you can set an 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 Symfony 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)**

```
# config/routes.yaml

simple_things_entity_audit:
    resource: "@SimpleThingsEntityAuditBundle/Resources/config/routing/audit.xml"
    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)

###  Health Score

71

—

ExcellentBetter than 100% of packages

Maintenance81

Actively maintained with recent releases

Popularity63

Solid adoption and visibility

Community36

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 Bus Factor4

4 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 ~93 days

Recently: every ~39 days

Total

56

Last Release

55d ago

Major Versions

v0.9.2 → v1.0.02017-01-05

1.23.1 → 2.x-dev2026-03-25

PHP version history (8 changes)0.9.0PHP ^5.3.9

0.9.1PHP ^5.3.9|~7.0

v1.0.1PHP ^5.6|~7.0

1.1.0PHP ^7.3 || ^8.0

1.8.0PHP ^7.4 || ^8.0

1.13.0PHP ^8.0

1.19.0PHP ^8.1

1.23.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/404157?v=4)[Sonata Project](/maintainers/sonata-project)[@sonata-project](https://github.com/sonata-project)

---

Top Contributors

[![SonataCI](https://avatars.githubusercontent.com/u/12843093?v=4)](https://github.com/SonataCI "SonataCI (97 commits)")[![VincentLanglet](https://avatars.githubusercontent.com/u/9052536?v=4)](https://github.com/VincentLanglet "VincentLanglet (89 commits)")[![DavidBadura](https://avatars.githubusercontent.com/u/470138?v=4)](https://github.com/DavidBadura "DavidBadura (62 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)")[![jordisala1991](https://avatars.githubusercontent.com/u/1137485?v=4)](https://github.com/jordisala1991 "jordisala1991 (19 commits)")[![phansys](https://avatars.githubusercontent.com/u/1231441?v=4)](https://github.com/phansys "phansys (18 commits)")[![franmomu](https://avatars.githubusercontent.com/u/720690?v=4)](https://github.com/franmomu "franmomu (12 commits)")[![tolry](https://avatars.githubusercontent.com/u/259744?v=4)](https://github.com/tolry "tolry (12 commits)")[![merk](https://avatars.githubusercontent.com/u/278097?v=4)](https://github.com/merk "merk (11 commits)")[![X-Coder264](https://avatars.githubusercontent.com/u/12602463?v=4)](https://github.com/X-Coder264 "X-Coder264 (9 commits)")[![smoench](https://avatars.githubusercontent.com/u/183530?v=4)](https://github.com/smoench "smoench (7 commits)")[![dmaicher](https://avatars.githubusercontent.com/u/921145?v=4)](https://github.com/dmaicher "dmaicher (7 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (6 commits)")[![wbloszyk](https://avatars.githubusercontent.com/u/2255674?v=4)](https://github.com/wbloszyk "wbloszyk (5 commits)")[![tommygnr](https://avatars.githubusercontent.com/u/929392?v=4)](https://github.com/tommygnr "tommygnr (4 commits)")[![bobvandevijver](https://avatars.githubusercontent.com/u/1835343?v=4)](https://github.com/bobvandevijver "bobvandevijver (3 commits)")[![soullivaneuh](https://avatars.githubusercontent.com/u/1698357?v=4)](https://github.com/soullivaneuh "soullivaneuh (3 commits)")[![TheRatG](https://avatars.githubusercontent.com/u/1580318?v=4)](https://github.com/TheRatG "TheRatG (3 commits)")

---

Tags

auditbundledatabasepersistencephpsonatasymfonysymfony-bundlepersistencedatabaseAudit

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

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