Skip to content

Knowledge Feedback Developer Guide

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

Knowledge feedback - Developer Guide

"Was this helpful?" and "Report as outdated" on Knowledge articles - after 5.19.0, asked for in #468 by @Dr4inder. User side: Knowledge - Feedback and Help Centre.

Knowledge counted reads, but a read says nothing about whether the reader found the answer, and a wrong step could not be reported on the article itself. Now every article ends with Yes / No, analysts can Report as outdated, and the comments reach the owner.


1. πŸ“ The files

File Role
includes/knowledge/feedback.php All the rules: knowledgeFeedbackVote(), knowledgeFeedbackReportOutdated(), knowledgeFeedbackTellOwner(), knowledgeFeedbackFor(), knowledgeFeedbackResolve(), knowledgeFeedbackOpenSql()
api/knowledge/article_feedback.php Analysts: read the feedback, vote, report, resolve
api/self-service/knowledge_feedback.php Portal readers: vote, and read their own vote only
api/knowledge/get_review_list.php, knowledge/review/index.php The Review page's Feedback tab and count
assets/js/knowledge.js (kbLoadFeedback(), kbFeedbackPost()) The box under an article, and the comments list
self-service/help-centre.php (hcLoadFeedback(), hcVote()) The portal's Yes / No
includes/services/notifications.php knowledge.feedback - the owner's bell
Tables knowledge_feedback (new)

2. πŸ—„οΈ One table, two kinds

CREATE TABLE IF NOT EXISTS `knowledge_feedback` (
    `id`                INT NOT NULL AUTO_INCREMENT,
    `article_id`        INT NOT NULL,
    `analyst_id`        INT NULL,
    `user_id`           INT NULL,
    `kind`              VARCHAR(12) NOT NULL,      -- 'vote' | 'outdated'
    `helpful`           TINYINT(1) NULL,           -- votes only: 1 / 0
    `comment`           TEXT NULL,
    `resolved_datetime` DATETIME NULL,
    `resolved_by_id`    INT NULL,
    ...
    KEY `idx_knowledge_feedback_article` (`article_id`, `kind`)
);

Exactly one of analyst_id (an analyst) and user_id (a signed-in portal user) says who - knowledgeFeedbackWho() refuses anything else, so there are no anonymous votes and nobody can flood an article. Both columns are in the analyst lifecycle map as history.

3. πŸ—³οΈ One vote per reader, changeable

knowledgeFeedbackVote() looks for the reader's existing vote row and updates it, or inserts one. A Yes drops any comment (only a No asks what was missing). A changed vote is a new opinion, so an old resolved mark is cleared. A No with a comment tells the owner.

4. 🚩 Report as outdated

$conn->prepare("INSERT INTO knowledge_feedback (article_id, $col, kind, comment, created_datetime, updated_datetime)
                VALUES (?, ?, 'outdated', ?, UTC_TIMESTAMP(), UTC_TIMESTAMP())")
     ->execute([$articleId, $id, $comment]);
// Due today - unless it was already due earlier, which stays (an overdue article
// must not look less overdue because somebody reported it).
$conn->prepare("UPDATE knowledge_articles SET next_review_date = DATE(UTC_TIMESTAMP())
                 WHERE id = ? AND (next_review_date IS NULL OR next_review_date > DATE(UTC_TIMESTAMP()))")
     ->execute([$articleId]);

A comment is required (an empty report tells the owner nothing). The article shows as due on the Review page straight away, and the review reminders (#469) pick it up.

5. πŸ”” Telling the owner

knowledgeFeedbackTellOwner() sends knowledge.feedback to the article's owner, else its author, about the article (entity_type = 'knowledge_article'). The bell's own rules apply: never about your own action, switchable in Preferences (on by default), merged with anything else unread about the article. A failure is logged, never thrown - feedback is saved whether or not the bell worked.

6. πŸ”’ Who sees what

  • Analysts who can read the article (knowledgeCanRead()) see the counts, their own vote and every comment.
  • Portal readers must be signed in and able to read the article (portalCanReadArticle()); their endpoint returns only their own vote - never the counts, never anyone's comments. Comments stay with the analysts.
  • Resolving needs the article's owner or Cap::KNOWLEDGE_MANAGE. ⚠️ That is a settings capability, so it is checked with analystHasCapability(); analystMayAct() refuses it ("not an everyday-work capability") - the first version of the endpoint failed every save that way.

7. πŸ“‹ The Review page's Feedback tab

function knowledgeFeedbackOpenSql(string $alias = 'ka'): string
{
    return "EXISTS (SELECT 1 FROM knowledge_feedback kf WHERE kf.article_id = $alias.id AND kf.resolved_datetime IS NULL
                     AND kf.comment IS NOT NULL AND kf.comment <> '' AND (kf.kind = 'outdated' OR kf.helpful = 0))";
}

An article is listed while it has an open comment: an unresolved outdated report, or an unresolved No with something said. A bare No with no comment counts in the ratio but does not ask anybody to act. The tab's count comes from the same expression. Before Database Verification the tab is empty and the count 0.

8. ⚠️ Traps found building it

  • display: flex beats [hidden]. The comment box under the article showed before anyone clicked No, because .kb-fb-form { display: flex } outranks the browser's [hidden] { display: none }. Both pages now say .kb-fb-form[hidden] { display: none; } - see Code traps.
  • The portal reads the article through portalKnowledgeScope() - audience customer or public. A test article with an audience value that does not exist (everyone) is simply invisible there.

9. βœ… Tests

FREEITSM_TEST_DATABASE=<throwaway db> FREEITSM_TEST_URL=http://localhost/<install> php tests/knowledge-feedback.php - 13 checks through the real endpoints as two analysts and a portal user: one vote per reader, the comment reaching the analysts and the owner's bell, the portal returning only its own vote, signed-out refused, a report needing a comment and making the article due today, the Feedback tab, resolving.

10. 🧭 Design decisions (5 December 2026)

Decision Options Chosen, and why Who
Anonymous votes on public articles Allow; limit; signed-in only Signed-in only - the request named flooding as the risk; every portal reader of Knowledge is signed in anyway Requester's suggestion
Portal "Report as outdated" Analysts only; portal too Analysts only - a portal reader's No with a comment already says it; reporting changes the article's review date, which is staff's call Me (the request made the portal optional)
Where comments are read A separate Feedback view; under the article Under the article, analysts only, plus the Review tab - the owner sees them where they fix the article Me
Marking a comment resolved No; yes Yes (the request's optional point) - otherwise the Feedback tab only ever grows Requester's suggestion
Who is told Owner; owner else author; Knowledge managers Owner, else author - the person who would fix it. Closest to ITIL (knowledge management): feedback reaches the article's owner, who keeps it accurate Me

Related pages

Knowledge Β· Knowledge review reminders - Developer Guide Β· Notifications - Developer Guide Β· Developer Tests - Knowledge

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally