PHP code example of tourze / doctrine-cron-job-bundle
1. Go to this page and download the library: Download tourze/doctrine-cron-job-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tourze / doctrine-cron-job-bundle example snippets
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();
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();
use Tourze\DoctrineCronJobBundle\Provider\DoctrineProvider;
class CustomCronProvider extends DoctrineProvider
{
// Implement custom logic
}
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 * * *']);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.