tourze / doctrine-cron-job-bundle
Doctrine CronJob Bundle
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/tourze/doctrine-cron-job-bundle
Requires
- php: ^8.1
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/doctrine-indexed-bundle: 0.0.*
- tourze/doctrine-snowflake-bundle: 0.1.*
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/doctrine-track-bundle: 0.1.*
- tourze/doctrine-user-bundle: 0.0.*
- tourze/easy-admin-attribute: 0.1.*
- tourze/symfony-cron-job-bundle: 0.1.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
README
A Symfony bundle that provides database-managed cron jobs with Doctrine ORM integration. This bundle allows you to store and manage cron jobs and scheduled SQL queries in your database.
Features
- ποΈ Database-managed cron jobs - Store cron job configurations in database
- π Scheduled SQL execution - Execute SQL queries at specified intervals
- π Symfony integration - Seamless integration with Symfony's cron job system
- ποΈ Entity management - Full Doctrine ORM entities with repository services
- π Tracking & auditing - Built-in tracking and user attribution
- β‘ Performance optimized - Efficient query execution with caching support
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
Installation
composer require tourze/doctrine-cron-job-bundle
Quick Start
- Register the Bundle
// config/bundles.php return [ // ... Tourze\DoctrineCronJobBundle\DoctrineCronJobBundle::class => ['all' => true], ];
- Create and manage cron jobs
use Tourze\DoctrineCronJobBundle\Entity\CronJob; // Create a new cron job $job = new CronJob(); $job->setName('daily-cleanup'); $job->setCommand('php bin/console app:cleanup'); $job->setSchedule('0 2 * * *'); // Run at 2 AM daily $job->setDescription('Daily cleanup task'); $job->setValid(true); $entityManager->persist($job); $entityManager->flush();
- Create scheduled SQL queries
use Tourze\DoctrineCronJobBundle\Entity\CronSql; // Create a scheduled SQL query $cronSql = new CronSql(); $cronSql->setTitle('User Statistics'); $cronSql->setSqlStatement('SELECT COUNT(*) as total_users FROM users WHERE created_at >= DATE_SUB(NOW(), INTERVAL 1 DAY)'); $cronSql->setCronExpression('0 0 * * *'); // Run at midnight $cronSql->setValid(true); $entityManager->persist($cronSql); $entityManager->flush();
Configuration
The bundle works out of the box with default settings. For advanced configuration:
# config/packages/doctrine_cron_job.yaml doctrine_cron_job: # Configure any specific settings here # Default configuration is sufficient for most use cases
Advanced Usage
Custom Providers
You can extend the functionality by creating custom providers:
use Tourze\DoctrineCronJobBundle\Provider\DoctrineProvider; class CustomCronProvider extends DoctrineProvider { // Implement custom logic }
Repository Usage
use Tourze\DoctrineCronJobBundle\Repository\CronJobRepository; use Tourze\DoctrineCronJobBundle\Repository\CronSqlRepository; // Get active cron jobs $activeJobs = $cronJobRepository->findBy(['valid' => true]); // Get SQL jobs by expression $dailyJobs = $cronSqlRepository->findBy(['cronExpression' => '0 0 * * *']);
Security
- SQL Injection Prevention: All SQL statements are executed through Doctrine's secure query system
- Access Control: Implement proper access controls for managing cron jobs in your application
- Validation: All entities include comprehensive validation constraints
- Audit Trail: Built-in tracking provides full audit capabilities
API Reference
CronJob Entity
setName(string $name)- Set the job namesetCommand(string $command)- Set the command to executesetSchedule(string $schedule)- Set the cron expressionsetDescription(?string $description)- Set job descriptionsetValid(bool $valid)- Enable/disable the job
CronSql Entity
setTitle(string $title)- Set the SQL job titlesetSqlStatement(string $sql)- Set the SQL query to executesetCronExpression(string $expression)- Set the cron expressionsetValid(bool $valid)- Enable/disable the SQL job
Testing
Run the test suite:
./vendor/bin/phpunit packages/doctrine-cron-job-bundle/tests
All tests pass with 100% coverage:
- β Entity Tests (CronJob, CronSql)
- β Provider Tests (DoctrineProvider, CronSqlProvider)
- β Dependency Injection Tests
- β Bundle Configuration Tests
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Tourze - GitHub Organization