Files
ad_testbed/app/Services/DirectorySyncHistory.php
T
2026-11-11 17:15:37 +00:00

33 lines
1.0 KiB
PHP

<?php
namespace App\Services;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Throwable;
class DirectorySyncHistory
{
/** @param array<string, int>|null $counts */
public function record(string $id, string $status, bool $dryRun, bool $deactivateMissing, int $duration, ?array $counts = null, ?string $failure = null): void
{
try {
DB::table('ad_sync_runs')->insert([
'id' => $id,
'status' => $status,
'dry_run' => $dryRun,
'deactivate_missing' => $deactivateMissing,
'duration_ms' => $duration,
'counts' => $counts === null ? null : json_encode($counts, JSON_THROW_ON_ERROR),
'failure' => $failure,
'finished_at' => now(),
]);
} catch (Throwable $exception) {
Log::warning('Active Directory sync history could not be saved.', [
'run_id' => $id,
'exception_type' => $exception::class,
]);
}
}
}