TenantAtlas/apps/platform/app/Support/Operations/Reconciliation/EnvironmentReviewComposeReconciliationAdapter.php
ahmido 840c9bd28d refactor: rename ManagedEnvironment context badge to Environment context (#431)
Renames ManagedEnvironment context badge to Environment context as requested.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #431
2026-06-06 20:30:26 +00:00

62 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support\Operations\Reconciliation;
use App\Models\OperationRun;
use App\Support\Operations\LifecycleReconciliationReason;
use Illuminate\Database\QueryException;
use Throwable;
final class EnvironmentReviewComposeReconciliationAdapter implements OperationRunReconciliationAdapter
{
public function __construct(
private readonly EnvironmentReviewComposeDecision $decision,
) {}
public function key(): string
{
return EnvironmentReviewComposeDecision::ADAPTER;
}
public function supportedTypes(): array
{
return ['environment.review.compose'];
}
public function supportsType(string $type): bool
{
return $type === 'environment.review.compose';
}
public function reconcile(OperationRun $run): ?ReconciliationResult
{
return $this->decision->evaluate($run);
}
public function reconcileException(OperationRun $run, Throwable $throwable): ?ReconciliationResult
{
if (! $throwable instanceof QueryException || ! $this->isUniqueViolation($throwable)) {
return null;
}
return ReconciliationResult::attentionRequired(
reasonCode: LifecycleReconciliationReason::AdapterOutOfSync->value,
reasonMessage: 'TenantPilot found matching review activity, but it could not be resolved automatically.',
evidence: [
'adapter' => EnvironmentReviewComposeDecision::ADAPTER,
'exception_class' => class_basename($throwable),
'workspace_id' => (int) $run->workspace_id,
'managed_environment_id' => (int) $run->managed_environment_id,
'fingerprint' => (string) data_get($run->context, 'review_fingerprint', ''),
],
);
}
private function isUniqueViolation(QueryException $exception): bool
{
return in_array(($exception->errorInfo[0] ?? null), ['23505', '23000'], true);
}
}