diff --git a/README.md b/README.md index fda9412..d56e70f 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ The tag takes the following arguments: - `name`: `ezplatform.cron.job` - `schedule`: _Takes any kind of [format supported by cron/cron](https://github.com/Cron/Cron#crontab-syntax), which mimics linux crontab format. E.g. `* * * * *`_ - `category`: _(Optional, by default: `default`) Lets you separate cronjobs that should be run under different logic then default, e.g. infrequent jobs (NOTE: Means end user will need to setup several entries in his crontab to run all categories!)_ +- `options`: _(Optional, by default: `''`) Takes custom option/s in string format which are added to the command. (E.g. '--keep=0 --status=draft' for running the cleanup versions command)_ ### Example diff --git a/src/bundle/DependencyInjection/Compiler/CronJobCompilerPass.php b/src/bundle/DependencyInjection/Compiler/CronJobCompilerPass.php index 8bd953b..92f0604 100644 --- a/src/bundle/DependencyInjection/Compiler/CronJobCompilerPass.php +++ b/src/bundle/DependencyInjection/Compiler/CronJobCompilerPass.php @@ -43,6 +43,7 @@ public function process(ContainerBuilder $container) $reference, $cronJob['schedule'], $cronJob['category'], + $cronJob['options'] ?? '', ]); } } diff --git a/src/bundle/Registry/CronJobsRegistry.php b/src/bundle/Registry/CronJobsRegistry.php index c49853c..fec5fa2 100644 --- a/src/bundle/Registry/CronJobsRegistry.php +++ b/src/bundle/Registry/CronJobsRegistry.php @@ -36,6 +36,11 @@ class CronJobsRegistry */ protected $siteaccess; + /** + * @var string + */ + protected $options; + public function __construct(string $environment, SiteAccess $siteaccess) { $finder = new PhpExecutableFinder(); @@ -45,12 +50,13 @@ public function __construct(string $environment, SiteAccess $siteaccess) $this->siteaccess = $siteaccess; } - public function addCronJob(Command $command, string $schedule = null, string $category = self::DEFAULT_CATEGORY): void + public function addCronJob(Command $command, string $schedule = null, string $category = self::DEFAULT_CATEGORY, string $options = ''): void { - $command = sprintf('%s %s %s --siteaccess=%s --env=%s', + $command = sprintf('%s %s %s %s --siteaccess=%s --env=%s', $this->executable, $_SERVER['SCRIPT_NAME'], $command->getName(), + $options, $this->siteaccess->name, $this->environment );