Ticket SLA: Fix on hold to pause only after first reply, show resolved closed and onhold as fixed on paused sla in the list

This commit is contained in:
johnnyq
2026-08-15 19:55:40 -04:00
parent bcc73737e4
commit 6af0634f47
11 changed files with 142 additions and 15 deletions

View File

@@ -0,0 +1,39 @@
<?php
/*
* ITFlow - Database update to version 2.7.0 (from 2.6.9)
* Included by admin/database_updates.php - do not access directly
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// The five built-in ticket statuses now have fixed SLA clock behaviour, matching
// getTicketStatusSlaLock() in functions/app.php: On Hold, Resolved and Closed
// pause the resolution clock, New and Open run it. Admin > Ticket Statuses no
// longer offers the choice on these five - only on custom statuses.
//
// On Hold shipped with the column defaulting to 0, so a stock install breached
// the resolution SLA on tickets parked waiting for a client or a vendor. Every
// install had to find the toggle themselves; this sets it for them.
//
// Resolved and Closed are set for consistency across the SLA surfaces, not to
// change behaviour - both already stopped the clocks via ticket_resolved_at and
// ticket_closed_at, which is what the cron and syncTicketSlaClock() actually read.
mysqli_query($mysqli, "UPDATE ticket_statuses SET ticket_status_pauses_sla = 1 WHERE ticket_status_id IN (3, 4, 5)");
mysqli_query($mysqli, "UPDATE ticket_statuses SET ticket_status_pauses_sla = 0 WHERE ticket_status_id IN (1, 2)");
/*
* Tickets already parked in On Hold are still holding an open sla_history
* interval, so their paused time would keep counting as consumed. Closing those
* intervals needs business-hours maths in the app timezone, and this file also
* runs from scripts/update_cli.php, which sets neither - so the first
* cron/ticket_sla.php run after the upgrade reconciles them instead, where the
* timezone is set. Nothing is lost by waiting a minute: the same cron no longer
* warns or breaches a paused ticket the moment the flag above lands.
*
* Breach verdicts already recorded against on-hold tickets are deliberately left
* alone. They were recorded by a clock that really was running under the old
* rules, and rewriting a stored miss is exactly what the reopen-integrity rules
* in functions/sla.php exist to prevent. Re-stamp an individual ticket (change
* its priority or its SLA) if you want it re-judged.
*/

View File

@@ -12,6 +12,8 @@ $ticket_status_color = escapeHtml($row['ticket_status_color']);
$ticket_status_order = intval($row['ticket_status_order']);
$ticket_status_active = intval($row['ticket_status_active']);
$ticket_status_pauses_sla = intval($row['ticket_status_pauses_sla']);
// Null for a custom status (the admin picks), 1 or 0 for the five built-in ones
$ticket_status_sla_lock = getTicketStatusSlaLock($ticket_status_id);
// Generate the HTML form content using output buffering.
ob_start();
@@ -66,12 +68,22 @@ ob_start();
<label>SLA</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-stopwatch"></i></span>
<select class="form-select select2" name="pauses_sla">
<option <?php if ($ticket_status_pauses_sla == 0) { echo "selected "; } ?>value="0">Resolution clock keeps running</option>
<option <?php if ($ticket_status_pauses_sla == 1) { echo "selected "; } ?>value="1">Pause the resolution clock</option>
</select>
<?php if (is_null($ticket_status_sla_lock)) { ?>
<select class="form-select select2" name="pauses_sla">
<option <?php if ($ticket_status_pauses_sla == 0) { echo "selected "; } ?>value="0">Resolution clock keeps running</option>
<option <?php if ($ticket_status_pauses_sla == 1) { echo "selected "; } ?>value="1">Pause the resolution clock</option>
</select>
<?php } else { ?>
<input type="text" class="form-control" value="<?= $ticket_status_sla_lock ? 'Pause the resolution clock' : 'Resolution clock keeps running' ?>" readonly>
<?php } ?>
</div>
<small class="text-muted">Tickets sitting in a paused status never warn or breach on resolution. Time already spent is kept and the deadline moves out when the ticket comes back.</small>
<?php if (is_null($ticket_status_sla_lock)) { ?>
<small class="text-muted">Tickets sitting in a paused status never warn or breach on resolution. Time already spent is kept and the deadline moves out when the ticket comes back.</small>
<?php } elseif ($ticket_status_sla_lock) { ?>
<small class="text-muted">Fixed for built-in statuses. Tickets here never warn or breach on resolution - time already spent is kept and the deadline moves out when the ticket comes back.</small>
<?php } else { ?>
<small class="text-muted">Fixed for built-in statuses. Tickets here are being worked, so their resolution clock runs.</small>
<?php } ?>
</div>
</div>

View File

@@ -33,7 +33,13 @@ if (isset($_POST['edit_ticket_status'])) {
$order = intval($_POST['order']);
$status = intval($_POST['status']);
$pauses_sla = intval($_POST['pauses_sla'] ?? 0);
// Built-in statuses have fixed SLA behaviour. The modal renders it read-only, and a
// read-only field submits nothing - so the value is decided here rather than taken
// from the POST, which also means a hand-made request cannot change it.
$pauses_sla = getTicketStatusSlaLock($ticket_status_id);
if (is_null($pauses_sla)) {
$pauses_sla = intval($_POST['pauses_sla'] ?? 0);
}
mysqli_query($mysqli, "UPDATE ticket_statuses SET ticket_status_name = '$name', ticket_status_color = '$color', ticket_status_order = $order, ticket_status_active = $status, ticket_status_pauses_sla = $pauses_sla WHERE ticket_status_id = $ticket_status_id");

View File

@@ -99,6 +99,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<?php } else { ?>
<span class="text-secondary">Running</span>
<?php } ?>
<?php if (!is_null(getTicketStatusSlaLock($ticket_status_id))) { ?>
<small class="text-muted ms-1" title="Built-in statuses have fixed SLA behaviour">(fixed)</small>
<?php } ?>
</td>
<td>
<div class="dropdown dropstart text-center">