mirror of
https://github.com/getgrav/grav.git
synced 2026-02-20 05:27:50 +01:00
Cron improvements
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
* Added `array_diff()` twig function
|
||||
* Added `template_from_string()` twig function
|
||||
1. [](#improved)
|
||||
* Improved `Scheduler` cron command check and more useful CLI information
|
||||
* Improved `Flex Users`: obey blueprints and allow Flex to be used in admin only
|
||||
* Improved `Flex` to support custom site template paths
|
||||
* Changed Twig `{% cache %}` tag to not need unique key, and `lifetime` is now optional
|
||||
|
||||
@@ -244,13 +244,20 @@ class Scheduler
|
||||
*/
|
||||
public function getCronCommand()
|
||||
{
|
||||
$phpBinaryFinder = new PhpExecutableFinder();
|
||||
$php = $phpBinaryFinder->find();
|
||||
$command = 'cd ' . str_replace(' ', '\ ', GRAV_ROOT) . ';' . $php . ' bin/grav scheduler';
|
||||
$command = $this->getSchedulerCommand();
|
||||
|
||||
return "(crontab -l; echo \"* * * * * {$command} 1>> /dev/null 2>&1\") | crontab -";
|
||||
}
|
||||
|
||||
public function getSchedulerCommand($php = null)
|
||||
{
|
||||
$phpBinaryFinder = new PhpExecutableFinder();
|
||||
$php = $php ?? $phpBinaryFinder->find();
|
||||
$command = 'cd ' . str_replace(' ', '\ ', GRAV_ROOT) . ';' . $php . ' bin/grav scheduler';
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to determine if cron job is setup
|
||||
*
|
||||
@@ -263,8 +270,10 @@ class Scheduler
|
||||
|
||||
if ($process->isSuccessful()) {
|
||||
$output = $process->getOutput();
|
||||
$command = str_replace('/', '\/', $this->getSchedulerCommand('.*'));
|
||||
$full_command = '/^(?!#).* .* .* .* .* ' . $command . '/m';
|
||||
|
||||
return preg_match('$bin\/grav schedule$', $output) ? 1 : 0;
|
||||
return preg_match($full_command, $output) ? 1 : 0;
|
||||
}
|
||||
|
||||
$error = $process->getErrorOutput();
|
||||
|
||||
@@ -152,17 +152,20 @@ class SchedulerCommand extends ConsoleCommand
|
||||
} elseif ($this->input->getOption('install')) {
|
||||
$io->title('Install Scheduler');
|
||||
|
||||
$verb = 'install';
|
||||
|
||||
if ($scheduler->isCrontabSetup()) {
|
||||
$io->success('All Ready! You have already set up Grav\'s Scheduler in your crontab');
|
||||
$io->success('All Ready! You have already set up Grav\'s Scheduler in your crontab. You can validate this by running "crontab -l" to list your current crontab entries.');
|
||||
$verb = 'reinstall';
|
||||
} else {
|
||||
$io->error('You still need to set up Grav\'s Scheduler in your crontab');
|
||||
}
|
||||
if (!Utils::isWindows()) {
|
||||
$io->note('To install, run the following command from your terminal:');
|
||||
$io->note("To $verb, run the following command from your terminal:");
|
||||
$io->newLine();
|
||||
$io->text(trim($scheduler->getCronCommand()));
|
||||
} else {
|
||||
$io->note('To install, create a scheduled task in Windows.');
|
||||
$io->note("To $verb, create a scheduled task in Windows.");
|
||||
$io->text('Learn more at https://learn.getgrav.org/advanced/scheduler');
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user