Kurzbeschreibung Versteckt die Rerun-Row-Action für archivierte (soft-deleted) RestoreRuns und verhindert damit fehlerhafte Neu-Starts aus dem Archiv; ergänzt einen Regressionstest. Änderungen Code: RestoreRunResource.php — Sichtbarkeit der rerun-Action geprüft auf ! $record->trashed() und defensive Abbruchprüfung im Action-Handler. Tests: RestoreRunRerunTest.php — neuer Test rerun action is hidden for archived restore runs. Warum Archivierte RestoreRuns durften nicht neu gestartet werden; UI zeigte trotzdem die Option. Das führte zu verwirrendem Verhalten und möglichen Fehlern beim Enqueueing. Verifikation / QA Unit/Feature: ./vendor/bin/sail artisan test tests/Feature/RestoreRunRerunTest.php Stil/format: ./vendor/bin/pint --dirty Manuell (UI): Als Tenant-Admin Filament → Restore Runs öffnen. Filter Archived aktivieren (oder Trashed filter auswählen). Sicherstellen, dass für archivierte Einträge die Rerun-Action nicht sichtbar ist. Auf einem aktiven (nicht-archivierten) Run prüfen, dass Rerun sichtbar bleibt und wie erwartet eine neue RestoreRun erzeugt. Wichtige Hinweise Kein DB-Migration required. Diese PR enthält nur den UI-/Filament-Fix; die zuvor gemachten operative Fixes für Queue/adapter-Reconciliation bleiben ebenfalls auf dem Branch (z. B. frühere commits während der Debugging-Session). T055 (Schema squash) wurde bewusst zurückgestellt und ist nicht Teil dieses PRs. Merge-Checklist Tests lokal laufen (RestoreRunRerunTest grünt) Pint läuft ohne ungepatchte Fehler Branch gepusht: 056-remove-legacy-bulkops (PR-URL: https://git.cloudarix.de/ahmido/TenantAtlas/compare/dev...056-remove-legacy-bulkops) Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #65
117 lines
3.7 KiB
PHP
117 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Filament\Resources\EntraGroupSyncRunResource;
|
|
use App\Filament\Resources\RestoreRunResource;
|
|
use App\Models\Tenant;
|
|
use App\Support\OperationRunLinks;
|
|
use Filament\Actions\Action;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class RunStatusChangedNotification extends Notification
|
|
{
|
|
/**
|
|
* @param array{
|
|
* tenant_id:int,
|
|
* run_type:string,
|
|
* run_id:int,
|
|
* status:string,
|
|
* counts?:array{total?:int, processed?:int, succeeded?:int, failed?:int, skipped?:int}
|
|
* } $metadata
|
|
*/
|
|
public function __construct(public array $metadata) {}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['database'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toDatabase(object $notifiable): array
|
|
{
|
|
$status = (string) ($this->metadata['status'] ?? 'queued');
|
|
$runType = (string) ($this->metadata['run_type'] ?? 'run');
|
|
$tenantId = (int) ($this->metadata['tenant_id'] ?? 0);
|
|
$runId = (int) ($this->metadata['run_id'] ?? 0);
|
|
|
|
$title = match ($status) {
|
|
'queued' => 'Run queued',
|
|
'running' => 'Run started',
|
|
'completed', 'succeeded' => 'Run completed',
|
|
'partial', 'partially succeeded', 'completed_with_errors' => 'Run completed (partial)',
|
|
'failed' => 'Run failed',
|
|
default => 'Run updated',
|
|
};
|
|
|
|
$body = sprintf('A %s run changed status to: %s.', str_replace('_', ' ', $runType), $status);
|
|
|
|
$color = match ($status) {
|
|
'queued', 'running' => 'gray',
|
|
'completed', 'succeeded' => 'success',
|
|
'partial', 'partially succeeded', 'completed_with_errors' => 'warning',
|
|
'failed' => 'danger',
|
|
default => 'gray',
|
|
};
|
|
|
|
$actions = [];
|
|
|
|
if (in_array($runType, ['bulk_operation', 'restore', 'directory_groups'], true) && $tenantId > 0 && $runId > 0) {
|
|
$tenant = Tenant::query()->find($tenantId);
|
|
|
|
if ($tenant) {
|
|
$url = match ($runType) {
|
|
'bulk_operation' => OperationRunLinks::view($runId, $tenant),
|
|
'restore' => RestoreRunResource::getUrl('view', ['record' => $runId], tenant: $tenant),
|
|
'directory_groups' => EntraGroupSyncRunResource::getUrl('view', ['record' => $runId], tenant: $tenant),
|
|
default => null,
|
|
};
|
|
|
|
if (! $url) {
|
|
return [
|
|
'format' => 'filament',
|
|
'title' => $title,
|
|
'body' => $body,
|
|
'color' => $color,
|
|
'duration' => 'persistent',
|
|
'actions' => [],
|
|
'icon' => null,
|
|
'iconColor' => null,
|
|
'status' => null,
|
|
'view' => null,
|
|
'viewData' => [
|
|
'metadata' => $this->metadata,
|
|
],
|
|
];
|
|
}
|
|
|
|
$actions[] = Action::make('view_run')
|
|
->label('View run')
|
|
->url($url)
|
|
->toArray();
|
|
}
|
|
}
|
|
|
|
return [
|
|
'format' => 'filament',
|
|
'title' => $title,
|
|
'body' => $body,
|
|
'color' => $color,
|
|
'duration' => 'persistent',
|
|
'actions' => $actions,
|
|
'icon' => null,
|
|
'iconColor' => null,
|
|
'status' => null,
|
|
'view' => null,
|
|
'viewData' => [
|
|
'metadata' => $this->metadata,
|
|
],
|
|
];
|
|
}
|
|
}
|