Skip to content

feat(kb): functional knowledge base backed by database tables - #72

Merged
mpge merged 1 commit into
mainfrom
feat/knowledge-base
Aug 2, 2026
Merged

feat(kb): functional knowledge base backed by database tables#72
mpge merged 1 commit into
mainfrom
feat/knowledge-base

Conversation

@mpge

@mpge mpge commented Aug 2, 2026

Copy link
Copy Markdown
Member

Summary

Makes the knowledge base functional, porting the Laravel reference to this plugin's table-based convention. Previously the widget queried a escalated_article custom post type that was never registered via register_post_type, so the public KB always returned nothing and there was no in-app authoring.

What changed

Storage (new tables, created via Activator::create_tables() / picked up by maybe_upgrade() on the bump to 1.3.0):

  • escalated_article_categories — self-referencing tree (parent_id), slug, position, description.
  • escalated_articlestitle/slug (unique), body, status (draft/published), published_at, optional category_id/author_id, and view_count/helpful_count/not_helpful_count.

Models (Escalated\Models\Article, Escalated\Models\ArticleCategory) using the existing static $wpdb helper pattern (like CannedResponse/ApiToken).

Admin CRUD REST controllers, registered in Api_Bootstrap like the others:

  • GET/POST /escalated/v1/admin/kb/articles, GET/PUT/PATCH/DELETE /admin/kb/articles/{id}
  • GET/POST /escalated/v1/admin/kb/categories, PUT/PATCH/DELETE /admin/kb/categories/{id}
  • Gated by the existing escalated_kb_view / _create / _edit / _delete capabilities — no new capability added, so the activator capability-count assertion (54) is unchanged.

Public read — the widget endpoints now read published articles from the tables (the bug fix): /widget/articles (list), /widget/articles/{slug} (show — increments the view counter, returns related articles), plus a new /widget/articles/{slug}/feedback recording helpful/not-helpful when knowledge_base_feedback_enabled. Slug/publish/category semantics match the reference.

Tests

New Test_Knowledge_Base_Api (13 tests, WP_UnitTestCase): table creation, admin create → public list/show, unpublished excluded from the public surface, category assignment, capability gating (agent can view but not create; unauthenticated 401), draft→publish stamping published_at, view-count increment, and helpful/not-helpful feedback.

Full suite green: 391 tests / 1030 assertions, 4 pre-existing skips (up from 378), Pint clean.

Port the Laravel reference knowledge base to the WordPress plugin's
table-based convention, replacing the stub that queried a never-registered
`escalated_article` custom post type (so the widget always returned nothing).

- Add `escalated_article_categories` (self-referencing tree, slug/position)
  and `escalated_articles` (draft/published + published_at, unique slug,
  optional category/author, view/helpful counters) tables to the activator's
  create_tables(); existing installs pick them up via maybe_upgrade() on the
  version bump to 1.3.0.
- Add Article and ArticleCategory models using the static $wpdb helper pattern.
- Add admin CRUD REST controllers under /admin/kb/articles and
  /admin/kb/categories, gated by the existing kb.* capabilities (no new
  capability, so the activator capability-count assertion is unchanged).
- Wire the public widget endpoints to read published articles from the tables:
  list, show (increments view count, returns related articles), and a new
  /articles/{slug}/feedback endpoint recording helpful/not-helpful when enabled.

Adds Test_Knowledge_Base_Api (13 tests) covering table creation, admin create
-> public list/show, unpublished excluded, category assignment, capability
gating, view increment, and feedback. Full suite: 391 passing.
@mpge
mpge merged commit 39c06d2 into main Aug 2, 2026
3 checks passed
@mpge
mpge deleted the feat/knowledge-base branch August 2, 2026 03:28
mpge added a commit that referenced this pull request Aug 2, 2026
Port the Laravel reference knowledge base to the WordPress plugin's
table-based convention, replacing the stub that queried a never-registered
`escalated_article` custom post type (so the widget always returned nothing).

- Add `escalated_article_categories` (self-referencing tree, slug/position)
  and `escalated_articles` (draft/published + published_at, unique slug,
  optional category/author, view/helpful counters) tables to the activator's
  create_tables(); existing installs pick them up via maybe_upgrade() on the
  version bump to 1.3.0.
- Add Article and ArticleCategory models using the static $wpdb helper pattern.
- Add admin CRUD REST controllers under /admin/kb/articles and
  /admin/kb/categories, gated by the existing kb.* capabilities (no new
  capability, so the activator capability-count assertion is unchanged).
- Wire the public widget endpoints to read published articles from the tables:
  list, show (increments view count, returns related articles), and a new
  /articles/{slug}/feedback endpoint recording helpful/not-helpful when enabled.

Adds Test_Knowledge_Base_Api (13 tests) covering table creation, admin create
-> public list/show, unpublished excluded, category assignment, capability
gating, view increment, and feedback. Full suite: 391 passing.

Co-authored-by: Matt Gros <mpge@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant