mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
repairBoardsOnStartup ran the shared board repair over every board and, via planBoardRepair, cleared swimlaneId to null on EVERY list that had one -- treating any swimlane-bound list as #6484 corruption. But a list with a swimlaneId is a legitimate PER-SWIMLANE list (rendered only in its swimlane via swimlaneLists()), indistinguishable from a #6484-corrupted board-wide list at the data level. So on upgrade to v10.26+ the routine silently unbound every per-swimlane list (the reporter: listsUnbound: 24) and all lists then rendered in every swimlane. Board open re-ran the same repair, so even a manual swimlaneId restore in the DB was nulled again. Remove list-unbind from the automatic plan (planBoardRepair.listsUnbind is always empty; repairBoardData no longer issues the swimlaneId: null write). The card repairs (missing-swimlane, orphaned) are kept. The #6484 CODE bug that could wrongly bind a board-wide list is already fixed, and an admin can still deliberately un-bind a specific board with the explicit repairBoardWideLists method. Affected boards keep their swimlaneIds now; a manual restore from a pre-upgrade backup will stick. Tests: boardRepair.test.cjs updated to assert per-swimlane lists are never auto-unbound and the applier no longer clears swimlaneId. Thanks to jullbo and xet7 ! Fixes #6515,
105 lines
4.0 KiB
JavaScript
105 lines
4.0 KiB
JavaScript
import Boards from '/models/boards';
|
|
import Cards from '/models/cards';
|
|
import Lists from '/models/lists';
|
|
import Swimlanes from '/models/swimlanes';
|
|
import { planBoardRepair, repairCounts } from '/models/lib/boardRepair';
|
|
|
|
// Server side of the shared board data-repairs (see models/lib/boardRepair.js for
|
|
// what is repaired and why). Used by BOTH:
|
|
// * board open -> server/methods/repairBoardData.js (boardRepairNeeded /
|
|
// repairBoardData), driven by client/components/boards/boardBody.js
|
|
// * the MongoDB <-> FerretDB v1 (SQLite) text migration ->
|
|
// server/methods/migrateTextDatabase.js runs repairAllBoards() on the live
|
|
// database before copying, so the migrated copy is clean too.
|
|
// All writes go through `.direct` (skip collection hooks) and are idempotent, so
|
|
// re-running is safe.
|
|
|
|
async function loadBoardData(boardId) {
|
|
const [swimlanes, lists, cards] = await Promise.all([
|
|
Swimlanes.find({ boardId }).fetchAsync(),
|
|
Lists.find({ boardId }).fetchAsync(),
|
|
Cards.find({ boardId }).fetchAsync(),
|
|
]);
|
|
return { swimlanes, lists, cards };
|
|
}
|
|
|
|
// The board's first usable swimlane (non-archived, non-template, lowest sort);
|
|
// creates a 'Default' swimlane if the board has none.
|
|
async function firstSwimlaneId(boardId) {
|
|
const existing = await Swimlanes.findOneAsync(
|
|
{ boardId, type: { $ne: 'template-swimlane' }, archived: false },
|
|
{ sort: { sort: 1 } },
|
|
);
|
|
if (existing) return existing._id;
|
|
return Swimlanes.insertAsync({
|
|
title: 'Default',
|
|
boardId,
|
|
archived: false,
|
|
sort: 0,
|
|
type: 'swimlane',
|
|
});
|
|
}
|
|
|
|
// Detect (no writes) what a board needs repaired. Returns
|
|
// { listsUnbound, cardsAssigned, cardsRescued, total }.
|
|
export async function detectBoardRepairs(boardId) {
|
|
const { swimlanes, lists, cards } = await loadBoardData(boardId);
|
|
return repairCounts(planBoardRepair(swimlanes, lists, cards));
|
|
}
|
|
|
|
// Apply the repairs for one board. Returns the same counts (what was fixed).
|
|
export async function runBoardRepair(boardId) {
|
|
const { swimlanes, lists, cards } = await loadBoardData(boardId);
|
|
const plan = planBoardRepair(swimlanes, lists, cards);
|
|
const counts = repairCounts(plan);
|
|
if (counts.total === 0) return counts;
|
|
|
|
// #6515: the automatic repair no longer clears list swimlaneIds — a per-swimlane
|
|
// list (a set swimlaneId) is legitimate and indistinguishable from #6484
|
|
// corruption, so plan.listsUnbind is always empty here. Deliberate per-board
|
|
// un-binding stays available via the admin repairBoardWideLists method.
|
|
|
|
// Missing-swimlane and orphaned cards -> the board's first swimlane, so they
|
|
// become visible again in the Swimlanes view.
|
|
const cardsToFix = plan.cardsMissing.concat(plan.cardsOrphaned);
|
|
if (cardsToFix.length > 0) {
|
|
const swimlaneId = await firstSwimlaneId(boardId);
|
|
await Cards.direct.updateAsync(
|
|
{ _id: { $in: cardsToFix }, boardId },
|
|
{ $set: { swimlaneId } },
|
|
{ multi: true },
|
|
);
|
|
}
|
|
|
|
return counts;
|
|
}
|
|
|
|
// Repair every (non-archived) board. onProgress(done, total, totals) is called
|
|
// after each board so a caller (the DB migration) can report progress. Never
|
|
// throws for a single bad board — it logs and continues.
|
|
export async function repairAllBoards(onProgress) {
|
|
const boards = await Boards.find(
|
|
{ archived: false },
|
|
{ fields: { _id: 1 } },
|
|
).fetchAsync();
|
|
const total = boards.length;
|
|
let done = 0;
|
|
const totals = { boardsRepaired: 0, listsUnbound: 0, cardsAssigned: 0, cardsRescued: 0 };
|
|
for (const board of boards) {
|
|
try {
|
|
const counts = await runBoardRepair(board._id);
|
|
totals.listsUnbound += counts.listsUnbound;
|
|
totals.cardsAssigned += counts.cardsAssigned;
|
|
totals.cardsRescued += counts.cardsRescued;
|
|
if (counts.total > 0) totals.boardsRepaired += 1;
|
|
} catch (error) {
|
|
console.error('[repairAllBoards] board', board._id, error);
|
|
}
|
|
done += 1;
|
|
if (typeof onProgress === 'function') {
|
|
try { onProgress(done, total, totals); } catch (_) {}
|
|
}
|
|
}
|
|
return { boardsScanned: total, ...totals };
|
|
}
|