fix: safety checklist — verify pending+unchecked before marking, auto-complete status
Universal: Auto Version Bump / Version Bump (push) Successful in 14s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 13s
Universal: Build & Release / Promote to RC (pull_request) Has been skipped
Universal: Build & Release / Build & Release Pipeline (pull_request) Successful in 18s
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
Universal: PR Check / Secret Scan (pull_request) Successful in 6s
Universal: PR Check / Validate PR (pull_request) Failing after 5s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Generic: Repo Health / Access control (pull_request) Successful in 1s
Branch Cleanup / Delete merged branch (pull_request) Has been skipped
RC Revert / Rename rc/ back to dev/ (pull_request) Has been skipped
Universal: Workflow Sync Trigger / Sync workflows to live repos (pull_request) Failing after 3s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled

This commit is contained in:
Jonathan Miller
2026-06-21 00:24:43 -05:00
parent 4ce4814e50
commit eeaef928b5
@@ -50,6 +50,18 @@ class SafetyChecklistHelper
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
// Verify item belongs to a pending checklist and is not already checked
$db->setQuery($db->getQuery(true)
->select('sci.id, sci.checked, sc.status AS checklist_status')
->from($db->quoteName('#__mokosuitefield_safety_checklist_items', 'sci'))
->join('INNER', $db->quoteName('#__mokosuitefield_safety_checklists', 'sc') . ' ON sc.id = sci.checklist_id')
->where('sci.id = ' . (int) $itemId));
$existing = $db->loadObject();
if (!$existing || $existing->checklist_status !== 'pending' || (int) $existing->checked === 1) {
return false;
}
$update = (object) [
'id' => $itemId,
'checked' => 1,
@@ -59,7 +71,26 @@ class SafetyChecklistHelper
'checked_by' => Factory::getApplication()->getIdentity()->id,
];
return $db->updateObject('#__mokosuitefield_safety_checklist_items', $update, 'id');
$db->updateObject('#__mokosuitefield_safety_checklist_items', $update, 'id');
// Auto-complete checklist if all items are checked
$db->setQuery($db->getQuery(true)
->select('sc.id, COUNT(sci2.id) AS total, SUM(CASE WHEN sci2.checked = 1 THEN 1 ELSE 0 END) AS done')
->from($db->quoteName('#__mokosuitefield_safety_checklist_items', 'sci2'))
->join('INNER', $db->quoteName('#__mokosuitefield_safety_checklists', 'sc') . ' ON sc.id = sci2.checklist_id')
->where('sci2.id = ' . (int) $itemId)
->group('sc.id'));
$progress = $db->loadObject();
if ($progress && (int) $progress->done === (int) $progress->total) {
$db->setQuery($db->getQuery(true)
->update('#__mokosuitefield_safety_checklists')
->set($db->quoteName('status') . ' = ' . $db->quote('completed'))
->where('id = ' . (int) $progress->id));
$db->execute();
}
return true;
}
/**