fastbolt / entity-archiver-bundle
Archives Doctrine entities
Installs: 414
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.4
Requires (Dev)
- doctrine/dbal: ^3.6
- doctrine/orm: ^2.17
- fig-r/psr2r-sniffer: ^1.3
- slevomat/coding-standard: ^7.0
- squizlabs/php_codesniffer: ^3.7
- symfony/config: ^6.3
- symfony/console: ^6.3
- symfony/http-kernel: ^6.3
- symfony/phpunit-bridge: ^6.3
This package is auto-updated.
Last update: 2024-11-08 16:52:15 UTC
README
EntityArchiverBundle handles automatic archiving or removal of doctrine entities in the application.
Installation:
composer require fastbolt/entity-archiver-bundle
You will need to create an entity-archiver.yaml file in your config directory. See 'Configuration' below.
To use the command, you will need to add the following line to the bundles.php:
Fastbolt\EntityArchiverBundle\EntityArchiverBundle::class => ['all' => true]
Execute by using this command:
php bin/console entity-archiver:run
Options:
--dry-run Will only display the results table, showing all entities from entity-archiver.yaml, the total number of entries in the origin table and the number of entities selected for archiving
--update-schema Will update the archive tables based on the configuration in entity-archiver.yaml
Configuration
Example:
#entity-archiver.yaml entity_archiver: table_suffix: archive entities: - entity: App\Entity\Log strategy: archive filters: - { type: age, age: 1, unit: months, field: created_at } archivingDateFieldName: archived_at fields: [ 'id', 'item_type', 'item_id', 'item_description', 'item_action', 'fk_client_id', 'fk_user_id' ]
table_suffix Suffix of the tables created by the bundle to hold the archived entities
addArchivedAt Wether to add a field for the archiving date in the archive table
archivingDateFieldName Field name of the generated date field holding the date when the archiving was done, default 'archived_at'
strategy What to do with the entity when it is selected to be archived
- remove Deletes the enitity using the 'id'-column
- archive Removes it from the original table and pastes a non-unique copy to the archive table
filters:
- type: age
- age integer
- unit ("days"/"months"/"years")
- field Entity field that is used to determin the age of the entry (Datetime)
Adding new Filters and Strategies: New filters need to implement the EntityArchivingFilterInterface, while strategies will need to implement the ArchivingStrategyInterface. Add the corresponding tag in the services.yaml.
Fastbolt\EntityArchiverBundle\Filter\AgeArchivingFilter: tags: [ 'fastbolt.archiver.filter' ] Fastbolt\EntityArchiverBundle\Strategy\ArchiveStrategy: tags: [ 'fastbolt.archiver.strategy' ]
Make doctrine ignore archive Tables: Doctrine will generate migrations to delete the generated archive tables, as they are not connected to an entity. To prevent that, add an exception to your doctrine configuration (replace '_archive' if you changed the table suffix):
#doctrine.yaml doctrine: dbal: schema_filter: ~^(?!.*_archive$)~