tourze / doctrine-track-bundle
实体跟踪
0.0.2
2025-04-10 05:38 UTC
Requires
- php: ^8.1
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^2.17 || ^3.0
- psr/log: ^3|^2|^1
- psr/simple-cache: ^1.0|^2.0|^3.0
- symfony/framework-bundle: ^6.4
- symfony/property-access: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/doctrine-async-bundle: 0.0.*
- tourze/doctrine-entity-checker-bundle: 0.0.*
- tourze/doctrine-helper: 0.0.*
- tourze/doctrine-indexed-bundle: 0.0.*
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/doctrine-user-bundle: 0.0.*
- tourze/request-id-bundle: 0.0.*
- tourze/symfony-schedule-entity-clean-bundle: 0.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
This package is auto-updated.
Last update: 2025-04-20 21:38:19 UTC
README
A Symfony bundle for tracking entity changes and logging them to the database. It helps you audit and review changes to important entities in your application.
Features
- Automatically logs create, update, and delete operations for marked entities
- Tracks only fields annotated with
TrackColumn
- Records user, IP, request ID, and change details
- Asynchronous log persistence
- Built-in entity log cleanup scheduling
Installation
- PHP >= 8.1
- Symfony >= 6.4
- Doctrine ORM >= 2.20
Install via Composer:
composer require tourze/doctrine-track-bundle
Quick Start
- Mark entity fields you want to track with
#[TrackColumn]
. - Register the bundle in your Symfony project (if not using Flex).
- Ensure your entities use an
id
property as primary key. - Run migrations to create the
entity_track_log
table.
Example:
use Tourze\DoctrineTrackBundle\Attribute\TrackColumn; class ExampleEntity { #[TrackColumn] private string $importantField; // ... }
Detailed Documentation
- The bundle listens to Doctrine events (
postPersist
,postUpdate
,preRemove
,postRemove
). - Only properties with
#[TrackColumn]
are tracked. - Logs are saved asynchronously to the
entity_track_log
table. - Each log contains: entity class, entity id, action (create/update/remove), changed data, user, IP, request ID, and timestamp.
- Log cleanup is scheduled with a default retention (180 days, configurable via
ENTITY_TRACK_LOG_PERSIST_DAY_NUM
).
Configuration
No mandatory configuration. You may set the retention period via environment variable:
ENTITY_TRACK_LOG_PERSIST_DAY_NUM=180
Contributing
- Please submit issues or pull requests via GitHub.
- Follow PSR coding standards.
- Add tests for new features.
License
MIT License. See LICENSE for details.
Changelog
See Releases for version history.