gtt / doctrine-auditable-bundle
Doctrine auditable bundle is alternative for DoctrineExtensions Loggable
Installs: 1 063
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 8
Forks: 7
Open Issues: 3
Type:symfony-bundle
Requires
- php: ~8.0
- doctrine/doctrine-bundle: ~2.0
- doctrine/orm: ~2.10
- symfony/config: ~5.4 || ~6.0
- symfony/dependency-injection: ~5.4 || ~6.0
- symfony/http-kernel: ~5.4 || ~6.0
- symfony/property-access: ~5.4 || ~6.0
Requires (Dev)
- mikey179/vfsstream: ^1.6.10
- phpunit/phpunit: ^9.5
- symfony/framework-bundle: ~5.4 || ~6.0
- symfony/phpunit-bridge: ^6.0
- symfony/proxy-manager-bridge: ~5.4 || ~6.0
- symfony/security-bundle: ~5.4 || ~6.0
Suggests
- symfony/security-core: For logging user made change
README
Auditable behavioral implementation helps tracking changes and history of objects. Fast and lightweight alternative for DoctrineExtensions Loggable with some features. Supports only ORM.
Features
- Group of changes
- Comments for changes
- Convenient store (tracked values before and after change stored in the separated columns, instead serialized entity data in the Loggable)
- Supports custom DBAL types
- Supports class inheritance configuration
Installation
- Install bundle
composer require "gtt/doctrine-auditable-bundle"
- Add to Kernel.php
public function registerBundles() { $bundles = array( ... new Gtt\Bundle\DoctrineAuditableBundle\DoctrineAuditableBundle(), ); ... }
- Create tables for changes storing
bin/console doctrine:schema:update --force
- Configure mapping if needed.
Usage
Add attributes for tracking property
<?php use Gtt\Bundle\DoctrineAuditableBundle\Mapping\Annotation as Auditable; /** * My entity */ #[ORM\Entity] #[ORM\Table(name: 'entity')] #[Auditable\Entity] class Entity { #[ORM\Column(name: 'assigned_user', type: 'string', length: 255)] #[Auditable\Property] protected string $assignedUser; ... }
Then somewhere in a service change an entity property and flush the changes.
<?php use Doctrine\ORM\EntityManagerInterface; use Gtt\Bundle\DoctrineAuditableBundle as Auditable; class PayloadService { private Auditable\Log\Store $auditable; private EntityManagerInterface $entityManager; /** * Operate! */ public function payloadMethod(YourDomain\Entity $entity): void { // 1. change some property that supposed to be logged to changelog $entity->updateProperty(); // ... just dummy example // 2. describe this change $this->auditable->describe($entity, 'Change description'); // 3. perform update $this->entityManager->flush(); } }