Skip to content

Import a board's kinerity/knowledgebase data when enabled - #13

Merged
bonelifer merged 5 commits into
mainfrom
feature/kinerity-import
Nov 12, 2026
Merged

bonelifer merged 5 commits into
mainfrom
feature/kinerity-import

Conversation

@bonelifer

Copy link
Copy Markdown
Contributor

Boards running Kailey's kinerity/knowledgebase extension can now move to this one: disable kinerity, keeping its data, and enable this extension. Enabling it imports kinerity's categories, articles and permissions. Nothing has to be converted by hand. The steps are in docs/upgrading-from-kinerity.md.

Builds on the PostgreSQL fix PR (its two commits are at the start of this branch). Merge that one first.

How it works

  • kinerity's tables are also called kb_articles and kb_categories, with different columns. A new migration that runs before version_1_0_0 copies them to backup tables (kb_kinerity_*) and checks that every row arrived. Only then does it drop the originals, so this extension can create its own tables. The backup tables stay.
  • version_2_0_32 imports from the backup, a batch at a time:
    • Categories: the same tree. Descriptions become plain text, at most 255 characters.
    • Articles: text, author, dates and views are kept.
      • Approved articles are published.
      • Waiting articles go to the approval queue.
      • Deleted and denied articles are kept, deactivated.
      • An article in several categories goes in the oldest one and is cross-listed in the rest.
      • Articles kinerity left in no category go in a new category, named in the board's language.
    • Permissions: each group's and user's kinerity setting (Yes or Never, set directly or through a role) is given to them on every category. kinerity's "read" and "manage" permissions become u_kb_view and a_manage_kb.
    • Clean-up: kinerity's permissions, ACP modules, settings, notification types and extension entry are removed. Its migration records stay, on purpose: re-enabling kinerity would otherwise drop this extension's tables.
  • Each backup row records the id it got here, and is claimed inside its batch's transaction before it is converted. An import that stops part way carries on where it stopped, and two requests at once never import the same row twice.
  • Enabling this extension is refused while kinerity is still enabled.

On large boards, use the command line. phpBB's ACP enables an extension in one page load, so a large import can end on a time-out page while PHP keeps going. Nothing is lost: purge the cache and enable again. The guide explains this.

Tests

  • tests/kb_kinerity_import_test.php builds this extension's real tables from its own migrations and covers each case above, including an import stopped part way and two imports running at once, on SQLite, MySQL and PostgreSQL. The full suite passes on phpBB 3.3.x and master, none skipped.
  • Claude switched seed-forum boards of 2,000 categories and 50,000 articles on phpBB 3.3 (MySQL, PostgreSQL, SQLite) and 4.0 (MySQL, PostgreSQL), through both the command line and the ACP. tests/board/kinerity_import_check.php compared every imported row with kinerity's. All checks passed on every board.
  • tests/browser/kb_kinerity_import.js passed 14 browser checks on the result.
  • Details, and what was not covered, are in docs/testing.md.

Not imported: old kinerity links (/kb/viewarticle?a=…) don't lead to the new article ids; the backup tables record old and new ids.

The board fixture and the ACP helper used for testing are in phpbbmodders/seed-forum and phpbbmodders/phpbb-release-tools PRs.


Investigated and written by Claude on behalf of William Jacoby (bonelifer).

🤖 Generated with Claude Code

bonelifer and others added 5 commits November 11, 2026 22:34
version_1_0_0 inserts the first seven Knowledge Base permission options
with explicit ids, which leaves PostgreSQL's sequence for kb_options at 1.
version_2_0_30 then let the sequence pick the id for kb_m_change_author,
got 1 again, and stopped with a duplicate key, so the extension could not
be enabled on a new PostgreSQL board. It now gives the option the next id
itself, as version_1_0_0 does.

Adds a regression test that builds kb_options the way version_1_0_0 does
and runs version_2_0_30 on SQLite, MySQL and PostgreSQL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On PostgreSQL, version_1_0_3 creates the search-match unique index as
plain un_mtch. phpBB 3.3's database tools find an index by that name but
drop it as {table}_un_mtch, so version_2_0_31 stopped with "index does
not exist" and a fresh phpBB 3.3 PostgreSQL board could not enable the
extension. version_2_0_31 now drops this table's un_mtch index under
whichever name it really has before creating the four-column one. It
leaves an index of that name on another table alone.

The regression test runs the real migration chain for the table
(version_1_0_0, 1_0_3 with its data step, 2_0_2, 2_0_15, then 2_0_31
twice) on SQLite, MySQL and PostgreSQL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kinerity/knowledgebase uses the table names kb_articles and kb_categories
with its own columns. New migration kinerity_tables_set_aside, which
version_1_0_0 now depends on, copies kinerity's tables to kb_kinerity_*
backup tables, counts the copies and drops the originals (and on
PostgreSQL the sequence phpBB 4.0 leaves behind). version_2_0_32 then
imports them in batches: categories with their tree, plain-text details
and kinerity's board-wide permissions on every category; articles with
their text, author, dates and views, the lowest category as primary and
the others cross-listed, waiting articles queued and deleted or denied
ones deactivated; then article counts, u_kb_view and a_manage_kb for
kinerity's readers and admins, and the removal of kinerity's
permissions, ACP modules, settings, notification types and extension
entry. Each backup row records its new id and is claimed inside its
batch's transaction, so an import that stops carries on where it
stopped and two requests never convert a row twice. Enabling is refused
while kinerity is enabled.

docs/upgrading-from-kinerity.md describes the move, including the
command line for large boards and retrying in the ACP.

Tests: kb_kinerity_import_test.php against this extension's real schema
on SQLite, MySQL and PostgreSQL; tests/board/kinerity_import_check.php
compares a switched board with its backup tables row by row, and
tests/browser/kb_kinerity_import.js checks the result in a browser.
docs/testing.md records 50,000-article boards on phpBB 3.3 and 4.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The category made for kinerity articles that were in no category was
named in English in PHP. Its name now comes from the new
language/en/default_content.php, read by inc/default_content.php in the
board's default language, falling back to English. The board checker
finds that category as the one the import adds, not by its name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bonelifer
bonelifer deleted the branch fix/postgres-kb-options-id November 12, 2026 10:39
@bonelifer bonelifer closed this Nov 12, 2026
@bonelifer bonelifer reopened this Nov 12, 2026
@bonelifer
bonelifer changed the base branch from fix/postgres-kb-options-id to main November 12, 2026 10:39
@bonelifer bonelifer closed this Nov 12, 2026
@bonelifer bonelifer reopened this Nov 12, 2026
@bonelifer
bonelifer merged commit e00f2f6 into main Nov 12, 2026
12 of 14 checks passed
@bonelifer
bonelifer deleted the feature/kinerity-import branch November 12, 2026 10:43
bonelifer added a commit that referenced this pull request Nov 12, 2026
EPV fails on htmlspecialchars() in inc/kinerity_import.php (merged in
#13, so main fails its EPV check) and inc/intro.php. They now call
phpBB's utf8_htmlspecialchars(), which does the same (ENT_COMPAT,
UTF-8). inc/default_content.php no longer defines IN_PHPBB itself,
which EPV also flagged; phpBB always defines it, and the tests do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bonelifer added a commit that referenced this pull request Nov 12, 2026
Brings in the fresh-PostgreSQL fix (#12) and the kinerity import (#13).
version_2_0_30 now inserts kb_m_change_author with an explicit id, so it
gets the same IDENTITY_INSERT wrapper on MSSQL as version_1_0_0, with a
test. Both new docs/testing.md sections are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bonelifer added a commit that referenced this pull request Nov 12, 2026
* Add an optional introduction above the Knowledge Base index

The ACP configuration page gets a switch, a text box and a Markdown
option for a short introduction shown under the Knowledge Base title, on
the hierarchical index and the flat index. It is written in BBCode or
Markdown and stored through the same article_text service as articles.
Migration version_2_0_33 adds it switched off, holding the text
kinerity/knowledgebase showed above its index, and switches it on on a
board imported from kinerity, so its visitors keep seeing it.

Tests: kb_intro_test.php (default text, display switch, saving BBCode
and Markdown, emptying, the migration and its kinerity check).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fix the EPV findings from the kinerity import and the intro text

EPV fails on htmlspecialchars() in inc/kinerity_import.php (merged in
#13, so main fails its EPV check) and inc/intro.php. They now call
phpBB's utf8_htmlspecialchars(), which does the same (ENT_COMPAT,
UTF-8). inc/default_content.php no longer defines IN_PHPBB itself,
which EPV also flagged; phpBB always defines it, and the tests do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.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