#bugfix: sync operation log user labels

This commit is contained in:
2026-06-01 14:35:23 +08:00
parent 4875031cc3
commit 1de5fe1ff9
2 changed files with 85 additions and 1 deletions
@@ -49,11 +49,13 @@ class IpUserMappingController extends Controller
]);
$mapping = IpUserMapping::query()->create($data);
$syncedCount = $this->syncMissingOperationLogUserLabels($mapping->ip_address, $mapping->user_name);
return response()->json([
'success' => true,
'data' => [
'mapping' => $mapping,
'synced_operation_logs_count' => $syncedCount,
],
]);
}
@@ -72,11 +74,14 @@ class IpUserMappingController extends Controller
]);
$mapping->update($data);
$mapping->refresh();
$syncedCount = $this->syncMissingOperationLogUserLabels($mapping->ip_address, $mapping->user_name);
return response()->json([
'success' => true,
'data' => [
'mapping' => $mapping->refresh(),
'mapping' => $mapping,
'synced_operation_logs_count' => $syncedCount,
],
]);
}
@@ -89,4 +94,15 @@ class IpUserMappingController extends Controller
'success' => true,
]);
}
private function syncMissingOperationLogUserLabels(string $ipAddress, string $userName): int
{
return DB::table('operation_logs')
->where('ip_address', $ipAddress)
->where(function ($query): void {
$query->whereNull('user_label')
->orWhere('user_label', '');
})
->update(['user_label' => $userName]);
}
}