Files
itflow/admin/modals/cron/cron_edit.php
johnnyq dfb0298245 Rebuild Maintenance > Cron on the Update and Backup pages' pattern: a status card at the top says cron is running, when it last ran, how many jobs are on and which runs next, or instead that cron has never run or has stopped, with the crontab line and a copy button, that it is switched off, with Turn cron on, that a managed instance's jobs are paused by its manager, or that a job failed, by name; the jobs are listed with an icon, what each does, its schedule and next run, its last run and how long it took, and a status of Queued, Running, Completed, Failed, Skipped, Paused, Not run yet or Didn't finish for one still running six hours on, with the reason a run was skipped under the job and a kept error shown until dismissed, marked as having run since once it has; the list sorts in PHP on the standard sort and order by job, schedule, last run or status, starting by schedule, with no pager or search as it is a fixed list of at most fifteen; a job's menu has Run now, Change the schedule, Copy the command to run it and Turn off, which asks first; the page reloads itself every 10 seconds while a job is queued or running and every 15 while cron has not been heard from; the side column has At a glance, the cron line with a copy button and Turn cron off, which asks first; includes/cron_jobs.php gives each job an icon and drops cronJobTimeAgo, which nothing uses now; the schedule window opens with what the job does, uses the select picker and names the time zone; admin/post/cron.php words its messages as the buttons are worded, with the audit log unchanged; js/auto_reload.js holds a reload while a window, menu or confirmation is open, a field has focus or text is selected, which also stops the Backup page reloading away its Change the time window or what is typed into its retention boxes; CONTRIBUTING says to give a new job its icon; no database change and no new CSS; changelog entries added to 26.11.8
2026-11-13 01:51:34 -05:00

105 lines
5.0 KiB
PHP

<?php
require_once '../../includes/modal_header.php'; // admin/includes - admins only
require_once '../../../includes/cron_jobs.php';
$cron_job_id = intval($_GET['id']);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT cron_job_daily_at, cron_job_enabled, cron_job_interval_minutes, cron_job_name,
cron_job_schedule FROM cron_jobs WHERE cron_job_id = $cron_job_id LIMIT 1"));
$registry = cronJobRegistryByName();
$job = $registry[$row['cron_job_name']] ?? null;
$cron_job_interval_safe = ($job['interval_safe'] ?? true);
$cron_job_name = escapeHtml($row['cron_job_name']);
$cron_job_label = escapeHtml($job['label'] ?? $row['cron_job_name']);
$cron_job_enabled = intval($row['cron_job_enabled']);
$cron_job_schedule = escapeHtml($row['cron_job_schedule']);
$cron_job_interval_minutes = intval($row['cron_job_interval_minutes']);
$cron_job_daily_at = escapeHtml(substr((string)$row['cron_job_daily_at'], 0, 5));
if (empty($cron_job_daily_at)) {
$cron_job_daily_at = '03:00';
}
// Generate the HTML form content using output buffering.
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-clock me-2"></i>Editing: <strong><?= $cron_job_label ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="cron_job_id" value="<?= $cron_job_id ?>">
<div class="modal-body">
<?php if (!empty($job['description'])) { ?>
<p class="small text-body-secondary"><?= escapeHtml($job['description']) ?></p>
<?php } ?>
<div class="mb-3">
<div class="form-check form-switch">
<input type="checkbox" class="form-check-input" name="enabled" value="1" id="cronJobEnabledSwitch" <?= $cron_job_enabled == 1 ? 'checked' : '' ?>>
<label class="form-check-label" for="cronJobEnabledSwitch">Runs on its schedule</label>
</div>
<small class="text-muted">Switched off, it only runs when someone asks it to with Run now.</small>
</div>
<div class="mb-3">
<label>Schedule</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
<select class="form-select select2" name="schedule" id="cronJobSchedule">
<?php if ($cron_job_interval_safe) { ?>
<option value="Interval" <?= $cron_job_schedule === 'Interval' ? 'selected' : '' ?>>Every so many minutes</option>
<?php } ?>
<option value="Daily" <?= ($cron_job_schedule === 'Daily' || !$cron_job_interval_safe) ? 'selected' : '' ?>>Once a day</option>
</select>
</div>
<?php if (!$cron_job_interval_safe) { ?>
<small class="text-muted">It only runs once a day - run more often, its work would be done twice.</small>
<?php } ?>
</div>
<div class="mb-3" id="cronJobIntervalGroup">
<label>Run every</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-redo"></i></span>
<input type="number" class="form-control" name="interval_minutes" value="<?= $cron_job_interval_minutes ?>" min="1" max="1440">
<span class="input-group-text">minutes</span>
</div>
<small class="text-muted">Cron wakes once a minute, so 1 is as often as anything can run.</small>
</div>
<div class="mb-3" id="cronJobDailyGroup">
<label>Run at</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
<input type="time" class="form-control" name="daily_at" value="<?= $cron_job_daily_at ?>">
</div>
<small class="text-muted">In ITFlow's time zone<?= !empty($session_timezone) ? ', ' . escapeHtml($session_timezone) : '' ?>. A run missed because the server was off happens when it's back, not a day later.</small>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="edit_cron_job" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<script>
function cronJobToggleScheduleFields() {
var daily = document.getElementById('cronJobSchedule').value === 'Daily';
document.getElementById('cronJobIntervalGroup').hidden = daily;
document.getElementById('cronJobDailyGroup').hidden = !daily;
}
document.getElementById('cronJobSchedule').addEventListener('change', cronJobToggleScheduleFields);
cronJobToggleScheduleFields();
</script>
<?php
require_once '../../../includes/modal_footer.php';