Download the PHP package tourze/symfony-schedule-entity-clean-bundle without Composer
On this page you can find all versions of the php package tourze/symfony-schedule-entity-clean-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tourze/symfony-schedule-entity-clean-bundle
More information about tourze/symfony-schedule-entity-clean-bundle
Files in tourze/symfony-schedule-entity-clean-bundle
Package symfony-schedule-entity-clean-bundle
Short Description Symfony bundle for automatic scheduled cleanup of Doctrine entities based on creation time and cron expressions
License MIT
Informations about the package symfony-schedule-entity-clean-bundle
Symfony Schedule Entity Clean Bundle
中文
[]
(https://packagist.org/packages/tourze/symfony-schedule-entity-clean-bundle)
[
]
(https://packagist.org/packages/tourze/symfony-schedule-entity-clean-bundle)
[
]
(https://packagist.org/packages/tourze/symfony-schedule-entity-clean-bundle)
[
]
(https://github.com/tourze/php-monorepo/actions)
[
]
(https://codecov.io/gh/tourze/php-monorepo)
A Symfony bundle for automatically cleaning old entity data based on scheduled cron expressions.
Features
- Automatically clean old entity data based on cron expressions
- Configurable retention period for each entity
- Custom retention period via environment variables
- Asynchronous processing using Symfony Messenger
- Event dispatching after cleaning operations
Table of Contents
- Features
- Installation
- Quick Start
- Configuration
- Console Commands
- Events
- Advanced Usage
- Requirements
- License
Installation
Register the bundle in your bundles.php:
Quick Start
-
Mark your entity class with the
AsScheduleCleanattribute: -
Ensure your entity has a
createTimefield. The bundle uses this field to determine which records to delete. - The bundle will automatically register a cron job that runs every minute to check if any entities need cleaning.
Configuration
The AsScheduleClean attribute accepts the following parameters:
expression: A cron expression that determines when to clean the entity (default: '0 0 *', which runs at midnight every day)defaultKeepDay: The number of days to keep records (default: 7)keepDayEnv: An optional environment variable name that can override the defaultKeepDay value
Console Commands
schedule-entity-clean:run
This command is responsible for periodically cleaning entity data based on the
configured cron expressions. It runs every minute by default and checks all
entities marked with the AsScheduleClean attribute.
The command:
- Scans all entities for
AsScheduleCleanattributes - Checks if the cron expression is due for execution
- Verifies that entities have a
createTimefield - Dispatches asynchronous cleanup messages for eligible entities
Usage:
Note: This command is automatically registered as a cron job and runs every minute. You don't need to call it manually unless for testing purposes.
Advanced Usage
Environment Variable Configuration
You can override the default keep days using environment variables:
Then set the environment variable:
Multiple Cleaning Schedules
You can apply multiple cleaning schedules to the same entity:
Events
The bundle dispatches a ScheduleEntityCleanFinishEvent after successfully
cleaning entity data. You can listen to this event to perform custom actions
after the cleaning process.
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM
- Entity must have a
createTimefield
License
The MIT License (MIT). Please see License File for more information.
All versions of symfony-schedule-entity-clean-bundle with dependencies
doctrine/doctrine-bundle Version ^2.13
doctrine/orm Version ^3.0
doctrine/persistence Version ^4.1
dragonmantank/cron-expression Version ^3.4
easycorp/easyadmin-bundle Version ^4
knplabs/knp-menu Version ^3.7
monolog/monolog Version ^3.1
psr/log Version ^3|^2|^1
symfony/config Version ^7.3
symfony/console Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/doctrine-bridge Version ^7.3
symfony/event-dispatcher Version ^7.3
symfony/event-dispatcher-contracts Version ^3
symfony/framework-bundle Version ^7.4
symfony/http-kernel Version ^7.3
symfony/messenger Version ^7.3
symfony/property-access Version ^7.3
symfony/yaml Version ^7.3
tourze/async-contracts Version 1.0.*
tourze/bundle-dependency Version 1.*
tourze/easy-admin-menu-bundle Version 1.0.*
tourze/symfony-cron-job-bundle Version 1.1.*
tourze/symfony-dependency-service-loader Version 1.0.*