|
|
|
|
@ -192,6 +192,7 @@ class UserDataDeletionService
|
|
|
|
|
// jobs before their parent rows so encrypted owner/VM payloads do
|
|
|
|
|
// not survive as orphaned administrator audit records.
|
|
|
|
|
$resourceJobRows = $this->deleteCloudResourceJobs($connection, $ids);
|
|
|
|
|
$this->anonymizeCompensationScopes($connection, $ids);
|
|
|
|
|
$trafficInstanceIds = $this->pluckByUsers(
|
|
|
|
|
$connection,
|
|
|
|
|
'cloud_instances',
|
|
|
|
|
@ -412,6 +413,49 @@ class UserDataDeletionService
|
|
|
|
|
})->delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Batch audit survives account deletion, but a historical single-instance
|
|
|
|
|
* scope may have frozen the tenant's chosen instance name and user ID.
|
|
|
|
|
* Replace that snapshot while its item rows still identify the affected
|
|
|
|
|
* batches. Host and public-pool scopes contain provider metadata only.
|
|
|
|
|
*/
|
|
|
|
|
private function anonymizeCompensationScopes(
|
|
|
|
|
$connection,
|
|
|
|
|
array $userIds
|
|
|
|
|
): void {
|
|
|
|
|
if (!$this->hasColumns($connection,
|
|
|
|
|
'cloud_service_compensation_items', ['batch_id', 'user_id'])
|
|
|
|
|
|| !$this->hasColumns($connection,
|
|
|
|
|
'cloud_service_compensations', [
|
|
|
|
|
'id', 'scope_type', 'scope_id', 'scope_snapshot_json',
|
|
|
|
|
])) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$batchIds = $connection->table('cloud_service_compensation_items')
|
|
|
|
|
->whereIn('user_id', $userIds)->orderBy('batch_id')
|
|
|
|
|
->pluck('batch_id')->map(static fn ($id): int => (int) $id)
|
|
|
|
|
->unique()->values()->all();
|
|
|
|
|
if ($batchIds === []) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$batches = $connection->table('cloud_service_compensations')
|
|
|
|
|
->whereIn('id', $batchIds)->where('scope_type', 'instance')
|
|
|
|
|
->orderBy('id')->lockForUpdate()->get(['id', 'scope_id']);
|
|
|
|
|
foreach ($batches as $batch) {
|
|
|
|
|
$scopeId = (int) $batch->scope_id;
|
|
|
|
|
$snapshot = json_encode([
|
|
|
|
|
'type' => 'instance',
|
|
|
|
|
'id' => $scopeId,
|
|
|
|
|
'label' => '单实例 #' . $scopeId,
|
|
|
|
|
'instance_id' => $scopeId,
|
|
|
|
|
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES
|
|
|
|
|
| JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$connection->table('cloud_service_compensations')
|
|
|
|
|
->where('id', (int) $batch->id)
|
|
|
|
|
->update(['scope_snapshot_json' => $snapshot]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function deleteCloudTrafficScanFailures(
|
|
|
|
|
$connection,
|
|
|
|
|
array $instanceIds,
|
|
|
|
|
|