fastbolt / entity-archiver-bundle
归档 Doctrine 实体
dev-main
2023-12-08 14:41 UTC
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-09-08 16:27:04 UTC
README
EntityArchiverBundle 处理应用程序中 Doctrine 实体的自动归档或删除。
安装
composer require fastbolt/entity-archiver-bundle
您需要在配置目录中创建一个 entity-archiver.yaml 文件。请参见下方的 '配置'。
要使用命令,您需要在 bundles.php 中添加以下行
Fastbolt\EntityArchiverBundle\EntityArchiverBundle::class => ['all' => true]
使用此命令执行
php bin/console entity-archiver:run
选项
--dry-run 只显示结果表,显示 entity-archiver.yaml 中的所有实体,原始表中的条目总数以及选择的归档实体数量
--update-schema 将根据 entity-archiver.yaml 中的配置更新归档表
配置
示例
#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)
添加新的过滤器和技术: 新的过滤器需要实现 EntityArchivingFilterInterface,而策略需要实现 ArchivingStrategyInterface。在 services.yaml 中添加相应的标签。
Fastbolt\EntityArchiverBundle\Filter\AgeArchivingFilter: tags: [ 'fastbolt.archiver.filter' ] Fastbolt\EntityArchiverBundle\Strategy\ArchiveStrategy: tags: [ 'fastbolt.archiver.strategy' ]
使 doctrine 忽略归档表: Doctrine 将生成迁移以删除生成的归档表,因为它们与实体没有关联。为了防止这种情况,请将异常添加到您的 doctrine 配置中(如果更改了表后缀,请将 '_archive' 替换掉)。
#doctrine.yaml doctrine: dbal: schema_filter: ~^(?!.*_archive$)~