mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Boards opened under the versions before #6515 had every per-swimlane list
un-bound automatically: the board data-repair treated any list with a
swimlaneId as #6484 corruption and cleared it, and a per-swimlane list is
indistinguishable from a corrupted board-wide one at the data level. #6515
stopped it. Nothing put the bindings back, so those lists still render under
every swimlane, and deleting one from a swimlane deletes the only list document
there is - which is what #6670 reports.
The old value is recoverable, not guessable. That clearing went through
Lists.direct.updateAsync, which bypasses collection hooks, so it only ever
touched the list document - while the binding each list was CREATED with is
recorded in a different collection:
// models/lists.js - Lists.after.insert -> trackOriginalPosition()
originalSwimlaneId: this.swimlaneId || null,
if (!existingHistory) { PositionHistory.insertAsync(document); }
That insert is insert-ONLY, written once at creation and never overwritten, so
it survived untouched for every list created since list position tracking
landed (2025-10-16, 2543df942).
Admin Panel / Problems / Summary now detects this the way it detects broken
cards - "Lists missing their swimlane N", with a Restore button beside it -
and restoring puts each list back in the swimlane its own record names.
Every rule is a reason to SKIP, because the failure mode here is worse than
doing nothing:
- a list that already has a swimlaneId is never touched, so the repair is
idempotent and cannot undo a binding an admin has since set by hand;
- a list with no record, or one recorded as board-wide (null), stays
board-wide;
- a swimlane that has since been deleted is not resurrected, and one on
another board is refused - either would hide the list in every swimlane,
which is worse than leaving it shared.
Nothing is inferred from the cards, and a test pins that the planner cannot
grow a use for them. Inference is the obvious idea and it is wrong: on a board
whose second swimlane is new every card is still in the first one, so it would
bind every list to swimlane 1 and hide them from the others - #6484 again,
the bug the clearing existed to fix.
Detection is read-only and swallows its own errors, because the Problems page
polls it every 30 seconds and a detection that throws would take the other
problems on that page with it. The repair writes swimlaneId and nothing else,
through .direct, one update per swimlane rather than one per list.
One new string, translated into all 197 locales that were complete, each
following that file's own "Repaired __fixed__ card(s)." sibling so the count
style and script match what the language already uses here. Low confidence on
the long tail - Bislama, Buryat, Cherokee, Ewe, Fijian, Greenlandic, Inuktitut,
Klingon, Nahuatl, Sakha, Tamazight, Venda, Volapük, Wolof - which a speaker
should correct. Noted while writing them: the `lists` value is wrong-language in
mn (Russian), sk (Czech), sr and wa-RR (Tagalog); not touched here.
Also fixed a guard that the parallel worktree exposed:
tests/noIdentityReplacement.test.cjs walked into .claude/worktrees/, a full
second checkout, and reported the deliberate samples in ITS copy of that test
file as real findings.
Thanks to TawsTm and xet7 !
140 lines
5.6 KiB
JavaScript
140 lines
5.6 KiB
JavaScript
import RecoveryStatus from '/models/recoveryStatus';
|
|
import AttachmentMigrationStatus from '/models/attachmentMigrationStatus';
|
|
import TextMigrationStatus from '/models/textMigrationStatus';
|
|
import Cards from '/models/cards';
|
|
import { loginProblemChecks } from '/models/lib/loginProblems';
|
|
import { buildProblemsOverview } from '/models/lib/problemsOverview';
|
|
import { brokenCardsSelector } from '/models/lib/brokenCardsRepair';
|
|
import { countRestorableListSwimlanes } from '/server/lib/restoreListSwimlanes';
|
|
import { isStatusActive } from '/models/lib/statusActive';
|
|
|
|
// Server hub for the Admin Panel / Problems "Status" overview and the
|
|
// `snap run wekan.problems` command. It PERSISTS the text-migration and
|
|
// board-repair progress (so a separate process can see "a migration/repair is in
|
|
// progress") and AGGREGATES every in-progress migration/repair plus the detected
|
|
// problems into one overview.
|
|
|
|
const TEXT_MIGRATION_ID = 'text-migration';
|
|
const BOARD_REPAIR_ID = 'board-repair';
|
|
const REPAIR_MARKER_ID = 'startup-repair-version';
|
|
|
|
async function upsertStatusDoc(id, fields) {
|
|
try {
|
|
await TextMigrationStatus.upsertAsync(
|
|
{ _id: id },
|
|
{ $set: { ...fields, _id: id, updatedAt: new Date() } },
|
|
);
|
|
} catch (error) {
|
|
console.error('[systemStatus] persist', id, error);
|
|
}
|
|
}
|
|
|
|
// Persist the MongoDB <-> SQLite text-migration progress snapshot.
|
|
export async function setTextMigrationStatus(fields) {
|
|
await upsertStatusDoc(TEXT_MIGRATION_ID, fields);
|
|
}
|
|
|
|
// Persist the server-side board data-repair progress snapshot.
|
|
export async function setBoardRepairStatus(fields) {
|
|
await upsertStatusDoc(BOARD_REPAIR_ID, fields);
|
|
}
|
|
|
|
// Version marker so the startup board-repair pass runs once per version, not on
|
|
// every boot (a full scan is expensive). Board open still repairs per board.
|
|
export async function getRepairMarkerVersion() {
|
|
const doc = await TextMigrationStatus.findOneAsync({ _id: REPAIR_MARKER_ID });
|
|
return doc && Number.isFinite(doc.version) ? doc.version : 0;
|
|
}
|
|
export async function setRepairMarkerVersion(version, summary) {
|
|
await upsertStatusDoc(REPAIR_MARKER_ID, { version, summary: summary || null });
|
|
}
|
|
|
|
function describeTextMigration(tm) {
|
|
let where = '';
|
|
if (tm.phase === 'migrating') {
|
|
where = `: ${tm.collection || ''} (${tm.collectionsDone || 0}/${tm.collectionsTotal || 0} collections)`;
|
|
} else if (tm.phase === 'repairing') {
|
|
where = `: repairing ${tm.boardsDone || 0}/${tm.boardsTotal || 0} boards`;
|
|
}
|
|
return `Database migration (${tm.direction || '?'}) — ${tm.phase || 'running'}${where}`;
|
|
}
|
|
|
|
// Everything currently in progress, as [{ kind, active, message }].
|
|
export async function getInProgress() {
|
|
const items = [];
|
|
|
|
// #6520: use isStatusActive, not the raw `running` flag, so a stale
|
|
// running:true (a completion write that lost a race with a late progress write,
|
|
// or a process killed mid-run) does not show the migration/repair "in progress"
|
|
// forever — e.g. "Board data-repair — 146/146 boards" that never clears.
|
|
const tm = await TextMigrationStatus.findOneAsync({ _id: TEXT_MIGRATION_ID });
|
|
if (isStatusActive(tm)) {
|
|
items.push({ kind: 'database-migration', active: true, message: describeTextMigration(tm) });
|
|
}
|
|
|
|
const br = await TextMigrationStatus.findOneAsync({ _id: BOARD_REPAIR_ID });
|
|
if (isStatusActive(br)) {
|
|
items.push({
|
|
kind: 'board-repair',
|
|
active: true,
|
|
message: `Board data-repair — ${br.boardsDone || 0}/${br.boardsTotal || 0} boards`,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const rec = await RecoveryStatus.findOneAsync({});
|
|
if (rec && rec.active) {
|
|
items.push({ kind: 'recovery', active: true, message: rec.message || 'Data recovery / maintenance in progress' });
|
|
}
|
|
} catch (_) {}
|
|
|
|
// The cron-driven migration subsystem that wrote `cronJobStatus` docs is gone (it
|
|
// never ran and had no UI), so this no longer looks there. Leaving the check in
|
|
// would have been worse than useless: a leftover status:'running' doc from an older
|
|
// version has nothing to clear it now, so Problems would show "Migration job X
|
|
// running" forever.
|
|
|
|
try {
|
|
const att = await AttachmentMigrationStatus.findOneAsync({ $or: [{ running: true }, { status: 'running' }] });
|
|
if (att) {
|
|
items.push({ kind: 'attachment-migration', active: true, message: att.message || 'Attachment migration / repair in progress' });
|
|
}
|
|
} catch (_) {}
|
|
|
|
return items;
|
|
}
|
|
|
|
// The login-page "Must be logged in" cause checklist (detected values).
|
|
export async function getLoginProblems() {
|
|
const inProgress = await getInProgress();
|
|
return loginProblemChecks({
|
|
migrationActive: inProgress.length > 0,
|
|
migrationMessage: inProgress.map(x => x.message).join('; '),
|
|
rootUrl: process.env.ROOT_URL || '',
|
|
ldapEnabled: process.env.LDAP_ENABLE === 'true' || process.env.LDAP_ENABLE === true,
|
|
sandstorm: !!(process.env.SANDSTORM || process.env.SANDSTORM_SMTP_SEND),
|
|
});
|
|
}
|
|
|
|
// What counts as broken lives in models/lib/brokenCardsRepair.js, shared with
|
|
// the Repair button on the Summary page, so the count and the repair can never
|
|
// disagree about which cards they mean.
|
|
async function countBrokenCards() {
|
|
try {
|
|
return await Cards.find(brokenCardsSelector()).countAsync();
|
|
} catch (_) {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
// The Problems "Status" overview: everything in progress + detected problems.
|
|
export async function getProblemsOverview() {
|
|
const [inProgress, loginProblems, brokenCards, unboundLists] = await Promise.all([
|
|
getInProgress(),
|
|
getLoginProblems(),
|
|
countBrokenCards(),
|
|
countRestorableListSwimlanes(),
|
|
]);
|
|
return buildProblemsOverview({ inProgress, loginProblems, brokenCards, unboundLists });
|
|
}
|