feat(v1.5): complete phases 40-43 workflow cleanup

This commit is contained in:
2026-03-25 22:46:51 +01:00
parent b8dda81e7b
commit 3610571949
37 changed files with 1557 additions and 259 deletions

View File

@@ -759,6 +759,59 @@ final class OrdersRepository
]);
}
/**
* @param array<string, mixed> $details
*/
public function shouldSkipDuplicateImportActivity(int $orderId, array $details): bool
{
if ($orderId <= 0 || !empty($details['created'])) {
return false;
}
$sourceOrderId = trim((string) ($details['source_order_id'] ?? ''));
$sourceUpdatedAt = trim((string) ($details['source_updated_at'] ?? ''));
$trigger = trim((string) ($details['trigger'] ?? ''));
if ($sourceOrderId === '' || $sourceUpdatedAt === '' || $trigger === '') {
return false;
}
try {
$stmt = $this->pdo->prepare(
'SELECT details_json
FROM order_activity_log
WHERE order_id = :order_id
AND event_type = :event_type
ORDER BY created_at DESC, id DESC
LIMIT 1'
);
$stmt->execute([
'order_id' => $orderId,
'event_type' => 'import',
]);
$lastDetailsJson = $stmt->fetchColumn();
} catch (Throwable) {
return false;
}
if (!is_string($lastDetailsJson) || trim($lastDetailsJson) === '') {
return false;
}
$lastDetails = json_decode($lastDetailsJson, true);
if (!is_array($lastDetails) || !empty($lastDetails['created'])) {
return false;
}
$lastSourceOrderId = trim((string) ($lastDetails['source_order_id'] ?? ''));
$lastSourceUpdatedAt = trim((string) ($lastDetails['source_updated_at'] ?? ''));
$lastTrigger = trim((string) ($lastDetails['trigger'] ?? ''));
return $lastSourceOrderId === $sourceOrderId
&& $lastSourceUpdatedAt === $sourceUpdatedAt
&& $lastTrigger === $trigger;
}
public function recordStatusChange(
int $orderId,
?string $fromStatus,