#bugfix: sync operation log user labels
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user