A row the merge bug minted is visible, fixable, and repairable in bulk (#938)
#920 made a merged ticket read-only on the server and shipped NO data change, deliberately: its guard reads `status === 'merged'` and not `merged_into_id !== null`, so the rows the bug had already produced — the pointer set, the status back to `open` — stayed EDITABLE and could be corrected in the product instead of in SQL. What it left behind was rows that are simultaneously live in the All Open queue and merged into another ticket, with nothing on any screen saying so and nothing offering to fix them. Both halves of the card ship, because option A is a BEHAVIOUR RULE and a behaviour rule is a setting: B — the office fixes them one at a time. `merged_inconsistent` rides on the model (Ticket::$appends), so the list row, the index detail pane and the Show header all draw the same amber badge — "merged_into set but status open — fix?" — off one predicate rather than three copies of an expression. The badge IS the button: it opens a modal that says what will change and what will not, and posts to a new `mark-merged` verb that writes `status` and nothing else. A new "Merged" view lists every ticket folded into another one BY THE POINTER, so the consistent and the broken appear side by side; a status filter would show one or the other and never the pair worth comparing. A — the migration re-marks all of them at once, and it is INERT unless `ticketing.auto_repair_merged_on_deploy` is on. It defaults OFF, which is also what a box that has never heard of the setting does, so this can ship ahead of the operator's decision and change nothing unasked. The toggle is on the Automation tab with the live count beside it, because nobody should arm a bulk data change without seeing how many rows it touches. `MergedTicketRepair` is one implementation with three callers for one reason: "which rows are broken" and "what fixing one means" must not drift, or the badge offers a fix on a row the migration skips. THE PROD COUNT THE CARD ASKS FOR IS NOT IN HERE, and it could not be: this worker box holds no ssh private key, so central-prod is unreachable from it and there is no prod container locally. `php artisan ticketing:repair-merged --dry-run` is the read-only answer for whoever does have access — it prints the card's own SELECT COUNT and lists the rows, and `--force` (not the bare form) is the only spelling that writes. Repairing NEVER reverts. Messages, participants, assignee and title edits made to a row while it was wrongly editable are somebody's work and the only copy of it; there is no record of what the fields held before the bad save, so "reverting" would invent a previous state rather than restore one. Proved by tests/Feature/Ticketing/MergedTicketInconsistentRowsTest.php (22 tests) in dashboard-shell, over the fixture the card names — one inconsistent row beside a genuinely merged one, both produced by the real merge endpoint. The NEGCTRL half is what keeps it honest: the consistent row and an ordinary open ticket must come out of every path untouched, and a repaired row must keep the reply and the rename it was given after the merge. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ use Dashboard\Ticketing\Models\TicketMessage;
|
||||
use Dashboard\Ticketing\Models\TicketParticipant;
|
||||
use Dashboard\Ticketing\Models\TicketStatus;
|
||||
use Dashboard\Ticketing\Models\TicketView;
|
||||
use Dashboard\Ticketing\Support\MergedTicketRepair;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -147,6 +148,11 @@ class TicketController extends Controller
|
||||
'unassigned' => (clone $baseQuery)->whereNull('assigned_to')->whereNotIn('status', $closedSlugs)->count(),
|
||||
'pending' => (clone $baseQuery)->where('status', 'pending')->count(),
|
||||
'resolved' => (clone $baseQuery)->whereIn('status', $closedSlugs)->count(),
|
||||
// #938: the pointer, not the status — this view exists to show the
|
||||
// rows where the two disagree, so filtering by `status = merged`
|
||||
// would hide exactly the ones worth looking at.
|
||||
'merged' => (clone $baseQuery)->whereNotNull('merged_into_id')->count(),
|
||||
'merged_inconsistent' => (clone $baseQuery)->inconsistentlyMerged()->count(),
|
||||
]
|
||||
: [
|
||||
'all' => (clone $baseQuery)->count(),
|
||||
@@ -154,6 +160,8 @@ class TicketController extends Controller
|
||||
'unassigned' => 0,
|
||||
'pending' => (clone $baseQuery)->where('status', 'pending')->count(),
|
||||
'resolved' => (clone $baseQuery)->whereIn('status', $closedSlugs)->count(),
|
||||
'merged' => 0,
|
||||
'merged_inconsistent' => 0,
|
||||
];
|
||||
|
||||
$query = Ticket::with(['group', 'priority', 'project']);
|
||||
@@ -181,6 +189,12 @@ class TicketController extends Controller
|
||||
$query->where('status', 'pending');
|
||||
} elseif ($request->filter === 'resolved') {
|
||||
$query->whereIn('status', $closedSlugs);
|
||||
} elseif ($request->filter === 'merged') {
|
||||
// Every ticket that has been folded into another one, whatever its
|
||||
// status says — which is what makes this the place the office
|
||||
// finds the rows #938 is about. `merged` is a closed slug, so the
|
||||
// whereNotIn below would drop the consistent half of the list.
|
||||
$query->whereNotNull('merged_into_id');
|
||||
} elseif (!$request->filled('status')) {
|
||||
$query->whereNotIn('status', $closedSlugs);
|
||||
}
|
||||
@@ -616,7 +630,7 @@ class TicketController extends Controller
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'view_mode' => 'sometimes|in:list,kanban',
|
||||
'filter' => 'sometimes|in:all,mine,unassigned,pending,resolved',
|
||||
'filter' => 'sometimes|in:all,mine,unassigned,pending,resolved,merged',
|
||||
]);
|
||||
|
||||
if (empty($validated)) {
|
||||
@@ -700,6 +714,42 @@ class TicketController extends Controller
|
||||
->with('success', "Ticket {$source->number} merged in.");
|
||||
}
|
||||
|
||||
/**
|
||||
* MARK ONE INCONSISTENT ROW AS MERGED — option B of [central-ticketing] #938.
|
||||
*
|
||||
* The rows the merge bug minted carry `merged_into_id` while their status
|
||||
* says `open`. #920 left them editable ON PURPOSE, so that they could be
|
||||
* corrected in the product; this is the correction, and until it existed the
|
||||
* only way to make one was to type the right status into the Edit form and
|
||||
* know that `merged` was not in the list.
|
||||
*
|
||||
* Note what it is NOT: it is not `update()` with a status of `merged`, which
|
||||
* `refuseIfMerged()` would have to be weakened to allow, and it does not
|
||||
* touch messages, participants or any field somebody edited after the merge.
|
||||
* It writes one column, on a row that is provably in the broken shape, and
|
||||
* it is a no-op on anything else — so a double-click, a stale page and a row
|
||||
* a colleague fixed thirty seconds ago all land somewhere harmless.
|
||||
*/
|
||||
public function markMerged(Ticket $ticket)
|
||||
{
|
||||
if (! $this->isAgent($ticket->group_id)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
if (! $ticket->isInconsistentlyMerged()) {
|
||||
// Deliberately not an error: the button is only rendered on a row in
|
||||
// the broken shape, so arriving here means somebody else has already
|
||||
// fixed it, and being told so is the right answer.
|
||||
return redirect()->route('ticketing.show', $ticket)
|
||||
->with('success', 'That ticket is already consistent — nothing to fix.');
|
||||
}
|
||||
|
||||
MergedTicketRepair::repair($ticket, 'user '.Auth::id());
|
||||
|
||||
return redirect()->route('ticketing.show', $ticket)
|
||||
->with('success', "Ticket {$ticket->number} is marked merged and is read-only again.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Split this ticket — create a copy with a new number, same metadata, duplicated messages.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user