33 lines
1.1 KiB
PHP
33 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\ActiveDirectory\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,
|
|
]);
|
|
}
|
|
}
|
|
}
|