ClaimOrphanRows
in package
Claim every NULL-owner data row across the schema for the given user.
When an existing single-user install is migrated to multi-user mode by
flipping MULTI_USER_ENABLED=true in .env, the
add_user_id_columns.sql migration's backfill is a no-op (it looks for
a users.UsUsername='admin' row that doesn't exist on a fresh users
table). Every legacy row stays at LgUsID/TxUsID/WoUsID = NULL, and
once user-scope filters kick in those rows become invisible to
everyone — looks like total data loss.
The first user to register on such an install is auto-promoted to admin (see Register::execute()). At that exact moment we know there is exactly one operator in charge and that the orphan rows belong to them, so we re-run the backfill against their UsID. On already-migrated installs the UPDATEs match zero rows and cost nothing.
Tags
Table of Contents
Constants
- TABLES = ['languages' => 'LgUsID', 'texts' => 'TxUsID', 'words' => 'WoUsID', 'tags' => 'TgUsID', 'text_tags' => 'T2UsID', 'news_feeds' => 'NfUsID', 'books' => 'BkUsID', 'local_dictionaries' => 'LdUsID']
- Tables and their owner-id columns that need backfilling. Order is irrelevant — every UPDATE is independent.
Methods
- execute() : array<string, int>
- Reassign every NULL-owner row in the multi-user data tables to `$userId`.
Constants
TABLES
Tables and their owner-id columns that need backfilling. Order is irrelevant — every UPDATE is independent.
private
array<string, string>
TABLES
= ['languages' => 'LgUsID', 'texts' => 'TxUsID', 'words' => 'WoUsID', 'tags' => 'TgUsID', 'text_tags' => 'T2UsID', 'news_feeds' => 'NfUsID', 'books' => 'BkUsID', 'local_dictionaries' => 'LdUsID']
Methods
execute()
Reassign every NULL-owner row in the multi-user data tables to `$userId`.
public
execute(int $userId) : array<string, int>
Parameters
- $userId : int
-
UsID of the new owner (must already exist in
users).
Return values
array<string, int> —Per-table count of rows reassigned. Tables that don't exist in this schema version are silently omitted.