mirror of
https://github.com/itflow-org/itflow
synced 2026-11-11 15:07:24 +00:00
55 lines
3.6 KiB
PHP
55 lines
3.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Get started - Cron: the crontab line, and whether cron has been heard from
|
|
* (checked again every 10 seconds while it hasn't - js/getting_started.js).
|
|
* Cron is on in a new install, so the switch only shows when someone has
|
|
* turned it off (getting_started_cron_on).
|
|
*/
|
|
|
|
defined('FROM_GETTING_STARTED') || die("Direct file access is not allowed");
|
|
|
|
$gs_cron = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT config_enable_cron, config_cron_last_dispatch_at FROM settings WHERE company_id = 1")) ?: [];
|
|
$gs_cron_heard = $gs_cron['config_cron_last_dispatch_at'] ?? null;
|
|
$gs_cron_running = $gs_cron_heard && time() - strtotime($gs_cron_heard) < 300;
|
|
$gs_cron_on = intval($gs_cron['config_enable_cron'] ?? 0) === 1;
|
|
$gs_cron_command = gettingStartedCronCommand();
|
|
|
|
?>
|
|
<ol class="itflow-gs-tasks list-unstyled mb-0">
|
|
<li class="<?= $gs_cron_running ? 'is-done' : '' ?>" data-gs-cron-heard="<?= $gs_cron_running ? 'yes' : 'no' ?>">
|
|
<span class="itflow-gs-task-mark"><i class="fas <?= $gs_cron_running ? 'fa-check' : 'fa-terminal' ?>"></i></span>
|
|
<div class="min-w-0 flex-grow-1">
|
|
<div class="fw-semibold">Add the cron job</div>
|
|
<div class="small text-body-secondary mb-2">One line, for the user that owns the ITFlow files - <code>crontab -e</code> as them. On a hosting control panel such as Jabali, HestiaCP or cPanel, add it as a cron job that runs every minute. The install script adds it for you.</div>
|
|
<div class="input-group input-group-sm">
|
|
<input type="text" class="form-control font-monospace" value="<?= escapeHtml($gs_cron_command) ?>" aria-label="Crontab line" readonly>
|
|
<button type="button" class="btn btn-outline-secondary clipboardjs" data-clipboard-text="<?= escapeHtml($gs_cron_command) ?>" title="Copy"><i class="far fa-copy"></i></button>
|
|
</div>
|
|
<div class="small mt-2" data-gs-cron-status>
|
|
<?php if ($gs_cron_running) { ?>
|
|
<span class="text-success"><i class="fas fa-check-circle me-1"></i>Cron ran <?= escapeHtml(timeAgo($gs_cron_heard)) ?>.</span>
|
|
<?php } else { ?>
|
|
<span class="text-body-secondary"><span class="spinner-border spinner-border-sm me-2" aria-hidden="true"></span><?= $gs_cron_heard ? 'Cron last ran ' . escapeHtml(timeAgo($gs_cron_heard)) . ' - waiting to hear from it again' : 'Waiting to hear from it - this page checks every few seconds' ?></span>
|
|
<?php } ?>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
<?php if (!$gs_cron_on) { ?>
|
|
<li data-gs-cron-switch="off">
|
|
<span class="itflow-gs-task-mark"><i class="fas fa-toggle-off"></i></span>
|
|
<div class="min-w-0 flex-grow-1">
|
|
<div class="fw-semibold">Turn cron back on</div>
|
|
<div class="small text-body-secondary mb-2">Someone switched it off in Maintenance > Cron, and every job stops itself while it is off.</div>
|
|
<form action="post.php" method="post" class="m-0">
|
|
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
|
<button type="submit" name="getting_started_cron_on" value="1" class="btn btn-primary"><i class="fas fa-toggle-on me-2"></i>Turn cron on</button>
|
|
</form>
|
|
</div>
|
|
</li>
|
|
<?php } ?>
|
|
</ol>
|
|
<?php if (!$gs_cron_running) { ?>
|
|
<div class="small text-body-secondary mt-3" data-gs-cron-poll="<?= gettingStartedUrl() ?>?cron_status=1">Nothing is emailed or backed up until cron runs - the other steps can be done meanwhile.</div>
|
|
<?php } ?>
|