Files
orderPRO/resources/views/settings/cron.php

155 lines
6.7 KiB
PHP

<?php
$schedulesList = is_array($schedules ?? null) ? $schedules : [];
$futureList = is_array($futureJobs ?? null) ? $futureJobs : [];
$pastList = is_array($pastJobs ?? null) ? $pastJobs : [];
$runOnWeb = ($runOnWebEnabled ?? false) === true;
$webLimit = max(1, (int) ($webCronLimit ?? 5));
?>
<section class="card">
<h1><?= $e($t('settings.title')) ?></h1>
<p class="muted"><?= $e($t('settings.description')) ?></p>
<nav class="settings-nav mt-16" aria-label="<?= $e($t('settings.submenu_label')) ?>">
<a class="settings-nav__link<?= ($activeSettings ?? '') === 'database' ? ' is-active' : '' ?>" href="/settings/database"><?= $e($t('settings.database.title')) ?></a>
<a class="settings-nav__link<?= ($activeSettings ?? '') === 'integrations' ? ' is-active' : '' ?>" href="/settings/integrations/shoppro"><?= $e($t('settings.integrations.title')) ?></a>
<a class="settings-nav__link<?= ($activeSettings ?? '') === 'cron' ? ' is-active' : '' ?>" href="/settings/cron"><?= $e($t('settings.cron.title')) ?></a>
<a class="settings-nav__link<?= ($activeSettings ?? '') === 'gs1' ? ' is-active' : '' ?>" href="/settings/gs1"><?= $e($t('settings.gs1.title')) ?></a>
</nav>
</section>
<section class="card mt-16">
<h2 class="section-title"><?= $e($t('settings.cron.run_on_web_title')) ?></h2>
<p class="muted mt-12"><?= $e($t('settings.cron.run_on_web_description')) ?></p>
<?php if (!empty($errorMessage)): ?>
<div class="alert alert--danger mt-12" role="alert"><?= $e((string) $errorMessage) ?></div>
<?php endif; ?>
<?php if (!empty($successMessage)): ?>
<div class="alert alert--success mt-12" role="status"><?= $e((string) $successMessage) ?></div>
<?php endif; ?>
<form action="/settings/cron/save" method="post" class="mt-16">
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
<label class="form-field">
<span class="field-label">
<input type="checkbox" name="cron_run_on_web" value="1"<?= $runOnWeb ? ' checked' : '' ?>>
<?= $e($t('settings.cron.run_on_web_label')) ?>
</span>
</label>
<label class="form-field mt-12">
<span class="field-label"><?= $e($t('settings.cron.web_limit')) ?></span>
<input class="form-control" type="number" min="1" max="100" name="cron_web_limit" value="<?= $e((string) $webLimit) ?>">
</label>
<div class="form-actions mt-16">
<button type="submit" class="btn btn--primary"><?= $e($t('settings.cron.actions.save')) ?></button>
</div>
</form>
</section>
<section class="card mt-16">
<h2 class="section-title"><?= $e($t('settings.cron.schedules_title')) ?></h2>
<div class="table-wrap mt-12">
<table class="table">
<thead>
<tr>
<th><?= $e($t('settings.cron.fields.job_type')) ?></th>
<th><?= $e($t('settings.cron.fields.enabled')) ?></th>
<th><?= $e($t('settings.cron.fields.interval')) ?></th>
<th><?= $e($t('settings.cron.fields.priority')) ?></th>
<th><?= $e($t('settings.cron.fields.next_run_at')) ?></th>
<th><?= $e($t('settings.cron.fields.last_run_at')) ?></th>
</tr>
</thead>
<tbody>
<?php if ($schedulesList === []): ?>
<tr><td colspan="6" class="muted"><?= $e($t('settings.cron.empty_schedules')) ?></td></tr>
<?php else: ?>
<?php foreach ($schedulesList as $row): ?>
<tr>
<td><?= $e((string) ($row['job_type'] ?? '')) ?></td>
<td><?= $e(((bool) ($row['enabled'] ?? false)) ? $t('settings.cron.enabled.yes') : $t('settings.cron.enabled.no')) ?></td>
<td><?= $e((string) ((int) ($row['interval_seconds'] ?? 0))) ?></td>
<td><?= $e((string) ((int) ($row['priority'] ?? 0))) ?></td>
<td><?= $e((string) (($row['next_run_at'] ?? null) ?? '-')) ?></td>
<td><?= $e((string) (($row['last_run_at'] ?? null) ?? '-')) ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</section>
<section class="card mt-16">
<h2 class="section-title"><?= $e($t('settings.cron.future_jobs_title')) ?></h2>
<div class="table-wrap mt-12">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th><?= $e($t('settings.cron.fields.job_type')) ?></th>
<th><?= $e($t('settings.cron.fields.status')) ?></th>
<th><?= $e($t('settings.cron.fields.priority')) ?></th>
<th><?= $e($t('settings.cron.fields.scheduled_at')) ?></th>
<th><?= $e($t('settings.cron.fields.attempts')) ?></th>
</tr>
</thead>
<tbody>
<?php if ($futureList === []): ?>
<tr><td colspan="6" class="muted"><?= $e($t('settings.cron.empty_future_jobs')) ?></td></tr>
<?php else: ?>
<?php foreach ($futureList as $row): ?>
<tr>
<td><?= $e((string) ((int) ($row['id'] ?? 0))) ?></td>
<td><?= $e((string) ($row['job_type'] ?? '')) ?></td>
<td><?= $e((string) ($row['status'] ?? '')) ?></td>
<td><?= $e((string) ((int) ($row['priority'] ?? 0))) ?></td>
<td><?= $e((string) (($row['scheduled_at'] ?? null) ?? '-')) ?></td>
<td><?= $e((string) ((int) ($row['attempts'] ?? 0)) . '/' . (string) ((int) ($row['max_attempts'] ?? 0))) ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</section>
<section class="card mt-16">
<h2 class="section-title"><?= $e($t('settings.cron.past_jobs_title')) ?></h2>
<div class="table-wrap mt-12">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th><?= $e($t('settings.cron.fields.job_type')) ?></th>
<th><?= $e($t('settings.cron.fields.status')) ?></th>
<th><?= $e($t('settings.cron.fields.scheduled_at')) ?></th>
<th><?= $e($t('settings.cron.fields.completed_at')) ?></th>
<th><?= $e($t('settings.cron.fields.last_error')) ?></th>
</tr>
</thead>
<tbody>
<?php if ($pastList === []): ?>
<tr><td colspan="6" class="muted"><?= $e($t('settings.cron.empty_past_jobs')) ?></td></tr>
<?php else: ?>
<?php foreach ($pastList as $row): ?>
<?php $error = trim((string) ($row['last_error'] ?? '')); ?>
<tr>
<td><?= $e((string) ((int) ($row['id'] ?? 0))) ?></td>
<td><?= $e((string) ($row['job_type'] ?? '')) ?></td>
<td><?= $e((string) ($row['status'] ?? '')) ?></td>
<td><?= $e((string) (($row['scheduled_at'] ?? null) ?? '-')) ?></td>
<td><?= $e((string) (($row['completed_at'] ?? null) ?? '-')) ?></td>
<td><?= $e($error === '' ? '-' : $error) ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</section>