2025-11-02 17:11:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Events;
|
|
|
|
|
|
|
|
|
|
use App\Models\Server;
|
|
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
|
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
|
|
|
|
class S3RestoreJobFinished
|
|
|
|
|
{
|
|
|
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
|
{
|
2025-11-17 09:05:18 +00:00
|
|
|
$containerName = data_get($data, 'containerName');
|
|
|
|
|
$serverTmpPath = data_get($data, 'serverTmpPath');
|
2025-11-02 17:11:24 +00:00
|
|
|
$scriptPath = data_get($data, 'scriptPath');
|
2025-11-17 09:05:18 +00:00
|
|
|
$containerTmpPath = data_get($data, 'containerTmpPath');
|
2025-11-02 17:11:24 +00:00
|
|
|
$container = data_get($data, 'container');
|
|
|
|
|
$serverId = data_get($data, 'serverId');
|
2025-11-17 09:05:18 +00:00
|
|
|
|
2025-11-17 13:23:50 +00:00
|
|
|
// Most cleanup now happens inline during restore process
|
|
|
|
|
// This acts as a safety net for edge cases (errors, interruptions)
|
2025-11-17 09:05:18 +00:00
|
|
|
if (filled($serverId)) {
|
|
|
|
|
$commands = [];
|
|
|
|
|
|
2025-11-17 13:23:50 +00:00
|
|
|
// Ensure helper container is removed (may already be gone from inline cleanup)
|
2025-11-17 09:05:18 +00:00
|
|
|
if (filled($containerName)) {
|
2025-11-25 09:18:30 +00:00
|
|
|
$commands[] = 'docker rm -f '.escapeshellarg($containerName).' 2>/dev/null || true';
|
2025-11-17 09:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-17 13:23:50 +00:00
|
|
|
// Clean up server temp file if still exists (should already be cleaned)
|
2025-11-17 09:05:18 +00:00
|
|
|
if (isSafeTmpPath($serverTmpPath)) {
|
2025-11-25 09:18:30 +00:00
|
|
|
$commands[] = 'rm -f '.escapeshellarg($serverTmpPath).' 2>/dev/null || true';
|
2025-11-17 09:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-17 13:23:50 +00:00
|
|
|
// Clean up any remaining files in database container (may already be cleaned)
|
2025-11-17 09:05:18 +00:00
|
|
|
if (filled($container)) {
|
|
|
|
|
if (isSafeTmpPath($containerTmpPath)) {
|
2025-11-25 09:18:30 +00:00
|
|
|
$commands[] = 'docker exec '.escapeshellarg($container).' rm -f '.escapeshellarg($containerTmpPath).' 2>/dev/null || true';
|
2025-11-17 09:05:18 +00:00
|
|
|
}
|
|
|
|
|
if (isSafeTmpPath($scriptPath)) {
|
2025-11-25 09:18:30 +00:00
|
|
|
$commands[] = 'docker exec '.escapeshellarg($container).' rm -f '.escapeshellarg($scriptPath).' 2>/dev/null || true';
|
2025-11-17 09:05:18 +00:00
|
|
|
}
|
2025-11-02 17:11:24 +00:00
|
|
|
}
|
2025-11-17 09:05:18 +00:00
|
|
|
|
2025-11-17 13:23:50 +00:00
|
|
|
if (! empty($commands)) {
|
|
|
|
|
$server = Server::find($serverId);
|
|
|
|
|
if ($server) {
|
|
|
|
|
instant_remote_process($commands, $server, throwError: false);
|
|
|
|
|
}
|
2025-11-17 13:13:10 +00:00
|
|
|
}
|
2025-11-02 17:11:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|