somnambulist/laravel-doctrine-entity-audit

A port of the SimpleThings EntityAudit package re-worked for Laravel 5+

0.7.3 2021-06-10 19:42 UTC

This package is auto-updated.

Last update: 2024-10-20 01:44:02 UTC


README

GitHub Actions Build Status Issues License PHP Version Current Version

This is a fork of the SimpleThings EntityAudit project, re-worked for usage with Laravel and the Laravel-Doctrine package. It maintains the same style of working, generating a revision for all tagged entities.

Need a Symfony based version? Check out the original SimpleThings EntityAudit.

To protect from conflicts it has been re-namespaced and some internals changed.

Installation

  • composer require somnambulist/laravel-doctrine-entity-audit
  • add the ServiceProvider to your config/app.php after the Doctrine provider
  • ./artisan vendor:publish
  • update the config file and then generate the audit tables:
    • ./artisan doctrine:migrations:diff
    • ./artisan doctrine:migrations:migrate

Configuring UserResolver

The UserResolver implementation may be switched out for another implementation by implementing the UserResolverInterface and binding this to the container in your AppServiceProvider. This needs to be during registration and not boot.

Alternatively: the UserResolver may be switched out at run time by accessing the AuditConfiguration from the AuditRegistry for the entity manager and setting a new resolver instance:

use Somnambulist\EntityAudit\AuditRegistry;

$app->get(AuditRegistry::class)->get(/* $emName */)->getConfiguration()->setUserResolver($resolver);

If the entity manager name is not specified, the default will be chosen. Note that the configuration is shared with the AuditReader. It is recommended to set the UserResolver this way as early as possible and preferably before loading and modifying any entities to avoid issues with user resolution.

Unit Tests

The existing unit tests have been ported over excluding the Gedmo soft-deleteable. To run the unit tests, ensure the dev dependencies have been installed:

  • vendor/bin/phpunit

Todo

  • refactor and simplify the listener internals
  • remove any remaining deprecated Doctrine API calls

From SimpleThings:

  • currently only works with auto-increment databases
  • proper metadata mapping is necessary, allow to disable versioning for fields and associations.
  • support Joined-Table-Inheritance
  • support many-to-many auditing

Links