Skip to content

Complete History Developer Guide

Ed Mozley edited this page Nov 29, 2026 · 1 revision

🕘 Complete history for tasks and tickets - Developer Guide

GitHub #430, raised by @Dr4inder · Tasks, Tickets · built after 5.12.1 (#3247-#3250)

How a task's History and a ticket's Audit became one timeline, and how everything in it is recorded in the same save as the change. The design, with the decisions and @Dr4inder's review, is Complete history - design.

The timeline

assets/js/history-timeline.js is used by both pages. Each page turns its entries into words and hands them over, so the component only lays them out, filters them and escapes them:

HistoryTimeline.open({ title: 'History - TASK-12', entries });   // the dialog
HistoryTimeline.render(host, { entries });                       // inline (the ticket workspace's History tab)
HistoryTimeline.compare(title, beforeHtml, afterHtml);           // a description revision, cleaned by safeHtmlFragment()

// entry: { at, who, text, category, categoryLabel, note, action: { label, run } | null }

The filter chips are built from the categories the record actually has, so there's never an empty choice. With only one kind of change, no filter is shown. The styles are in assets/css/inbox.css, which both pages load.

  • Tasks: loadTaskHistory() in assets/js/tasks.js builds the entries with the existing line() renderer and taskHistCategory(). The section in the task window shows the latest five, and History (N) opens the rest. It's part of the task window, so it's there in every layout: panel, large window and embedded.
  • Tickets: showAuditHistory() in assets/js/inbox.js builds them with ticketAuditText() and the server's category.

Tasks: recorded in the save

TasksService::updateTask() works out what really changed (fieldHistory()), compared with the task as it was. It writes those lines with TaskHistory::recordStrict(), inside the same transaction as the update:

Event from / to detail
title_changed, priority_changed, estimate_changed, tags_changed, work_scheduled before / after, in words -
linked / unlinked what it points at - a ticket number, change title, contract or parent task field, id
description_changed - revision → task_description_revisions (both versions, whole)
time_logged / time_removed minutes entry_id, minutes, work_date
  • An unchanged save writes nothing. The same title, tags or link sent again is not a change.
  • A failed save writes nothing. It's one transaction, and recording is strict.
  • The description is kept whole in each version, never squeezed into a short column. api/tasks/history.php?task_id=N&revision=M serves a revision only when it belongs to task N, after the same company check as the history itself.

Read in, not copied

TaskHistory::forTask() and api/tickets/get_ticket_audit.php merge in records that already have a time and an author:

Source Line Never shows
task_comments Added a comment the comment's text
ticket_notes Added an internal note / a note shared with the requester the note's text
task_time_entries / ticket_time_entries with no stored "logged" line Logged 1 h 30 m for 23 Nov - marked as it is now -

TRAP: a time entry's history is never rewritten (@Dr4inder's first clarification). New entries get a stored logged line when they're logged. An edit (tickets) or a removal is a line of its own. So logged 60 → changed to 90 → removed stays three true lines. Reading a time entry in only happens for one logged before this existed, and that line says so: nothing older was kept, and none is invented.

Visibility is checked on the response itself (his second clarification). Both readers answer only after the record's own company check (analystCanAccessTask / analystCanAccessTicket). A line names a comment or note but never carries its text, so nothing in the timeline is more visible than the record.

Tickets: auditing moved to the server

Before Now
The inbox saved, then sent each changed field to log_ticket_audit.php as a second request assign_ticket.php and update_ticket_owner.php pass writeAudit = true, so TicketsService::updateTicket() writes every line
The change and its line could come apart (a closed tab, a lost connection) updateTicket() always wraps the change and its audit in one transaction. Notifications and workflows still follow the commit
The API and the inbox recorded the same change differently One path, one wording
  • TRAP: logAudit() in inbox.js is a no-op, kept so its callers need no change. Bringing the request back would write every line twice.
  • log_ticket_audit.php is retired. It answers success and writes nothing, so a browser still running the old script after an upgrade can't add second copies.

Every line says who did it: TicketsService::auditWriteBy() stores actor_kind and actor_name from TaskHistory::actor(). So an API key or a workflow is named rather than reading as a person or "System". Time entries carry their facts in ticket_audit.detail_json:

self::auditWriteBy($conn, $ticketId, $ctx, 'Time changed', '60 min, 2026-11-21', '90 min, 2026-11-21',
    ['entry_id' => 7, 'from_minutes' => 60, 'minutes' => 90, 'from_work_date' => '2026-11-21', 'work_date' => '2026-11-21',
     'note_changed' => false, 'only_note' => false]);

A note-only edit is Changed the note of the time logged for 23 Nov, without the note's text. Ticket views stay in the Audit exactly as before.

Schema

ALTER TABLE ticket_audit ADD actor_kind VARCHAR(20) NULL, ADD actor_name VARCHAR(255) NULL, ADD detail_json TEXT NULL;
CREATE TABLE task_description_revisions (id, task_id, before_text LONGTEXT, after_text LONGTEXT, analyst_id, created_datetime);
-- fk_task_desc_rev_task ON DELETE CASCADE; analyst_id is in the analyst lifecycle registry as history

📁 Files

File Change
🟢 assets/js/history-timeline.js The timeline
🟡 includes/services/tasks.php fieldHistory(), revisions, time-entry lines
🟡 includes/services/task_history.php Comments and time entries read in; revision()
🟡 includes/services/tickets.php auditWriteBy(), one transaction, time-entry lines
🟡 api/tickets/get_ticket_audit.php Notes and time read in; categories
🟡 api/tickets/assign_ticket.php, update_ticket_owner.php writeAudit = true
🔴 api/tickets/log_ticket_audit.php Retired
🟡 api/tasks/history.php ?revision=
🟡 assets/js/tasks.js, assets/js/inbox.js, assets/css/inbox.css History button, Audit as the timeline
🟣 database/freeitsm.sql, includes/db_verify_schema.php, api/system/db_verify.php The schema
🟢 tests/complete-history.php 28 checks

How it was proved

tests/complete-history.php runs through the real endpoints on a test install and checks:

  • Task fields: each one makes its line, with an unchanged save as the control, and a failed save records nothing.
  • Revisions: they keep both versions, and another task's revision is refused.
  • Comments and notes are read in without their text.
  • Time-entry lines are never rewritten by an edit or a removal, and older entries are marked as it is now.
  • Inbox changes get one server audit line each.
  • The retired endpoint writes nothing.

The task History dialog and the ticket Audit were also checked in a browser.

Related

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally