Skip to content

Knowledge Review Reminders Developer Guide

Ed Mozley edited this page Dec 1, 2026 · 1 revision

Knowledge review reminders - developer guide

5.15.0, #469, raised by @Dr4inder. The user's view: Knowledge § Reviews and reminders.

An article has an owner (knowledge_articles.owner_id) and a next review date (next_review_date). Before 5.15.0 a date passing showed on Knowledge → Review and in the Watchtower count, and nobody was told. Now a daily job sends each owner one bell notification with how many of their articles are due or overdue, linked to Knowledge → Review. Off by default.

📁 Files

File What
includes/knowledge/review_reminders.php The module: the settings, and knowledgeReviewRemindersRun()
cron/knowledge_review_reminders.php The job's script - command line only
includes/job_registry.php The knowledge_review_reminders entry, and its module in $jobModules
includes/services/notifications.php The knowledge.review_due type in types()
includes/entity_links.php knowledge_review → knowledge/review/
lang/*/common.php notifications.event.knowledge.review_due and notifications.pref.knowledge.review_due
lang/en/reporting.php jobs.name_knowledge_review_reminders, jobs.affects_knowledge_review_reminders
knowledge/settings/manifest.php, knowledge/settings/index.php The Reviews tab
includes/feature_bingo/cards/knowledge.php Card knowledge.review_reminders
tests/knowledge-review-reminders.php 16 checks against a real database, rolled back

⚙️ The settings

Three system_settings keys, each checked against the values the page offers - anything else is the default:

Key Values Default
knowledge_review_reminders off, weekly, daily off
knowledge_review_warn_days 0, 7, 14, 30 - also count reviews due within this many days 7
knowledge_review_unowned_to an analyst id, or '' (nobody) ''
const KB_REVIEW_MODES     = ['off', 'weekly', 'daily'];
const KB_REVIEW_WARN_DAYS = ['0', '7', '14', '30'];

$s = knowledgeReviewReminderSettings($conn);   // ['mode' => 'off', 'warn' => 7, 'unowned' => 0]

knowledgeReviewReminderSettings() reads the three keys in one query and swallows a missing table (off). An unknown mode - hourly, a typo - is off, never "on, somehow" (one of the test's checks).

Who may write them

The Reviews tab is declared in the module's manifest, and that is what makes its keys writable:

[
    'id'           => 'reviews',
    'cap'          => capKey(Cap::KNOWLEDGE_MANAGE),
    'label_key'    => 'knowledge.settings.tab_reviews',
    'grant'        => 'Turn review reminders on or off and choose who hears about articles with no owner',
    'setting_keys' => ['knowledge_review_reminders', 'knowledge_review_warn_days', 'knowledge_review_unowned_to'],
],

settingKeyOwners() (includes/settings_keys.php) derives key → capability from every manifest, so the generic api/settings/save_system_settings.php accepts these three keys from someone with Cap::KNOWLEDGE_MANAGE and refuses them from anyone else - no endpoint of its own. The tab posts there:

fetch('../../api/settings/save_system_settings.php', { method: 'POST', ...
    body: JSON.stringify({ settings: {
        knowledge_review_reminders:  document.getElementById('kbReviewMode').value,
        knowledge_review_warn_days:  document.getElementById('kbReviewWarn').value,
        knowledge_review_unowned_to: document.getElementById('kbReviewUnowned').value
    } }) });

It reads them server-side when the page is drawn (knowledgeReviewReminderSettings() in knowledge/settings/index.php), not through api/settings/get_system_settings.php, whose module check (assets, software, tickets, system) a Knowledge-only manager would not pass. The unowned recipient is a dropdown of active analysts - no typed ids.

🔁 knowledgeReviewRemindersRun()

$st = $conn->prepare(
    "SELECT ka.id, ka.next_review_date, an.id AS owner
       FROM knowledge_articles ka
  LEFT JOIN analysts an ON an.id = ka.owner_id AND an.is_active = 1
      WHERE COALESCE(ka.is_archived, 0) = 0
        AND ka.next_review_date IS NOT NULL
        AND ka.next_review_date <= ?"
);
$st->execute([$until]);   // today + warn days
  • Archived articles and articles with no review date never count.
  • An owner who has left is no owner. The LEFT JOIN ... AND an.is_active = 1 makes owner NULL for an inactive or deleted analyst, so the article goes to the unowned recipient - somebody still has to hear about it. With no recipient chosen it is counted (unowned in the result) and sent to nobody.
  • Each article adds to its recipient's overdue (date before today) or due count, and unowned when it had no owner. The unowned recipient is checked to still be active before anything is sent.

Once per period: the ledger

The same ledger the Projects overdue digest uses (includes/projects/nudges.php), so a reminder goes out once per person per day or week however often the job runs:

$period = $s['mode'] === 'daily' ? $today : gmdate('o-\WW', $todayTs);   // 2027-03-10, or 2027-W10
$claim = $conn->prepare("INSERT IGNORE INTO workflow_scheduled_emissions (trigger_event, entity_key, fingerprint, emitted_datetime)
                         VALUES ('knowledge.review_due', ?, ?, UTC_TIMESTAMP())");
$claim->execute(['kb_review:' . $analystId, $s['mode'] . ':' . $period]);
if ($claim->rowCount() !== 1) continue;   // already told this period

The fingerprint carries the mode, so switching weekly → daily mid-week sends the first daily one rather than waiting. If the ledger cannot be written the loop stops - sending without it would repeat every run.

The notification

NotificationsService::notify($conn, [
    'analyst_id'  => (int)$analystId,
    'event_type'  => 'knowledge.review_due',
    'entity_type' => 'knowledge_review',
    'entity_id'   => (int)$analystId,   // one row per person: next period's reminder updates it
    'entity_ref'  => 'Reviews',
    'title'       => $title,            // "3 Knowledge articles are due for review"
    'body'        => implode(', ', $parts) . '. Open Knowledge - Review to see them.',   // "1 overdue, 2 due within 7 days"
    'actor_id'    => null,
    'actor_name'  => null,   // nobody's action: the schedule's
]);
  • entity_id is the analyst's own id. The bell coalesces by entity, so a person has one review-reminder row that each period's reminder refreshes, not a new row every week.
  • TRAP: counts, never titles. The unowned recipient may not be allowed to read every unowned article - a restricted article's title in their bell would be a disclosure. The notification names no article; Knowledge → Review, where it links, applies the reader's permissions. Do not "improve" the body by listing titles without filtering each through knowledgeCanRead() for that recipient. The test checks no fixture title reaches the notification.
  • actor_id null: rule 1 of notify() (never tell you about your own action) does not apply - it is the schedule's.

🔔 Registering the notification type

// includes/services/notifications.php, types()
'knowledge.review_due'       => ['default' => true,  'entity' => 'knowledge_review'],

// includes/entity_links.php - where the bell row goes
case 'knowledge_review':
    return 'knowledge/review/';

On by default: nothing is sent until an administrator turns reminders on, and then each analyst can switch the type off in Preferences → Notifications.

The labels go in lang/<code>/common.php, under both notifications.event (the bell) and notifications.pref (the Preferences switch):

'knowledge' => [
    'review_due' => 'Knowledge articles are due for review',   // event
],
...
'knowledge' => [
    'review_due' => 'Knowledge articles I own are due or overdue for review (when reminders are on in Knowledge -> Settings -> Reviews)',   // pref
],

tests/notification-labels.php requires both labels in every complete language - English plus da, de, el, es, fr, id, pl and uk - and fails naming the missing keys otherwise. A new notification type therefore ships with those eight translations in the same commit, not in the next translation pass.

⏱️ The job

// includes/job_registry.php
'knowledge_review_reminders' => [
    'command' => 'php cron/knowledge_review_reminders.php', 'web' => false,
    'interval' => 1440, 'grace' => 360, 'max_runtime' => 5,
    'needed'  => fn(PDO $c) => in_array(jobSettingStrict($c, 'knowledge_review_reminders'), ['daily', 'weekly'], true),
],
...
$jobModules = [ ..., 'knowledge_review_reminders' => 'knowledge', ... ];
  • needed is false while reminders are off, so Reporting → System logs → Background jobs does not call a switched-off job overdue.
  • $jobModules: with the Knowledge module switched off for the install the job is not needed either, and the script exits through cronModuleSwitchedOff().
  • Daily even when the setting is weekly. How often it sends is the setting plus the ledger; the job only has to run at least once a day.
  • 'web' => false: command line only (PHP_SAPI !== 'cli' → 403), so it needs no cron token. The script records a skipped run while off, otherwise JobRun::lock() / start() / finish() with a summary like "2 people told about 5 articles due for review (1 with no owner)."

🧪 Testing

FREEITSM_TEST_DATABASE=<db> php tests/knowledge-review-reminders.php

ZZ analysts, articles and settings inside one transaction, always rolled back; $today is injected (knowledgeReviewRemindersRun($conn, '2027-03-10')) so the periods are deterministic. 16 checks: off sends nothing; one notification per owner counting overdue, due today and due within 7 days but not later, archived or undated; no article named; an owner who left is not told and their article reaches the chosen recipient; a second run in the same week sends nothing; the next week sends again; daily is once per day; nobody chosen means unowned articles are counted but not sent; an unknown mode is off; the job is registered and needed only while on.

Also run tests/notification-labels.php, tests/job-health.php and scripts/feature_bingo_check.php after touching any of the registrations.

Related pages

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally