Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Improve cron validation function, cron helpers and cron input errors #3120

Draft
wants to merge 13 commits into
base: next
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bootstrap/helpers/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
use Lcobucci\JWT\Token\Builder;
use phpseclib3\Crypt\EC;
use phpseclib3\Crypt\RSA;
use Poliander\Cron\CronExpression;
use PurplePixie\PhpDns\DNSQuery;
use Spatie\Url\Url;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -341,22 +340,23 @@ function isCloud(): bool
return ! config('constants.coolify.self_hosted');
}

function translate_cron_expression($expression_to_validate): string
{
if (isset(VALID_CRON_STRINGS[$expression_to_validate])) {
return VALID_CRON_STRINGS[$expression_to_validate];
}

return $expression_to_validate;
}

function validate_cron_expression($expression_to_validate): bool
{
if (empty($expression_to_validate)) {
return false;
}

$isValid = false;
$expression = new CronExpression($expression_to_validate);
$isValid = $expression->isValid();
try {
$expression = new CronExpression($expression_to_validate);
$isValid = $expression->isValid();
} catch (\Exception $e) {
return false;
}

if (isset(VALID_CRON_STRINGS[$expression_to_validate])) {
$isValid = true;
Expand Down