TenantAtlas/app/Support/OpsUx/OperationStatusNormalizer.php
2026-03-17 22:48:57 +01:00

55 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support\OpsUx;
/**
* Normalize OperationRun legacy storage fields into Ops-UX canonical statuses.
*/
final class OperationStatusNormalizer
{
/**
* Returns one of: queued|running|succeeded|partial|blocked|failed.
*/
public static function toUxStatus(?string $status, ?string $outcome): string
{
$status = strtolower(trim((string) $status));
$outcome = strtolower(trim((string) $outcome));
if ($status === 'queued') {
return 'queued';
}
if ($status === 'running') {
return 'running';
}
if ($status === 'completed' && $outcome === 'blocked') {
return 'blocked';
}
// Terminal normalization (compatibility)
if ($status === 'failed' || $outcome === 'failed') {
return 'failed';
}
if ($status === 'completed' && $outcome === 'partially_succeeded') {
return 'partial';
}
if ($status === 'completed' && $outcome === 'succeeded') {
return 'succeeded';
}
// Best-effort fallback.
return match ($outcome) {
'partially_succeeded' => 'partial',
'succeeded' => 'succeeded',
'blocked' => 'blocked',
'failed' => 'failed',
default => 'failed',
};
}
}