Plugin: handover step + auto-seed prior notes into next session (hc-dy9)

Add a final "Notes for next time" step so the tech finishing today can flag
pending issues, watch-fors, and outstanding client decisions for whoever
picks up the next healthcheck on the same site.

On ATT_HC_Session::start() for a given site_key, the server's step history
for the handover step is queried (limit 1, excluding the just-created
session). If a prior session left handover notes, they're written into
the new session's "Before You Start" notes prefixed with the prior
session's date ("From previous session (YYYY-MM-DD):") so the carry-over
is obvious. The tech can edit/clear them as normal step notes from there.

- includes/steps/125-handover.php — new step (id=handover) using the
  standard notes field. No server schema or API change; it's just another
  step row in step_updates, surfaced like any other.
- ATT_HC_Session::seed_before_notes_from_prior_handover() — best-effort,
  silent degrade on API failure. The session is already registered on
  the server before this runs, so a failed seed never blocks start.
- No seed on resume() — resuming an existing session would clobber
  whatever the tech had already typed.

Verified end-to-end against the live MySQL server: handover-test-XXXX
flow shows carry-over with date prefix; no-handover-XXXX flow confirms
no false-positive seed for a fresh site_key. Test rows purged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-30 10:17:44 +01:00
parent 3c64dd8125
commit 1a9e5ac0fd
3 changed files with 59 additions and 1 deletions

View File

@@ -84,7 +84,39 @@ final class ATT_HC_Session {
]);
update_option(ATT_HC_OPT_SESSION, $data, false);
return new self($data);
$session = new self($data);
// Carry handover notes from the prior session into the new "before"
// notes. Best-effort: a failure here must not block session creation,
// since the session is already registered on the server above.
self::seed_before_notes_from_prior_handover($session);
return $session;
}
/**
* If the prior session for this site left "Notes for next time" (id=handover),
* pre-fill the new session's "Before You Start" (id=before) notes with them,
* prefixed with the prior session's date so it's clear they're carried over.
*/
private static function seed_before_notes_from_prior_handover(self $session): void {
try {
$resp = ATT_HC_Api::step_history('handover', $session->site_key(), 1, $session->id());
} catch (ATT_HC_Api_Exception $e) {
return;
}
$rows = $resp['history'] ?? [];
if (!$rows) return;
$notes = trim((string) ($rows[0]['notes'] ?? ''));
if ($notes === '') return;
$prefix = 'From previous session (' . date('Y-m-d', (int) $rows[0]['started_at']) . "):\n";
try {
$session->update_step('before', self::STATUS_NOT_STARTED, $prefix . $notes);
} catch (ATT_HC_Api_Exception $e) {
// Already-rare degrade path — the session is alive, just no auto-seed.
}
}
/**