Skip to content

Commit 513af3b

Browse files
marcelfolaronclaude
andcommitted
fix: address Copilot review feedback on moveTicket + sprint filter
- moveTicket: pass null (not '') to the nullable integer columns sprint/dependingTicketId/milestoneid so Postgres accepts the clear; check the child patch() return value and short-circuit on failure so a milestone can't end up half-moved; drop the duplicate ticket_updated dispatch since patch() already fires it on success. - Sprint filter (both call sites in Tickets repo): replace the is_numeric guard with per-element ctype_digit validation so comma-separated multi-sprint filters like "1,2,3" work again, while 'backlog' / empty / non-digit values still fall through to the dedicated backlog branch. Addresses review comments on #3360. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 66e1258 commit 513af3b

2 files changed

Lines changed: 33 additions & 15 deletions

File tree

app/Domain/Tickets/Repositories/Tickets.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,15 @@ public function getAllBySearchCriteria(array $searchCriteria, string $sort = 'st
561561
});
562562
}
563563

564-
if (isset($searchCriteria['sprint']) && is_numeric($searchCriteria['sprint']) && $searchCriteria['sprint'] > 0) {
565-
$sprintIds = explode(',', $searchCriteria['sprint']);
566-
$query->whereIn('zp_tickets.sprint', $sprintIds);
564+
if (isset($searchCriteria['sprint']) && $searchCriteria['sprint'] !== '' && $searchCriteria['sprint'] !== 'backlog') {
565+
$sprintIds = array_values(array_filter(
566+
array_map('trim', explode(',', (string) $searchCriteria['sprint'])),
567+
static fn ($token) => ctype_digit($token) && (int) $token > 0
568+
));
569+
570+
if ($sprintIds !== []) {
571+
$query->whereIn('zp_tickets.sprint', array_map('intval', $sprintIds));
572+
}
567573
}
568574

569575
if (isset($searchCriteria['sprint']) && $searchCriteria['sprint'] === 'backlog') {
@@ -1224,12 +1230,19 @@ public function getAllMilestones(array $searchCriteria, string $sort = 'standard
12241230
});
12251231
}
12261232

1227-
if (isset($searchCriteria['sprint']) && is_numeric($searchCriteria['sprint']) && $searchCriteria['sprint'] > 0) {
1228-
$sprintIds = explode(',', $searchCriteria['sprint']);
1229-
$query->where(function ($q) use ($sprintIds) {
1230-
$q->whereIn('zp_tickets.sprint', $sprintIds)
1231-
->orWhere('zp_tickets.type', 'milestone');
1232-
});
1233+
if (isset($searchCriteria['sprint']) && $searchCriteria['sprint'] !== '' && $searchCriteria['sprint'] !== 'backlog') {
1234+
$sprintIds = array_values(array_filter(
1235+
array_map('trim', explode(',', (string) $searchCriteria['sprint'])),
1236+
static fn ($token) => ctype_digit($token) && (int) $token > 0
1237+
));
1238+
1239+
if ($sprintIds !== []) {
1240+
$intSprintIds = array_map('intval', $sprintIds);
1241+
$query->where(function ($q) use ($intSprintIds) {
1242+
$q->whereIn('zp_tickets.sprint', $intSprintIds)
1243+
->orWhere('zp_tickets.type', 'milestone');
1244+
});
1245+
}
12331246
}
12341247

12351248
if (isset($searchCriteria['sprint']) && $searchCriteria['sprint'] === 'backlog') {

app/Domain/Tickets/Services/Tickets.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,17 +2235,22 @@ public function moveTicket(int $id, int $projectId): bool
22352235
if ($ticket->type == 'milestone') {
22362236
$milestoneTickets = $this->getAll(['milestone' => $ticket->id]);
22372237
foreach ($milestoneTickets as $childTicket) {
2238-
$this->patch($childTicket['id'], ['projectId' => $projectId, 'sprint' => '']);
2238+
$childMoved = $this->patch($childTicket['id'], [
2239+
'projectId' => $projectId,
2240+
'sprint' => null,
2241+
]);
2242+
2243+
if (! $childMoved) {
2244+
return false;
2245+
}
22392246
}
22402247
}
22412248

2242-
self::dispatchEvent('ticket_updated');
2243-
22442249
return $this->patch($ticket->id, [
22452250
'projectId' => $projectId,
2246-
'sprint' => '',
2247-
'dependingTicketId' => '',
2248-
'milestoneid' => '',
2251+
'sprint' => null,
2252+
'dependingTicketId' => null,
2253+
'milestoneid' => null,
22492254
]);
22502255
}
22512256

0 commit comments

Comments
 (0)