Tasks Archive Developer Guide - edmozley/freeitsm GitHub Wiki
๐๏ธ Archiving done tasks - Developer Guide
GitHub #442, raised by @pappas81 ยท Tasks ยท built after 5.12.1 (#3232-#3236)
How done tasks leave the board without being deleted, and how they come back. For what an analyst sees, start at Tasks โ Archiving done tasks.
Decided
| When | Question | Decision |
|---|---|---|
| 29 Nov 2026 | Archive automatically after N days, by hand, or both? | Both (Ed). By hand from the right-click menu or a Done column, and automatically N days after the task was finished (Tasks โ Settings โ Archive, default 30, Never available) |
| 29 Nov 2026 | A job that archives, or a rule worked out when tasks are read? | Worked out when read. The only task job (task_recurrence) runs only on installs with a fixed-schedule repeat, so a new job would have to be scheduled by every administrator before anything happened. A rule needs nothing scheduled, and changing N takes effect at once - both ways |
| 29 Nov 2026 | What does Hide done do to the Done columns? | They stay, empty, with a count of what is hidden. Removing them (#184) left nowhere to drag a card to Done |
The rule
A task is archived when it is in a closed status and either:
- it was archived by hand -
tasks.archived_datetimeis set; or - it was finished more than N days ago (
completed_datetime), and it has not been restored in the last N days (restored_datetime).
// includes/task_archive.php
function taskArchivedSql(PDO $conn, string $t = 't', string $s = 'ts'): string
{
if (!taskArchiveReady($conn)) return '0';
$days = taskArchiveDays($conn); // tasks_archive_after_days, clamped 0-3650; 0 = never
$auto = $days > 0
? " OR ($t.completed_datetime IS NOT NULL AND $t.completed_datetime < UTC_TIMESTAMP() - INTERVAL $days DAY"
. " AND ($t.restored_datetime IS NULL OR $t.restored_datetime < UTC_TIMESTAMP() - INTERVAL $days DAY))"
: '';
return "(COALESCE($s.is_closed, 0) = 1 AND ($t.archived_datetime IS NOT NULL$auto))";
}
TRAP: only a closed task can be archived. Reopening a task by any path - the board, the API, a workflow - brings it straight back, and no code has to remember to clear the mark. The test pins this down with an open task that has archived_datetime set.
Restore gives another N days. Restore clears archived_datetime and stamps restored_datetime. Without that, a task finished 40 days ago on a 30-day setting would vanish again the moment it was restored.
$days is an integer clamped by taskArchiveDays(), so inlining it is safe. Before Database Verification has added the columns, the expression is '0' and nothing is archived.
Where it applies
| Place | Archived tasks |
|---|---|
api/tasks/list.php (the board, list, table, calendar and timeline) |
Left out. ?archived=only lists them (the Archived dialog), ?archived=include keeps them. A subtask whose parent is archived is left out too |
| History, the evidence report, projects, follow-ups, links, the REST API | Unchanged - archiving tidies the board, it removes nothing |
list.php also returns archived_count: how many tasks the same filter has in Archived, for the number beside the sidebar's Archived button.
// api/tasks/list.php - the same WHERE as the board, archived only
$aw = $whereBeforeArchive;
$aw[] = $archSelf;
$ac = $conn->prepare("SELECT COUNT(*) FROM tasks t LEFT JOIN task_statuses ts ON ts.id = t.status_id
WHERE " . implode(' AND ', $aw) . $tenantSql);
Archiving and restoring
POST api/tasks/archive.php:
{ "action": "archive", "task_ids": [12, 13] } // -> { "archived": 1, "skipped": 1 }
{ "action": "restore", "task_id": 12 }
- Needs write access to Tasks (
requireModuleWriteJsonandTasksService::assertCanWrite), and each task must be one the analyst can reach (analystCanAccessTask). - Archive skips, and counts, anything that is not closed or already archived by hand. It never half-does a batch silently. At most 1,000 at a time.
- Restore refuses a task that is not archived.
- Each one writes a task history event,
archivedorrestored, shown in the task's History.
A Done column's archive button sends the ids of the tasks the column shows, after the board's search, tag, project and contractor filters. It asks first, with the count.
The setting
Tasks โ Settings โ Archive, its own tab and capability (Cap::TASKS_ARCHIVE, tasks.archive). It is a dropdown, not a number box: Never, 7, 14, 30, 60, 90, 180 or 365 days. save_settings.php accepts any whole number 0-3650 and ignores anything else. A value outside the list, set through the API, is still shown.
Follow-ups (the rest of #442)
- The title box was a sliver.
.detail-selectiswidth:100%, so the Task/Ticket picker beside it took the whole line.#taskFollowUpSection .fu-line .detail-select { width: auto; flex: 0 0 auto; }- with aTRAP:comment. - Both lines are labelled - Create a new one / Or link one that already exists.
- Linking searches.
api/tasks/search_links.php?type=task&q=โฆ&exclude=Nfinds a task byTASK-12,12or its title, in the board's company scope, leaving the open task out. Typing a number and pressing Enter or Link still works.
๐ Files
| File | Change |
|---|---|
๐ข includes/task_archive.php |
The rule, archive and restore |
๐ข api/tasks/archive.php |
Archive / restore |
๐ก api/tasks/list.php |
Leaves archived tasks out; ?archived=; archived_count |
๐ก api/tasks/search_links.php |
type=task |
๐ก api/tasks/save_settings.php, get_settings.php |
archive_after_days |
๐ก assets/js/tasks.js, tasks-ctx-menu.js, assets/css/tasks.css |
Done columns kept, archive button, Archived dialog, menu item, follow-up box |
๐ก tasks/index.php, tasks/settings/index.php, manifest.php, includes/capabilities.php |
The dialog, the Archive tab and its permission |
๐ฃ database/freeitsm.sql, includes/db_verify_schema.php |
tasks.archived_datetime, tasks.restored_datetime |
๐ข tests/task-archive.php |
29 checks on a test install |
How it was proved
tests/task-archive.php on a test install:
- The rule: each case with its control.
- The endpoints: the archived task is on the board before it's archived, so an empty list can't pass.
- The setting's limits.
- The follow-up search.
The board, the Archived dialog and the follow-up box were also checked in a browser.